001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.debugger.ui.breakpoint;
021:
022: import java.util.ArrayList;
023: import java.util.HashMap;
024: import java.util.List;
025:
026: /**
027: * An abstract Node corresponding to each XML node when
028: * a BPEL file is parsed. It includes the line number and XPath
029: * information as well as the references to parent node and children node
030: *
031: * @author Sun Microsystems
032: *
033: */
034: public class BPELNode {
035:
036: /** "receive" element tag */
037: public static final String RECEIVE = "receive";
038:
039: /** "reply" element tag */
040: public static final String REPLY = "reply";
041:
042: /** "invoke" element tag */
043: public static final String INVOKE = "invoke";
044:
045: /** "assign" element tag */
046: public static final String ASSIGN = "assign";
047:
048: /** "throw" element tag */
049: public static final String THROW = "throw";
050:
051: /** "exit" element tag */
052: public static final String TERMINATE = "exit";
053:
054: /** "wait" element tag */
055: public static final String WAIT = "wait";
056:
057: /** "empty" element tag */
058: public static final String EMPTY = "empty";
059:
060: /** "sequence" element tag */
061: public static final String SEQUENCE = "sequence";
062:
063: /** "switch" element tag */
064: public static final String SWITCH = "switch";
065:
066: /** "if" element tag */
067: public static final String IF = "if";
068:
069: /** "while" element tag */
070: public static final String WHILE = "while";
071:
072: /** "repeatUntil element tag */
073: public static final String REPEAT_UNTIL = "repeatUntil";
074:
075: /** "repeatUntil element tag */
076: public static final String FOREACH = "forEach";
077:
078: /** "pick" element tag */
079: public static final String PICK = "pick";
080:
081: /** "flow" element tag */
082: public static final String FLOW = "flow";
083:
084: /** "scope" element tag */
085: public static final String SCOPE = "scope";
086:
087: /** "compensate" element tag */
088: public static final String COMPENSATE = "compensate";
089:
090: /** "compensateScope" element tag */
091: public static final String COMPENSATE_SCOPE = "compensateScope";
092:
093: /** "rethrow" element tag */
094: public static final String RETHROW = "rethrow";
095:
096: /** "validate" element tag */
097: public static final String VALIDATE = "validate";
098:
099: private static HashMap ALL_ACTIVITIES_MAP;
100:
101: /**
102: * NodeType class to ensure type safe comparison,
103: * so that no equalsTo is required to indentify
104: * what type the BPELNode is.
105: *
106: */
107: static public final class BPELNodeType {
108:
109: private String mName;
110: //Not an activity type
111: private static final String NONE_ACTIVITY = "NoneActivity";
112:
113: /**
114: * Private constructor to avoid creating an instance.
115: * All instances are precreated.
116: *
117: * @param nodeType The nodeType
118: *
119: */
120: private BPELNodeType(String nodeType) {
121: mName = nodeType;
122: }
123:
124: /**
125: * The 'receive' activity
126: */
127: public static final BPELNodeType RECEIVE_TYPE = new BPELNodeType(
128: RECEIVE);
129:
130: /**
131: * The 'reply' activity
132: */
133: public static final BPELNodeType REPLY_TYPE = new BPELNodeType(
134: REPLY);
135:
136: /**
137: * The 'invoke' activity
138: */
139: public static final BPELNodeType INVOKE_TYPE = new BPELNodeType(
140: INVOKE);
141:
142: /**
143: * The 'assign' activity
144: */
145: public static final BPELNodeType ASSIGN_TYPE = new BPELNodeType(
146: ASSIGN);
147:
148: /**
149: * The 'throw' activity
150: */
151: public static final BPELNodeType THROW_TYPE = new BPELNodeType(
152: THROW);
153:
154: /**
155: * The 'terminate' activity
156: */
157: public static final BPELNodeType TERMINATE_TYPE = new BPELNodeType(
158: TERMINATE);
159:
160: /**
161: * The 'wait' activity
162: */
163: public static final BPELNodeType WAIT_TYPE = new BPELNodeType(
164: WAIT);
165:
166: /**
167: * The 'empty' activity
168: */
169: public static final BPELNodeType EMPTY_TYPE = new BPELNodeType(
170: EMPTY);
171:
172: /**
173: * The 'sequence' activity
174: */
175: public static final BPELNodeType SEQUENCE_TYPE = new BPELNodeType(
176: SEQUENCE);
177:
178: /**
179: * The 'if' activity
180: */
181: public static final BPELNodeType IF_TYPE = new BPELNodeType(IF);
182:
183: /**
184: * The 'switch' activity
185: */
186: public static final BPELNodeType SWITCH_TYPE = new BPELNodeType(
187: SWITCH);
188:
189: /**
190: * The 'repeatUntil' activity
191: */
192: public static final BPELNodeType REPEAT_UNTIL_TYPE = new BPELNodeType(
193: REPEAT_UNTIL);
194:
195: /**
196: * The 'while' activity
197: */
198: public static final BPELNodeType WHILE_TYPE = new BPELNodeType(
199: WHILE);
200:
201: /**
202: * The 'forEach' activity
203: */
204: public static final BPELNodeType FOREACH_TYPE = new BPELNodeType(
205: FOREACH);
206:
207: /**
208: * The 'pick' activity
209: */
210: public static final BPELNodeType PICK_TYPE = new BPELNodeType(
211: PICK);
212:
213: /**
214: * The 'flow' activity
215: */
216: public static final BPELNodeType FLOW_TYPE = new BPELNodeType(
217: FLOW);
218:
219: /**
220: * The 'scope' activity
221: */
222: public static final BPELNodeType SCOPE_TYPE = new BPELNodeType(
223: SCOPE);
224:
225: /**
226: * The 'compensateScope' activity
227: */
228: public static final BPELNodeType COMPENSATE_SCOPE_TYPE = new BPELNodeType(
229: COMPENSATE_SCOPE);
230:
231: /**
232: * The 'rethrow' activity
233: */
234: public static final BPELNodeType RETHROW_TYPE = new BPELNodeType(
235: RETHROW);
236: /**
237: * The 'validate' activity
238: */
239: public static final BPELNodeType VALIDATE_TYPE = new BPELNodeType(
240: VALIDATE);
241: /**
242: * The 'compensate' activity
243: */
244: public static final BPELNodeType COMPENSATE_TYPE = new BPELNodeType(
245: COMPENSATE);
246:
247: /**
248: * Any node that is not the above mentioned types
249: *
250: */
251: public static final BPELNodeType NONE_ACTIVITY_TYPE = new BPELNodeType(
252: NONE_ACTIVITY);
253:
254: public boolean equals(Object obj) {
255: // TODO Auto-generated method stub
256: if (obj instanceof BPELNodeType)
257: return false;
258: return ((BPELNodeType) obj).mName.equals(mName);
259: }
260:
261: public int hashCode() {
262: // TODO Auto-generated method stub
263: return mName.hashCode();
264: }
265:
266: public String toString() {
267: // TODO Auto-generated method stub
268: return "Type:" + mName;
269: }
270:
271: }
272:
273: static {
274: ALL_ACTIVITIES_MAP = new HashMap();
275: ALL_ACTIVITIES_MAP.put(RECEIVE, BPELNodeType.RECEIVE_TYPE);
276: ALL_ACTIVITIES_MAP.put(REPLY, BPELNodeType.REPLY_TYPE);
277: ALL_ACTIVITIES_MAP.put(INVOKE, BPELNodeType.INVOKE_TYPE);
278: ALL_ACTIVITIES_MAP.put(ASSIGN, BPELNodeType.ASSIGN_TYPE);
279: ALL_ACTIVITIES_MAP.put(THROW, BPELNodeType.THROW_TYPE);
280: ALL_ACTIVITIES_MAP.put(TERMINATE, BPELNodeType.TERMINATE_TYPE);
281: ALL_ACTIVITIES_MAP.put(WAIT, BPELNodeType.WAIT_TYPE);
282: ALL_ACTIVITIES_MAP.put(EMPTY, BPELNodeType.EMPTY_TYPE);
283: ALL_ACTIVITIES_MAP.put(SEQUENCE, BPELNodeType.SEQUENCE_TYPE);
284: ALL_ACTIVITIES_MAP.put(IF, BPELNodeType.IF_TYPE);
285: ALL_ACTIVITIES_MAP.put(REPEAT_UNTIL,
286: BPELNodeType.REPEAT_UNTIL_TYPE);
287: ALL_ACTIVITIES_MAP.put(FOREACH, BPELNodeType.FOREACH_TYPE);
288: ALL_ACTIVITIES_MAP.put(SWITCH, BPELNodeType.SWITCH_TYPE);
289: ALL_ACTIVITIES_MAP.put(WHILE, BPELNodeType.WHILE_TYPE);
290: ALL_ACTIVITIES_MAP.put(PICK, BPELNodeType.PICK_TYPE);
291: ALL_ACTIVITIES_MAP.put(FLOW, BPELNodeType.FLOW_TYPE);
292: ALL_ACTIVITIES_MAP.put(SCOPE, BPELNodeType.SCOPE_TYPE);
293: ALL_ACTIVITIES_MAP
294: .put(COMPENSATE, BPELNodeType.COMPENSATE_TYPE);
295: ALL_ACTIVITIES_MAP.put(COMPENSATE_SCOPE,
296: BPELNodeType.COMPENSATE_SCOPE_TYPE);
297: ALL_ACTIVITIES_MAP.put(RETHROW, BPELNodeType.RETHROW_TYPE);
298: ALL_ACTIVITIES_MAP.put(VALIDATE, BPELNodeType.VALIDATE_TYPE);
299: }
300:
301: public static BPELNodeType getNodeType(String nodeName) {
302: return ALL_ACTIVITIES_MAP.get(nodeName) != null ? ((BPELNodeType) ALL_ACTIVITIES_MAP
303: .get(nodeName))
304: : BPELNodeType.NONE_ACTIVITY_TYPE;
305: }
306:
307: private final int mLineNo;
308: private final String mName;
309: private final String mXpath;
310: private final BPELNodeType mType;
311: private final boolean mActivityFlag;
312: private final String mTargetNameSpace;
313: private int mClosingNo;
314:
315: private List mChildren = new ArrayList();
316: private BPELNode mParent;
317:
318: public BPELNode(final String name, final int lineNumber,
319: final String targetNamespace, final BPELNodeType type,
320: final BPELNode parent) {
321: mName = name;
322: mLineNo = lineNumber;
323: mTargetNameSpace = targetNamespace;
324: mType = type;
325: mActivityFlag = (getNodeType(name) != BPELNodeType.NONE_ACTIVITY_TYPE);
326: mParent = parent;
327: mXpath = constructXpath();
328: }
329:
330: /**
331: * Returns whether he BPEL Node is an Activity type
332: * of node
333: * @return true if it is
334: */
335: public boolean isActivity() {
336: return mActivityFlag;
337: }
338:
339: private String constructXpath() {
340: // TODO Auto-generated method stub
341: String result = "/";
342: if (mParent == null) {
343: return result + mName;
344: }
345: String xpath = mParent.getXpath();
346: List sibings = mParent.getChildren();
347:
348: int index = 1;
349: for (int i = 0; i < sibings.size(); i++) {
350: BPELNode sibling = (BPELNode) sibings.get(i);
351: if (sibling.getType() == mType) {
352: index++;
353: }
354: }
355: return xpath + "/" + mName + "[" + index + "]";
356: }
357:
358: public String getName() {
359: return mName;
360: }
361:
362: /**
363: * Returns the type of this node
364: * @return
365: */
366: public BPELNodeType getType() {
367: // TODO Auto-generated method stub
368: return mType;
369: }
370:
371: /**
372: * Returns the children of this node
373: * @return
374: */
375: public List getChildren() {
376: // TODO Auto-generated method stub
377: return mChildren;
378: }
379:
380: /**
381: * Add a child
382: * @param child
383: */
384: public void addChild(BPELNode child) {
385: mChildren.add(child);
386: }
387:
388: /**
389: * Returns the xpath of this node
390: * @return
391: */
392: public String getXpath() {
393: // TODO Auto-generated method stub
394: return mXpath;
395: }
396:
397: /**
398: * Returns the lineNo of this node
399: * @return
400: */
401: public int getLineNumber() {
402: return mLineNo;
403: }
404:
405: public BPELNode getParent() {
406: return mParent;
407: }
408:
409: /**
410: * Returns the target name space
411: */
412: public String getTargetNameSpace() {
413: return mTargetNameSpace;
414: }
415:
416: /**
417: * Sets the closing number
418: * @param lineNo the line no. for the closing tag line
419: */
420:
421: public void setClosingNumber(int lineNumber) {
422: mClosingNo = lineNumber;
423: }
424:
425: /**
426: * Gets the closing number
427: * @return the line no. for the closing tag line
428: */
429: public int getClosingNumber() {
430: return mClosingNo;
431: }
432:
433: @Override
434: public boolean equals(Object obj) {
435: // TODO Auto-generated method stub
436: if (!(obj instanceof BPELNode)) {
437: return false;
438: }
439: return ((BPELNode) obj).mTargetNameSpace
440: .equals(mTargetNameSpace)
441: && ((BPELNode) obj).mXpath.equals(mXpath);
442: }
443:
444: @Override
445: public int hashCode() {
446: // TODO Auto-generated method stub
447: return (mXpath.hashCode() + mTargetNameSpace.hashCode()) * 37;
448: }
449:
450: @Override
451: public String toString() {
452: // TODO Auto-generated method stub
453: return "targetNameSpace:" + mTargetNameSpace + " name:"
454: + mName + " lineNo:" + mLineNo + " xPath:" + mXpath;
455: }
456: }
|