PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/bpel.validation/src/org/netbeans/modules/bpel/validation/custom/Validator.java

https://bitbucket.org/openesb/netbeans-soa
Java | 1063 lines | 799 code | 141 blank | 123 comment | 255 complexity | 21b35e4a9dbd2229801c80149ef3191c MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.bpel.validation.custom;
  45. import java.util.ArrayList;
  46. import java.util.List;
  47. import java.util.Collection;
  48. import org.netbeans.modules.xml.wsdl.model.Operation;
  49. import org.netbeans.modules.xml.wsdl.model.PortType;
  50. import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation;
  51. import org.netbeans.modules.xml.xam.Component;
  52. import org.netbeans.modules.xml.validation.core.Expression;
  53. import org.netbeans.modules.bpel.model.api.BaseCorrelation;
  54. import org.netbeans.modules.bpel.model.api.BpelEntity;
  55. import org.netbeans.modules.bpel.model.api.Branches;
  56. import org.netbeans.modules.bpel.model.api.CompletionCondition;
  57. import org.netbeans.modules.bpel.model.api.Copy;
  58. import org.netbeans.modules.bpel.model.api.Correlation;
  59. import org.netbeans.modules.bpel.model.api.CorrelationContainer;
  60. import org.netbeans.modules.bpel.model.api.CorrelationsHolder;
  61. import org.netbeans.modules.bpel.model.api.CorrelationSet;
  62. import org.netbeans.modules.bpel.model.api.CreateInstanceActivity;
  63. import org.netbeans.modules.bpel.model.api.Else;
  64. import org.netbeans.modules.bpel.model.api.ElseIf;
  65. import org.netbeans.modules.bpel.model.api.EventHandlers;
  66. import org.netbeans.modules.bpel.model.api.Exit;
  67. import org.netbeans.modules.bpel.model.api.FaultHandlers;
  68. import org.netbeans.modules.bpel.model.api.Flow;
  69. import org.netbeans.modules.bpel.model.api.ForEach;
  70. import org.netbeans.modules.bpel.model.api.If;
  71. import org.netbeans.modules.bpel.model.api.Invoke;
  72. import org.netbeans.modules.bpel.model.api.OnAlarmEvent;
  73. import org.netbeans.modules.bpel.model.api.OnEvent;
  74. import org.netbeans.modules.bpel.model.api.OnMessage;
  75. import org.netbeans.modules.bpel.model.api.PartnerLink;
  76. import org.netbeans.modules.bpel.model.api.PatternedCorrelation;
  77. import org.netbeans.modules.bpel.model.api.PatternedCorrelationContainer;
  78. import org.netbeans.modules.bpel.model.api.Pick;
  79. import org.netbeans.modules.bpel.model.api.Process;
  80. import org.netbeans.modules.bpel.model.api.Receive;
  81. import org.netbeans.modules.bpel.model.api.Reply;
  82. import org.netbeans.modules.bpel.model.api.Sequence;
  83. import org.netbeans.modules.bpel.model.api.TerminationHandler;
  84. import org.netbeans.modules.bpel.model.api.StartCounterValue;
  85. import org.netbeans.modules.bpel.model.api.FinalCounterValue;
  86. import org.netbeans.modules.bpel.model.api.Throw;
  87. import org.netbeans.modules.bpel.model.api.references.BpelReference;
  88. import org.netbeans.modules.bpel.model.api.references.WSDLReference;
  89. import org.netbeans.modules.bpel.model.api.support.AtomicTxType;
  90. import org.netbeans.modules.bpel.model.api.support.BinaryCopy;
  91. import org.netbeans.modules.bpel.model.api.support.Initiate;
  92. import org.netbeans.modules.bpel.model.api.support.TBoolean;
  93. import org.netbeans.modules.bpel.model.api.support.SimpleBpelModelVisitor;
  94. import org.netbeans.modules.bpel.model.api.support.SimpleBpelModelVisitorAdaptor;
  95. import org.netbeans.modules.bpel.validation.core.BpelValidator;
  96. import static org.netbeans.modules.xml.misc.UI.*;
  97. /**
  98. * @author Vladimir Yaroslavskiy
  99. * @version 2007.05.03
  100. */
  101. public final class Validator extends BpelValidator {
  102. @Override
  103. protected void init() {
  104. myErrored = new ArrayList<Component>();
  105. }
  106. @Override
  107. protected SimpleBpelModelVisitor getVisitor() {
  108. return new SimpleBpelModelVisitorAdaptor() {
  109. @Override
  110. public void visit(ForEach forEach) {
  111. //out();
  112. // # 86259
  113. checkReceive(forEach);
  114. // # 124918
  115. checkCounters(forEach);
  116. // # 125001
  117. checkNegativeCounter(forEach);
  118. //out("forEach: " + forEach);
  119. //out("forEach.getCounterName: " + forEach.getCounterName());
  120. String counter = forEach.getCounterName();
  121. if (counter == null) {
  122. return;
  123. }
  124. CompletionCondition completionCondition = forEach.getCompletionCondition();
  125. if (completionCondition == null) {
  126. return;
  127. }
  128. Branches branches = completionCondition.getBranches();
  129. if (branches == null) {
  130. return;
  131. }
  132. String expression = branches.getContent();
  133. if (expression == null) {
  134. return;
  135. }
  136. List<String> variables = Expression.getUsedVariables(expression);
  137. if (variables == null) {
  138. return;
  139. }
  140. //out("variables: " + variables);
  141. //out();
  142. for (String variable : variables) {
  143. if (variable.equals(counter)) {
  144. addError("FIX_Branches_Cant_Use_Counter", branches, counter); // NOI18N
  145. }
  146. }
  147. }
  148. private void checkReceive(ForEach forEach) {
  149. if (forEach.getParallel() != TBoolean.YES) {
  150. return;
  151. }
  152. if (hasReceive(forEach)) {
  153. addError("FIX_Parallel_ForEach", forEach, forEach.getName()); // NOI18N
  154. }
  155. }
  156. private boolean hasReceive(BpelEntity entity) {
  157. if (entity == null) {
  158. return false;
  159. }
  160. List<BpelEntity> children = entity.getChildren();
  161. for (BpelEntity child : children) {
  162. if (child instanceof Receive) {
  163. return true;
  164. }
  165. if (hasReceive(child)) {
  166. return true;
  167. }
  168. }
  169. return false;
  170. }
  171. private void checkCounters(ForEach forEach) {
  172. StartCounterValue startCounterValue = forEach.getStartCounterValue();
  173. if (startCounterValue == null) {
  174. return;
  175. }
  176. int startCounter;
  177. try {
  178. startCounter = Integer.parseInt(startCounterValue.getContent());
  179. } catch (NumberFormatException e) {
  180. return;
  181. }
  182. FinalCounterValue finalCounterValue = forEach.getFinalCounterValue();
  183. if (finalCounterValue == null) {
  184. return;
  185. }
  186. int finalCounter;
  187. try {
  188. finalCounter = Integer.parseInt(finalCounterValue.getContent());
  189. } catch (NumberFormatException e) {
  190. return;
  191. }
  192. if (finalCounter < startCounter) {
  193. addError("FIX_Final_Start_Counters", forEach, "" + startCounter, "" + finalCounter); // NOI18N
  194. }
  195. }
  196. private void checkNegativeCounter(ForEach forEach) {
  197. // start
  198. StartCounterValue startCounterValue = forEach.getStartCounterValue();
  199. if (startCounterValue == null) {
  200. return;
  201. }
  202. int startCounter;
  203. try {
  204. startCounter = Integer.parseInt(startCounterValue.getContent());
  205. } catch (NumberFormatException e) {
  206. return;
  207. }
  208. if (startCounter < 0) {
  209. addError("FIX_Negative_Start_Counter", startCounterValue, "" + startCounter); // NOI18N
  210. }
  211. // final
  212. FinalCounterValue finalCounterValue = forEach.getFinalCounterValue();
  213. if (finalCounterValue == null) {
  214. return;
  215. }
  216. int finalCounter;
  217. try {
  218. finalCounter = Integer.parseInt(finalCounterValue.getContent());
  219. } catch (NumberFormatException e) {
  220. return;
  221. }
  222. if (finalCounter < 0) {
  223. addError("FIX_Negative_Final_Counter", finalCounterValue, "" + finalCounter); // NOI18N
  224. }
  225. // completion
  226. CompletionCondition completionCondition = forEach.getCompletionCondition();
  227. if (completionCondition == null) {
  228. return;
  229. }
  230. Branches branches = completionCondition.getBranches();
  231. if (branches == null) {
  232. return;
  233. }
  234. int completionCounter;
  235. try {
  236. completionCounter = Integer.parseInt(branches.getContent());
  237. } catch (NumberFormatException e) {
  238. return;
  239. }
  240. if (completionCounter < 0) {
  241. addError("FIX_Negative_Completion_Counter", branches, "" + completionCounter); // NOI18N
  242. }
  243. }
  244. @Override
  245. public void visit(EventHandlers handlers) {
  246. //out();
  247. //out("HANDLERS: " + handlers);
  248. //out();
  249. // # 112489
  250. checkCase1(handlers);
  251. checkCase3(handlers);
  252. checkCase245(handlers);
  253. }
  254. @Override
  255. public void visit(Copy copy) {
  256. // # 170271
  257. checkAttribueValue(copy, "", Copy.BINARY_COPY, BinaryCopy.values(), "FIX_BinaryCopy"); // NOI18N
  258. }
  259. private void checkCase3(EventHandlers handlers) {
  260. OnAlarmEvent[] onAlarms = handlers.getOnAlarms();
  261. if (onAlarms == null) {
  262. return;
  263. }
  264. for (OnAlarmEvent onAlarm : onAlarms) {
  265. if (onAlarm.getRepeatEvery() == null) {
  266. continue;
  267. }
  268. List<Receive> receives = getReceives(onAlarm);
  269. for (Receive receive : receives) {
  270. addWarning("FIX_Receive_in_OnAlarm", receive, receive.getName()); // NOI18N
  271. }
  272. }
  273. }
  274. private void checkCase245(EventHandlers handlers) {
  275. List<Receive> receives = new ArrayList<Receive>();
  276. receives.addAll(getReceives(handlers.getOnEvents()));
  277. receives.addAll(getReceives(handlers.getOnAlarms()));
  278. checkDuplicate(receives);
  279. }
  280. private List<Receive> getReceives(OnEvent[] onEvents) {
  281. List<Receive> receives = new ArrayList<Receive>();
  282. if (onEvents == null) {
  283. return receives;
  284. }
  285. for (OnEvent onEvent : onEvents) {
  286. receives.addAll(getReceives(onEvent));
  287. }
  288. return receives;
  289. }
  290. private void checkDuplicate(List<Receive> receives) {
  291. for (int i = 0; i < receives.size(); i++) {
  292. for (int j = i + 1; j < receives.size(); j++) {
  293. checkDuplicate(receives.get(i), receives.get(j));
  294. }
  295. }
  296. }
  297. private void checkDuplicate(Receive receive1, Receive receive2) {
  298. if (samePartnerLink(receive1, receive2) &&
  299. samePortType(receive1, receive2) &&
  300. sameOperation(receive1, receive2)) {
  301. addWarning("FIX_Receives_in_OnEventOnAlarm", receive1, receive1.getName(), receive2.getName()); // NOI18N
  302. addWarning("FIX_Receives_in_OnEventOnAlarm", receive2, receive2.getName(), receive1.getName()); // NOI18N
  303. }
  304. }
  305. private boolean sameOperation(Receive receive1, Receive receive2) {
  306. WSDLReference<Operation> reference1 = receive1.getOperation();
  307. if (reference1 == null) {
  308. return false;
  309. }
  310. WSDLReference<Operation> reference2 = receive2.getOperation();
  311. if (reference2 == null) {
  312. return false;
  313. }
  314. return same(reference1.get(), reference2.get());
  315. }
  316. private boolean samePortType(Receive receive1, Receive receive2) {
  317. WSDLReference<PortType> reference1 = receive1.getPortType();
  318. if (reference1 == null) {
  319. return false;
  320. }
  321. WSDLReference<PortType> reference2 = receive2.getPortType();
  322. if (reference2 == null) {
  323. return false;
  324. }
  325. return same(reference1.get(), reference2.get());
  326. }
  327. private boolean samePartnerLink(Receive receive1, Receive receive2) {
  328. BpelReference<PartnerLink> reference1 = receive1.getPartnerLink();
  329. if (reference1 == null) {
  330. return false;
  331. }
  332. BpelReference<PartnerLink> reference2 = receive2.getPartnerLink();
  333. if (reference2 == null) {
  334. return false;
  335. }
  336. return same(reference1.get(), reference2.get());
  337. }
  338. private boolean same(Object object1, Object object2) {
  339. if (object1 == null) {
  340. return false;
  341. }
  342. return object1.equals(object2);
  343. }
  344. private List<Receive> getReceives(OnAlarmEvent[] onAlarms) {
  345. List<Receive> receives = new ArrayList<Receive>();
  346. if (onAlarms == null) {
  347. return receives;
  348. }
  349. for (OnAlarmEvent onAlarm : onAlarms) {
  350. if (onAlarm.getRepeatEvery() == null) {
  351. receives.addAll(getReceives(onAlarm));
  352. }
  353. }
  354. return receives;
  355. }
  356. private void checkCase1(EventHandlers handlers) {
  357. OnEvent[] onEvents = handlers.getOnEvents();
  358. if (onEvents == null) {
  359. return;
  360. }
  361. for (OnEvent onEvent : onEvents) {
  362. List<Receive> receives = getReceives(onEvent);
  363. for (Receive receive : receives) {
  364. addWarning("FIX_Receive_in_OnEvent", receive, receive.getName()); // NOI18N
  365. }
  366. }
  367. }
  368. private List<Receive> getReceives(BpelEntity entity) {
  369. List<Receive> receives = new ArrayList<Receive>();
  370. collectReceives(entity, receives);
  371. return receives;
  372. }
  373. private void collectReceives(BpelEntity entity, List<Receive> receives) {
  374. if (entity instanceof Receive) {
  375. receives.add((Receive) entity);
  376. }
  377. List<BpelEntity> children = entity.getChildren();
  378. for (BpelEntity child : children) {
  379. collectReceives(child, receives);
  380. }
  381. }
  382. // # 93078
  383. @Override
  384. public void visit(Branches branches) {
  385. String content = branches.getContent();
  386. if (content == null) {
  387. return;
  388. }
  389. content = content.toLowerCase();
  390. if (content.contains("true") || content.contains("false")) { // NOI18N
  391. addError("FIX_Branches_Must_Be_Integer", branches); // NOI18N
  392. }
  393. }
  394. @Override
  395. public void visit(Process process) {
  396. List<Reply> replies = new ArrayList<Reply>();
  397. List<CorrelationsHolder> holders = new ArrayList<CorrelationsHolder>();
  398. visitEntities(process.getChildren(), replies, holders);
  399. // # 81404
  400. checkReplies(replies);
  401. // # 109412
  402. checkHolders(holders);
  403. // # 129266
  404. checkExit(process);
  405. // # 169664
  406. checkAtomicValues(process);
  407. }
  408. private void checkAtomicValues(Process process) {
  409. checkAttribueValue(process, "sxtx:", Process.ATOMIC, TBoolean.values(), "FIX_Atomic"); // NOI18N
  410. checkAttribueValue(process, "sxtx:", Process.ATOMIC_TX_TYPE, AtomicTxType.values(), "FIX_AtomicTxType"); // NOI18N
  411. checkAtomicAndAtomicTxType(process);
  412. }
  413. private void checkAttribueValue(BpelEntity entity, String prefix, String attribute, Object[] values, String error) {
  414. String cuurent = getPrefixAttribute(entity, prefix, attribute);
  415. if (cuurent == null) {
  416. return;
  417. }
  418. //out();
  419. //out("values: " + values);
  420. //out();
  421. for (Object value : values) {
  422. //out(" see value: " + value);
  423. if (cuurent.equals(value.toString())) {
  424. return;
  425. }
  426. }
  427. addError(error, entity);
  428. }
  429. private String getPrefixAttribute(BpelEntity entity, String prefix, String attribute) {
  430. String value = getAttribute(entity, attribute);
  431. if (value != null) {
  432. return value;
  433. }
  434. return getAttribute(entity, prefix + attribute);
  435. }
  436. private String getAttribute(BpelEntity entity, String attribute) {
  437. String value = entity.getPeer().getAttribute(attribute);
  438. if (value != null && value.length() == 0) {
  439. value = null;
  440. }
  441. return value;
  442. }
  443. private void checkAtomicAndAtomicTxType(Process process) {
  444. if (process.getAtomicTxType() != null && process.isAtomic() != TBoolean.YES) {
  445. addError("FIX_Atomic_and_AtomicTxType", process); // NOI18N
  446. }
  447. }
  448. private void checkExit(BpelEntity entity) {
  449. List<BpelEntity> children = entity.getChildren();
  450. boolean hasExit = false;
  451. if (!(entity instanceof Flow)) {
  452. for (BpelEntity child : children) {
  453. if (hasExit) {
  454. addError("FIX_Activity_after_Exit", child); // NOI18N
  455. }
  456. if (child instanceof Exit) {
  457. hasExit = true;
  458. }
  459. }
  460. }
  461. for (BpelEntity child : children) {
  462. checkExit(child);
  463. }
  464. }
  465. private void visitEntities(List<BpelEntity> entities, List<Reply> replies, List<CorrelationsHolder> holders) {
  466. for (BpelEntity entity : entities) {
  467. if (entity instanceof Reply) {
  468. replies.add((Reply) entity);
  469. } else if (entity instanceof CorrelationsHolder) {
  470. holders.add((CorrelationsHolder) entity);
  471. }
  472. visitEntities(entity.getChildren(), replies, holders);
  473. }
  474. }
  475. private void checkReplies(List<Reply> replies) {
  476. //out();
  477. //out();
  478. for (int i = 0; i < replies.size(); i++) {
  479. Reply reply1 = replies.get(i);
  480. for (int j = i + 1; j < replies.size(); j++) {
  481. checkReplies(reply1, replies.get(j));
  482. }
  483. }
  484. //out();
  485. //out();
  486. }
  487. private void checkHolders(List<CorrelationsHolder> holders) {
  488. for (CorrelationsHolder holder : holders) {
  489. checkInitiateAndUse(holder);
  490. }
  491. //out();
  492. //out();
  493. for (int i = 0; i < holders.size(); i++) {
  494. CorrelationsHolder holder1 = holders.get(i);
  495. for (int j = i + 1; j < holders.size(); j++) {
  496. checkHolders(holder1, holders.get(j));
  497. }
  498. }
  499. //out();
  500. //out();
  501. }
  502. // # 120390
  503. private void checkInitiateAndUse(CorrelationsHolder holder) {
  504. CorrelationContainer container = holder.getCorrelationContainer();
  505. if (container == null) {
  506. return;
  507. }
  508. Correlation[] correlations = container.getCorrelations();
  509. if (correlations == null) {
  510. return;
  511. }
  512. Process process = holder.getBpelModel().getProcess();
  513. //out();
  514. //out("SEE: " + getName(holder));
  515. for (Correlation correlation : correlations) {
  516. Initiate initiate = correlation.getInitiate();
  517. if (initiate != Initiate.NO) {
  518. continue;
  519. }
  520. BpelReference<CorrelationSet> ref = correlation.getSet();
  521. if (ref == null) {
  522. continue;
  523. }
  524. CorrelationSet set = ref.get();
  525. if (set == null) {
  526. continue;
  527. }
  528. //out("check: " + getName(correlation));
  529. if (!checkCorrelationSet(set, holder, process)) {
  530. addError("FIX_Not_Instantiated_Correlation_Set", correlation, set.getName()); // NOI18N
  531. }
  532. }
  533. }
  534. private boolean checkCorrelationSet(CorrelationSet set, CorrelationsHolder holder, BpelEntity entity) {
  535. List<BpelEntity> children = entity.getChildren();
  536. for (BpelEntity child : children) {
  537. if (checkCorrelationSet(set, holder, child)) {
  538. return true;
  539. }
  540. }
  541. if (holder == entity) {
  542. return false;
  543. }
  544. if (checkCorrelationSetInInvoke(set, entity)) {
  545. return true;
  546. }
  547. if (!(entity instanceof CorrelationsHolder)) {
  548. return false;
  549. }
  550. CorrelationsHolder current = (CorrelationsHolder) entity;
  551. CorrelationContainer container = current.getCorrelationContainer();
  552. if (container == null) {
  553. return false;
  554. }
  555. Correlation[] correlations = container.getCorrelations();
  556. if (correlations == null) {
  557. return false;
  558. }
  559. for (Correlation correlation : correlations) {
  560. if (theSame(set, correlation)) {
  561. //out(" view: " + getName(corr));
  562. return true;
  563. //out(" FOUND");
  564. }
  565. }
  566. return false;
  567. }
  568. private boolean checkCorrelationSetInInvoke(CorrelationSet set, BpelEntity entity) {
  569. if (!(entity instanceof Invoke)) {
  570. return false;
  571. }
  572. Invoke invoke = (Invoke) entity;
  573. PatternedCorrelationContainer container = invoke.getPatternedCorrelationContainer();
  574. if (container == null) {
  575. return false;
  576. }
  577. PatternedCorrelation[] correlations = container.getPatternedCorrelations();
  578. if (correlations == null) {
  579. return false;
  580. }
  581. for (PatternedCorrelation correlation : correlations) {
  582. if (theSame(set, correlation)) {
  583. //out(" view: " + getName(corr));
  584. return true;
  585. //out(" FOUND");
  586. }
  587. }
  588. return false;
  589. }
  590. private boolean theSame(CorrelationSet set, BaseCorrelation correlation) {
  591. BpelReference<CorrelationSet> ref = correlation.getSet();
  592. if (ref == null) {
  593. return false;
  594. }
  595. CorrelationSet corr = ref.get();
  596. if (corr == null) {
  597. return false;
  598. }
  599. //out(" view: " + getName(corr));
  600. return corr == set && correlation.getInitiate() != Initiate.NO;
  601. }
  602. private void checkReplies(Reply reply1, Reply reply2) {
  603. //out();
  604. //out("reply1: " + reply1.getName());
  605. //out("reply2: " + reply2.getName());
  606. if (!isInGate(reply1) && !isInGate(reply2)) {
  607. if (haveTheSamePartnerLinkAndOperation(reply1, reply2)) {
  608. if (!hasNextExit(reply1) && !hasNextExit(reply2)) {
  609. addErrorCheck("FIX_Replies_PartnerLink_Gate", reply1, reply1.getName(), reply2.getName()); // NOI18N
  610. addErrorCheck("FIX_Replies_PartnerLink_Gate", reply2, reply2.getName(), reply1.getName()); // NOI18N
  611. return;
  612. }
  613. }
  614. }
  615. if (getParent(reply1) == getParent(reply2)) {
  616. if (haveTheSamePartnerLinkAndOperation(reply1, reply2)) {
  617. addErrorCheck("FIX_Replies_PartnerLink_Scope", reply1, reply1.getName(), reply2.getName()); // NOI18N
  618. addErrorCheck("FIX_Replies_PartnerLink_Scope", reply2, reply2.getName(), reply1.getName()); // NOI18N
  619. return;
  620. }
  621. }
  622. }
  623. private boolean hasNextExit(BpelEntity entity) {
  624. if (entity == null) {
  625. return false;
  626. }
  627. BpelEntity parent = entity.getParent();
  628. if (parent == null) {
  629. return false;
  630. }
  631. List<BpelEntity> children = parent.getChildren();
  632. boolean findExit = false;
  633. for (BpelEntity child : children) {
  634. if (findExit) {
  635. if (child instanceof Exit) {
  636. return true;
  637. }
  638. }
  639. if (child == entity) {
  640. findExit = true;
  641. }
  642. }
  643. return false;
  644. }
  645. private void checkHolders(CorrelationsHolder holder1, CorrelationsHolder holder2) {
  646. //out();
  647. //out("holder1: " + holder1);
  648. //out("holder2: " + holder2);
  649. BpelEntity parent1 = getParent(holder1);
  650. BpelEntity parent2 = getParent(holder2);
  651. if (!isInGate(holder1) && !isInGate(holder2)) {
  652. if (haveTheSameCorrelationWithInitiateYes(holder1, holder2, parent1, parent2)) {
  653. addErrorCheck("FIX_Holder_Correlation_Gate", holder1, getName(holder1), getName(holder2)); // NOI18N
  654. addErrorCheck("FIX_Holder_Correlation_Gate", holder2, getName(holder2), getName(holder1)); // NOI18N
  655. return;
  656. }
  657. }
  658. if (parent1 == parent2) {
  659. if (haveTheSameCorrelationWithInitiateYes(holder1, holder2, parent1, parent2)) {
  660. addErrorCheck("FIX_Holder_Correlation_Scope", holder1, getName(holder1), getName(holder2)); // NOI18N
  661. addErrorCheck("FIX_Holder_Correlation_Scope", holder2, getName(holder2), getName(holder1)); // NOI18N
  662. return;
  663. }
  664. }
  665. }
  666. private boolean haveTheSameCorrelationWithInitiateYes(
  667. CorrelationsHolder holder1,
  668. CorrelationsHolder holder2,
  669. BpelEntity parent1,
  670. BpelEntity parent2) {
  671. // # 128357
  672. if (holder1 instanceof OnMessage && parent1 instanceof Pick) {
  673. return false;
  674. }
  675. if (holder2 instanceof OnMessage && parent2 instanceof Pick) {
  676. return false;
  677. }
  678. CorrelationContainer container1 = holder1.getCorrelationContainer();
  679. //out(" 1");
  680. if (container1 == null) {
  681. return false;
  682. }
  683. //out(" 2");
  684. Correlation[] correlations1 = container1.getCorrelations();
  685. if (correlations1 == null) {
  686. return false;
  687. }
  688. //out(" 3");
  689. CorrelationContainer container2 = holder2.getCorrelationContainer();
  690. if (container2 == null) {
  691. return false;
  692. }
  693. //out(" 4");
  694. Correlation[] correlations2 = container2.getCorrelations();
  695. if (correlations2 == null) {
  696. return false;
  697. }
  698. //out(" 5");
  699. return checkCorrelations(correlations1, correlations2);
  700. }
  701. private boolean checkCorrelations(Correlation[] correlations1, Correlation[] correlations2) {
  702. //out(" ");
  703. for (Correlation correlation : correlations1) {
  704. //out("SEE: " + correlation + " " + correlation.getInitiate());
  705. if (correlation.getInitiate() != Initiate.YES) {
  706. continue;
  707. }
  708. if (checkCorrelation(correlations2, correlation)) {
  709. return true;
  710. }
  711. }
  712. return false;
  713. }
  714. private boolean checkCorrelation(Correlation[] correlations, Correlation correlation) {
  715. //out("for: " + correlation);
  716. for (Correlation next : correlations) {
  717. //out(" see: " + next + " " + next.getInitiate());
  718. if (theSame(next, correlation)) {
  719. return next.getInitiate() == Initiate.YES;
  720. }
  721. }
  722. return false;
  723. }
  724. private boolean theSame(Correlation correlation1, Correlation correlation2) {
  725. BpelReference<CorrelationSet> ref1 = correlation1.getSet();
  726. if (ref1 == null) {
  727. return false;
  728. }
  729. BpelReference<CorrelationSet> ref2 = correlation2.getSet();
  730. if (ref2 == null) {
  731. return false;
  732. }
  733. return ref1.get() == ref2.get();
  734. }
  735. private boolean haveTheSamePartnerLinkAndOperation(Reply reply1, Reply reply2) {
  736. if (reply1.getPartnerLink() == null) {
  737. //out(" reply1 has PL ref null");
  738. return false;
  739. }
  740. PartnerLink partnerLink1 = reply1.getPartnerLink().get();
  741. if (partnerLink1 == null) {
  742. //out(" reply1 has PL null");
  743. return false;
  744. }
  745. if (reply2.getPartnerLink() == null) {
  746. //out(" reply2 has PL ref null");
  747. return false;
  748. }
  749. PartnerLink partnerLink2 = reply2.getPartnerLink().get();
  750. if (partnerLink2 == null) {
  751. //out(" reply2 has PL null");
  752. return false;
  753. }
  754. if (partnerLink1 != partnerLink2) {
  755. return false;
  756. }
  757. // operation
  758. if (reply1.getOperation() == null) {
  759. return false;
  760. }
  761. Operation operation1 = reply1.getOperation().get();
  762. if (operation1 == null) {
  763. return false;
  764. }
  765. if (reply2.getOperation() == null) {
  766. return false;
  767. }
  768. Operation operation2 = reply2.getOperation().get();
  769. if (operation2 == null) {
  770. return false;
  771. }
  772. return operation1 == operation2;
  773. }
  774. private BpelEntity getParent(BpelEntity entity) {
  775. BpelEntity parent = entity.getParent();
  776. while (true) {
  777. if (parent instanceof Sequence) {
  778. parent = parent.getParent();
  779. continue;
  780. }
  781. break;
  782. }
  783. return parent;
  784. }
  785. private boolean isInGate(BpelEntity entity) {
  786. //out();
  787. //out("is in gate ...");
  788. BpelEntity parent = entity.getParent();
  789. //out(" entity: " + entity);
  790. //out(" parent: " + parent);
  791. while (true) {
  792. //out(" parent: " + parent);
  793. if (parent == null) {
  794. break;
  795. }
  796. if (parent instanceof If) {
  797. return true;
  798. }
  799. if (parent instanceof Else) {
  800. return true;
  801. }
  802. if (parent instanceof ElseIf) {
  803. return true;
  804. }
  805. if (parent instanceof FaultHandlers) {
  806. return true;
  807. }
  808. if (parent instanceof Flow) {
  809. return true;
  810. }
  811. if (parent instanceof OnMessage) {
  812. return true;
  813. }
  814. if (parent instanceof OnAlarmEvent) {
  815. return true;
  816. }
  817. parent = parent.getParent();
  818. }
  819. return false;
  820. }
  821. // # 90125
  822. @Override
  823. public void visit(CorrelationContainer container) {
  824. //out();
  825. //out("see container: " + container + " " + container.getParent());
  826. //out();
  827. Component parent = container.getParent();
  828. if (!(parent instanceof CreateInstanceActivity)) {
  829. return;
  830. }
  831. CreateInstanceActivity activity = (CreateInstanceActivity) parent;
  832. if (!isCreateInstanceYes(activity)) {
  833. return;
  834. }
  835. Correlation[] correlations = container.getCorrelations();
  836. if (correlations == null) {
  837. return;
  838. }
  839. for (Correlation correlation : correlations) {
  840. Initiate initiate = correlation.getInitiate();
  841. if (initiate != Initiate.NO) {
  842. return;
  843. }
  844. }
  845. addError("FIX_Activity_with_Correlation", parent); // NOI18N
  846. }
  847. // # 129986
  848. @Override
  849. public void visit(Receive receive) {
  850. //out();
  851. //out("RECEIVE: " + receive);
  852. WSDLReference<PortType> ref = receive.getPortType();
  853. if (ref == null) {
  854. return;
  855. }
  856. PortType portType = ref.get();
  857. if (portType == null) {
  858. return;
  859. }
  860. Collection<Operation> operations = portType.getOperations();
  861. if (operations.size() != 1) {
  862. return;
  863. }
  864. Operation operation = operations.iterator().next();
  865. if (operation == null) {
  866. return;
  867. }
  868. if (operation.getInput() == null || operation.getOutput() == null) {
  869. return;
  870. }
  871. if (!findReply(receive.getBpelModel().getProcess(), portType)) {
  872. addError("FIX_In_Out_Receive_Reply", receive, receive.getName()); // NOI18N
  873. }
  874. }
  875. private boolean findReply(BpelEntity entity, PortType portType) {
  876. if (entity instanceof Reply) {
  877. WSDLReference<PortType> ref = ((Reply) entity).getPortType();
  878. if (ref != null && portType == ref.get()) {
  879. return true;
  880. }
  881. }
  882. List<BpelEntity> children = entity.getChildren();
  883. for (BpelEntity child : children) {
  884. if (findReply(child, portType)) {
  885. return true;
  886. }
  887. }
  888. return false;
  889. }
  890. @Override
  891. public void visit(Reply reply) {
  892. super.visit(reply);
  893. WSDLReference<Operation> opRef = reply.getOperation();
  894. if (opRef == null) {
  895. return;
  896. }
  897. Operation operation = opRef.get();
  898. if (operation == null) {
  899. return;
  900. }
  901. if (!(operation instanceof RequestResponseOperation)) {
  902. addError("FIX_ReplyOperation", reply, opRef.getQName().toString()); // NOI18N
  903. }
  904. }
  905. // # 111409
  906. @Override
  907. public void visit(Throw _throw) {
  908. if (_throw.getParent() instanceof TerminationHandler) {
  909. addError("FIX_Throw_in_TerminationHandler", _throw, _throw.getName()); // NOI18N
  910. }
  911. }
  912. private void addErrorCheck(String key, Component component, String name1, String name2) {
  913. if (myErrored.contains(component)) {
  914. return;
  915. }
  916. myErrored.add(component);
  917. addError(key, component, name1, name2);
  918. }
  919. };
  920. }
  921. private List<Component> myErrored;
  922. }