0001: package org.enhydra.jawe;
0002:
0003: import java.util.ArrayList;
0004: import java.util.Collection;
0005: import java.util.HashSet;
0006: import java.util.Iterator;
0007: import java.util.List;
0008: import java.util.Map;
0009: import java.util.Set;
0010:
0011: import org.enhydra.jawe.base.xpdlhandler.XPDLHandler;
0012: import org.enhydra.jawe.components.graph.GraphEAConstants;
0013: import org.enhydra.shark.utilities.SequencedHashMap;
0014: import org.enhydra.shark.xpdl.XMLCollection;
0015: import org.enhydra.shark.xpdl.XMLCollectionElement;
0016: import org.enhydra.shark.xpdl.XMLComplexElement;
0017: import org.enhydra.shark.xpdl.XMLElement;
0018: import org.enhydra.shark.xpdl.XMLUtil;
0019: import org.enhydra.shark.xpdl.XPDLConstants;
0020: import org.enhydra.shark.xpdl.elements.Activities;
0021: import org.enhydra.shark.xpdl.elements.Activity;
0022: import org.enhydra.shark.xpdl.elements.ActivitySet;
0023: import org.enhydra.shark.xpdl.elements.ActualParameter;
0024: import org.enhydra.shark.xpdl.elements.Application;
0025: import org.enhydra.shark.xpdl.elements.Applications;
0026: import org.enhydra.shark.xpdl.elements.ArrayType;
0027: import org.enhydra.shark.xpdl.elements.BlockActivity;
0028: import org.enhydra.shark.xpdl.elements.DataField;
0029: import org.enhydra.shark.xpdl.elements.DataFields;
0030: import org.enhydra.shark.xpdl.elements.DataTypes;
0031: import org.enhydra.shark.xpdl.elements.Deadline;
0032: import org.enhydra.shark.xpdl.elements.DeclaredType;
0033: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
0034: import org.enhydra.shark.xpdl.elements.ExtendedAttributes;
0035: import org.enhydra.shark.xpdl.elements.ExternalPackage;
0036: import org.enhydra.shark.xpdl.elements.FormalParameter;
0037: import org.enhydra.shark.xpdl.elements.Join;
0038: import org.enhydra.shark.xpdl.elements.ListType;
0039: import org.enhydra.shark.xpdl.elements.Member;
0040: import org.enhydra.shark.xpdl.elements.Package;
0041: import org.enhydra.shark.xpdl.elements.Participant;
0042: import org.enhydra.shark.xpdl.elements.RecordType;
0043: import org.enhydra.shark.xpdl.elements.RedefinableHeader;
0044: import org.enhydra.shark.xpdl.elements.Responsible;
0045: import org.enhydra.shark.xpdl.elements.Responsibles;
0046: import org.enhydra.shark.xpdl.elements.Split;
0047: import org.enhydra.shark.xpdl.elements.SubFlow;
0048: import org.enhydra.shark.xpdl.elements.Tool;
0049: import org.enhydra.shark.xpdl.elements.Tools;
0050: import org.enhydra.shark.xpdl.elements.Transition;
0051: import org.enhydra.shark.xpdl.elements.TransitionRef;
0052: import org.enhydra.shark.xpdl.elements.TransitionRefs;
0053: import org.enhydra.shark.xpdl.elements.TransitionRestriction;
0054: import org.enhydra.shark.xpdl.elements.TransitionRestrictions;
0055: import org.enhydra.shark.xpdl.elements.Transitions;
0056: import org.enhydra.shark.xpdl.elements.TypeDeclaration;
0057: import org.enhydra.shark.xpdl.elements.UnionType;
0058: import org.enhydra.shark.xpdl.elements.WorkflowProcess;
0059:
0060: /**
0061: * Various utilities.
0062: *
0063: * @author Sasa Bojanic
0064: */
0065: public class XPDLUtils {
0066:
0067: public boolean hasCircularTransitions(Set transitions) {
0068: Iterator it = transitions.iterator();
0069: while (it.hasNext()) {
0070: Transition t = (Transition) it.next();
0071: if (t.getFrom().equals(t.getTo()))
0072: return true;
0073: }
0074: return false;
0075: }
0076:
0077: // Useful only if JaWE is set to work without start/end bubbles
0078: public boolean isStartingActivity(Activity act) {
0079: Set trans = XMLUtil.getIncomingTransitions(act);
0080: if (trans.size() == 0
0081: || (trans.size() == 1 && hasCircularTransitions(trans))) {
0082: return true;
0083: }
0084: return false;
0085: }
0086:
0087: // Useful only if JaWE is set to work without start/end bubbles
0088: public boolean isEndingActivity(Activity act) {
0089: Set trans = XMLUtil.getNonExceptionalOutgoingTransitions(act);
0090: if (trans.size() == 0
0091: || (trans.size() == 1 && hasCircularTransitions(trans))) {
0092: return true;
0093: }
0094: return false;
0095: }
0096:
0097: public List getReferences(XMLComplexElement pkgOrWp,
0098: XMLComplexElement referenced) {
0099: if (pkgOrWp instanceof Package) {
0100: return getReferences((Package) pkgOrWp, referenced);
0101: } else if (pkgOrWp instanceof WorkflowProcess) {
0102: return getReferences((WorkflowProcess) pkgOrWp, referenced);
0103: }
0104: return new ArrayList();
0105: }
0106:
0107: public List getReferences(Package pkg, XMLComplexElement referenced) {
0108: if (referenced instanceof Package) {
0109: return getReferences((Package) referenced);
0110: } else if (referenced instanceof TypeDeclaration) {
0111: return getReferences(pkg, (TypeDeclaration) referenced);
0112: } else if (referenced instanceof Participant) {
0113: return getReferences(pkg, (Participant) referenced);
0114: } else if (referenced instanceof Application) {
0115: return getReferences(pkg, (Application) referenced);
0116: } else if (referenced instanceof DataField) {
0117: return getReferences(pkg, (DataField) referenced);
0118: } else if (referenced instanceof WorkflowProcess) {
0119: return getReferences(pkg, (WorkflowProcess) referenced);
0120: }
0121: return new ArrayList();
0122: }
0123:
0124: public List getReferences(WorkflowProcess wp,
0125: XMLComplexElement referenced) {
0126: if (referenced instanceof Participant) {
0127: return getReferences(wp, (Participant) referenced);
0128: } else if (referenced instanceof Application) {
0129: return getReferences(wp, (Application) referenced);
0130: } else if (referenced instanceof DataField) {
0131: return getReferences(wp, (DataField) referenced);
0132: } else if (referenced instanceof WorkflowProcess) {
0133: return getReferences(wp, (WorkflowProcess) referenced);
0134: } else if (referenced instanceof FormalParameter) {
0135: return getReferences(wp, (FormalParameter) referenced);
0136: } else if (referenced instanceof ActivitySet) {
0137: return getReferences(wp, (ActivitySet) referenced);
0138: }
0139:
0140: return new ArrayList();
0141: }
0142:
0143: public List getReferences(Package pkg) {
0144: List references = new ArrayList();
0145: String pkgId = pkg.getId();
0146: Iterator it = JaWEManager.getInstance().getXPDLHandler()
0147: .getAllPackages().iterator();
0148: while (it.hasNext()) {
0149: Package p = (Package) it.next();
0150: if (p.getExternalPackageIds().contains(pkgId)) {
0151: references.add(p);
0152: }
0153: }
0154:
0155: return references;
0156:
0157: }
0158:
0159: public List getAllExternalPackageReferences(Package pkg,
0160: Package referenced) {
0161: List references = new ArrayList();
0162:
0163: if (referenced != null) {
0164: Iterator it = referenced.getApplications().toElements()
0165: .iterator();
0166: while (it.hasNext()) {
0167: Application app = (Application) it.next();
0168: references.addAll(getReferences(pkg, app));
0169: }
0170: it = referenced.getParticipants().toElements().iterator();
0171: while (it.hasNext()) {
0172: Participant par = (Participant) it.next();
0173: references.addAll(getReferences(pkg, par));
0174: }
0175: it = referenced.getWorkflowProcesses().toElements()
0176: .iterator();
0177: while (it.hasNext()) {
0178: WorkflowProcess wp = (WorkflowProcess) it.next();
0179: references.addAll(getReferences(pkg, wp));
0180: }
0181: }
0182:
0183: return references;
0184: }
0185:
0186: public List getReferences(Package pkg, TypeDeclaration referenced) {
0187: return getTypeDeclarationReferences(pkg, referenced.getId());
0188: }
0189:
0190: public List getReferences(WorkflowProcess wp,
0191: TypeDeclaration referenced) {
0192: return tGetTypeDeclarationReferences(wp, referenced.getId());
0193: }
0194:
0195: public List getReferences(TypeDeclaration td,
0196: TypeDeclaration referenced) {
0197: if (td.getId().equals(referenced.getId()))
0198: return new ArrayList();
0199: return getReferencingDeclaredTypes(td.getDataTypes(),
0200: referenced.getId());
0201: }
0202:
0203: public List getTypeDeclarationReferences(Package pkg,
0204: String referencedId) {
0205: List references = new ArrayList();
0206: if (referencedId.equals("")) {
0207: return references;
0208: }
0209: Iterator it = pkg.getTypeDeclarations().toElements().iterator();
0210: while (it.hasNext()) {
0211: TypeDeclaration td = (TypeDeclaration) it.next();
0212: if (td.getId().equals(referencedId))
0213: continue;
0214: references.addAll(getReferencingDeclaredTypes(td
0215: .getDataTypes(), referencedId));
0216: }
0217:
0218: references.addAll(tGetTypeDeclarationReferences(pkg,
0219: referencedId));
0220:
0221: it = pkg.getWorkflowProcesses().toElements().iterator();
0222: while (it.hasNext()) {
0223: WorkflowProcess wp = (WorkflowProcess) it.next();
0224: references.addAll(tGetTypeDeclarationReferences(wp,
0225: referencedId));
0226: }
0227:
0228: return references;
0229: }
0230:
0231: protected List tGetTypeDeclarationReferences(
0232: XMLComplexElement pkgOrWp, String referencedId) {
0233: List references = new ArrayList();
0234: if (referencedId.equals("")) {
0235: return references;
0236: }
0237:
0238: Iterator it = ((Applications) pkgOrWp.get("Applications"))
0239: .toElements().iterator();
0240: while (it.hasNext()) {
0241: Application app = (Application) it.next();
0242: Iterator fps = app.getApplicationTypes()
0243: .getFormalParameters().toElements().iterator();
0244: while (fps.hasNext()) {
0245: Object obj = fps.next();
0246: // System.err.println(obj.getClass().getName());
0247: FormalParameter fp = (FormalParameter) obj;
0248: references.addAll(getReferencingDeclaredTypes(fp
0249: .getDataType().getDataTypes(), referencedId));
0250: }
0251: }
0252: it = ((DataFields) pkgOrWp.get("DataFields")).toElements()
0253: .iterator();
0254: while (it.hasNext()) {
0255: DataField df = (DataField) it.next();
0256: references.addAll(getReferencingDeclaredTypes(df
0257: .getDataType().getDataTypes(), referencedId));
0258: }
0259: if (pkgOrWp instanceof WorkflowProcess) {
0260: it = ((WorkflowProcess) pkgOrWp).getFormalParameters()
0261: .toElements().iterator();
0262: while (it.hasNext()) {
0263: FormalParameter fp = (FormalParameter) it.next();
0264: references.addAll(getReferencingDeclaredTypes(fp
0265: .getDataType().getDataTypes(), referencedId));
0266: }
0267: }
0268:
0269: return references;
0270: }
0271:
0272: public List getReferencingDeclaredTypes(DataTypes dts,
0273: String typeDeclarationId) {
0274: List toRet = new ArrayList();
0275: if (typeDeclarationId.equals("")) {
0276: return toRet;
0277: }
0278:
0279: XMLElement choosen = dts.getChoosen();
0280: if (choosen instanceof DeclaredType) {
0281: if (((DeclaredType) choosen).getId().equals(
0282: typeDeclarationId)) {
0283: toRet.add(choosen);
0284: }
0285: } else if (choosen instanceof ArrayType) {
0286: return getReferencingDeclaredTypes(((ArrayType) choosen)
0287: .getDataTypes(), typeDeclarationId);
0288: } else if (choosen instanceof ListType) {
0289: return getReferencingDeclaredTypes(((ListType) choosen)
0290: .getDataTypes(), typeDeclarationId);
0291: } else if (choosen instanceof RecordType
0292: || choosen instanceof UnionType) {
0293: Iterator it = ((XMLCollection) choosen).toElements()
0294: .iterator();
0295: while (it.hasNext()) {
0296: Member m = (Member) it.next();
0297: toRet.addAll(getReferencingDeclaredTypes(m
0298: .getDataTypes(), typeDeclarationId));
0299: }
0300: }
0301:
0302: return toRet;
0303: }
0304:
0305: public List getParticipantReferences(XMLComplexElement pkgOrWp,
0306: String referencedId) {
0307: if (referencedId.equals("")) {
0308: return new ArrayList();
0309: }
0310: if (pkgOrWp instanceof Package) {
0311: return getParticipantReferences((Package) pkgOrWp,
0312: referencedId);
0313: }
0314:
0315: return getParticipantReferences((WorkflowProcess) pkgOrWp,
0316: referencedId);
0317: }
0318:
0319: public List getReferences(Package pkg, Participant referenced) {
0320: if (XMLUtil.getPackage(referenced) != pkg
0321: && pkg.getParticipant(referenced.getId()) != null) {
0322: return new ArrayList();
0323: }
0324:
0325: return getParticipantReferences(pkg, referenced.getId());
0326: }
0327:
0328: public List getParticipantReferences(Package pkg,
0329: String referencedId) {
0330: List references = new ArrayList();
0331: if (referencedId.equals("")) {
0332: return references;
0333: }
0334:
0335: references.addAll(tGetParticipantReferences(pkg, referencedId));
0336:
0337: Iterator it = pkg.getWorkflowProcesses().toElements()
0338: .iterator();
0339: while (it.hasNext()) {
0340: WorkflowProcess wp = (WorkflowProcess) it.next();
0341: if (wp.getParticipant(referencedId) == null) {
0342: references.addAll(getParticipantReferences(wp,
0343: referencedId));
0344: }
0345: }
0346:
0347: return references;
0348: }
0349:
0350: public List getReferences(WorkflowProcess wp, Participant referenced) {
0351: if (XMLUtil.getWorkflowProcess(referenced) == null
0352: && wp.getParticipant(referenced.getId()) != null) {
0353: return new ArrayList();
0354: }
0355: Package pkg = XMLUtil.getPackage(wp);
0356: if (XMLUtil.getPackage(referenced) != pkg
0357: && pkg.getParticipant(referenced.getId()) != null) {
0358: return new ArrayList();
0359: }
0360:
0361: return getParticipantReferences(wp, referenced.getId());
0362: }
0363:
0364: public List getParticipantReferences(WorkflowProcess wp,
0365: String referencedId) {
0366: List references = new ArrayList();
0367: if (referencedId.equals("")) {
0368: return references;
0369: }
0370: references.addAll(tGetParticipantReferences(wp, referencedId));
0371:
0372: Iterator it = wp.getActivitySets().toElements().iterator();
0373: while (it.hasNext()) {
0374: ActivitySet as = (ActivitySet) it.next();
0375: references.addAll(tGetParticipantReferences(as,
0376: referencedId));
0377: }
0378:
0379: return references;
0380: }
0381:
0382: protected List tGetParticipantReferences(
0383: XMLComplexElement pkgOrWpOrAs, String referencedId) {
0384: List references = new ArrayList();
0385: if (referencedId.equals("")) {
0386: return references;
0387: }
0388:
0389: if (!(pkgOrWpOrAs instanceof ActivitySet)) {
0390: Iterator it = ((RedefinableHeader) pkgOrWpOrAs
0391: .get("RedefinableHeader")).getResponsibles()
0392: .toElements().iterator();
0393: while (it.hasNext()) {
0394: Responsible rs = (Responsible) it.next();
0395: if (rs.toValue().equals(referencedId)) {
0396: references.add(rs);
0397: }
0398: }
0399: }
0400: if (!(pkgOrWpOrAs instanceof Package)) {
0401: Iterator it = ((Activities) pkgOrWpOrAs.get("Activities"))
0402: .toElements().iterator();
0403: while (it.hasNext()) {
0404: Activity act = (Activity) it.next();
0405: String perf = act.getPerformer();
0406: if (perf.equals(referencedId)) {
0407: references.add(act.get("Performer"));
0408: }
0409: }
0410: }
0411:
0412: return references;
0413: }
0414:
0415: public List getApplicationReferences(XMLComplexElement pkgOrWp,
0416: String referencedId) {
0417: if (referencedId.equals("")) {
0418: return new ArrayList();
0419: }
0420: if (pkgOrWp instanceof Package) {
0421: return getApplicationReferences((Package) pkgOrWp,
0422: referencedId);
0423: }
0424:
0425: return getApplicationReferences((WorkflowProcess) pkgOrWp,
0426: referencedId);
0427: }
0428:
0429: public List getReferences(Package pkg, Application referenced) {
0430: if (XMLUtil.getPackage(referenced) != pkg
0431: && pkg.getApplication(referenced.getId()) != null) {
0432: return new ArrayList();
0433: }
0434:
0435: return getApplicationReferences(pkg, referenced.getId());
0436: }
0437:
0438: public List getApplicationReferences(Package pkg,
0439: String referencedId) {
0440: List references = new ArrayList();
0441: if (referencedId.equals("")) {
0442: return references;
0443: }
0444:
0445: Iterator it = pkg.getWorkflowProcesses().toElements()
0446: .iterator();
0447: while (it.hasNext()) {
0448: WorkflowProcess wp = (WorkflowProcess) it.next();
0449: if (wp.getApplication(referencedId) == null) {
0450: references.addAll(getApplicationReferences(wp,
0451: referencedId));
0452: }
0453: }
0454:
0455: return references;
0456: }
0457:
0458: public List getReferences(WorkflowProcess wp, Application referenced) {
0459: if (XMLUtil.getWorkflowProcess(referenced) == null
0460: && wp.getApplication(referenced.getId()) != null) {
0461: return new ArrayList();
0462: }
0463: Package pkg = XMLUtil.getPackage(wp);
0464: if (XMLUtil.getPackage(referenced) != pkg
0465: && pkg.getParticipant(referenced.getId()) != null) {
0466: return new ArrayList();
0467: }
0468:
0469: return getApplicationReferences(wp, referenced.getId());
0470: }
0471:
0472: public List getApplicationReferences(WorkflowProcess wp,
0473: String referencedId) {
0474: List references = new ArrayList();
0475: if (referencedId.equals("")) {
0476: return references;
0477: }
0478:
0479: references.addAll(tGetApplicationReferences(wp, referencedId));
0480:
0481: Iterator it = wp.getActivitySets().toElements().iterator();
0482: while (it.hasNext()) {
0483: ActivitySet as = (ActivitySet) it.next();
0484: references.addAll(tGetApplicationReferences(as,
0485: referencedId));
0486: }
0487:
0488: return references;
0489: }
0490:
0491: protected List tGetApplicationReferences(
0492: XMLCollectionElement wpOrAs, String referencedId) {
0493: List references = new ArrayList();
0494: if (referencedId.equals("")) {
0495: return references;
0496: }
0497:
0498: List types = new ArrayList();
0499: types.add(new Integer(XPDLConstants.ACTIVITY_TYPE_TOOL));
0500: Iterator it = getActivities(
0501: (Activities) wpOrAs.get("Activities"), types)
0502: .iterator();
0503: while (it.hasNext()) {
0504: Activity act = (Activity) it.next();
0505: Iterator tools = act.getActivityTypes().getImplementation()
0506: .getImplementationTypes().getTools().toElements()
0507: .iterator();
0508: while (tools.hasNext()) {
0509: Tool t = (Tool) tools.next();
0510: if (t.getId().equals(referencedId)) {
0511: references.add(t);
0512: }
0513: }
0514: }
0515:
0516: return references;
0517: }
0518:
0519: public List getDataFieldReferences(XMLComplexElement pkgOrWp,
0520: String referencedId) {
0521: if (referencedId.equals("")) {
0522: return new ArrayList();
0523: }
0524: if (pkgOrWp instanceof Package) {
0525: return getDataFieldReferences((Package) pkgOrWp,
0526: referencedId);
0527: }
0528:
0529: return getDataFieldReferences((WorkflowProcess) pkgOrWp,
0530: referencedId);
0531: }
0532:
0533: public List getReferences(Package pkg, DataField referenced) {
0534: return getDataFieldReferences(pkg, referenced.getId());
0535: }
0536:
0537: public List getDataFieldReferences(Package pkg, String referencedId) {
0538: List references = new ArrayList();
0539: if (referencedId.equals("")) {
0540: return references;
0541: }
0542:
0543: Iterator it = pkg.getWorkflowProcesses().toElements()
0544: .iterator();
0545: while (it.hasNext()) {
0546: WorkflowProcess wp = (WorkflowProcess) it.next();
0547: if (wp.getDataField(referencedId) == null) {
0548: references.addAll(getDataFieldReferences(wp,
0549: referencedId));
0550: }
0551: }
0552:
0553: return references;
0554: }
0555:
0556: public List getReferences(WorkflowProcess wp, DataField referenced) {
0557: if (XMLUtil.getWorkflowProcess(referenced) == null
0558: && (wp.getDataField(referenced.getId()) != null || wp
0559: .getFormalParameter(referenced.getId()) != null)) {
0560: return new ArrayList();
0561: }
0562:
0563: return getDataFieldReferences(wp, referenced.getId());
0564: }
0565:
0566: public List getDataFieldReferences(WorkflowProcess wp,
0567: String referencedId) {
0568: List references = new ArrayList();
0569: if (referencedId.equals("")) {
0570: return references;
0571: }
0572:
0573: references.addAll(getVariableReferences(wp, referencedId));
0574:
0575: Iterator it = wp.getActivitySets().toElements().iterator();
0576: while (it.hasNext()) {
0577: ActivitySet as = (ActivitySet) it.next();
0578: references.addAll(getVariableReferences(as, referencedId));
0579: }
0580:
0581: return references;
0582: }
0583:
0584: public List getReferences(Package pkg, WorkflowProcess referenced) {
0585: List references = new ArrayList();
0586: if (XMLUtil.getPackage(referenced) != pkg
0587: && pkg.getWorkflowProcess(referenced.getId()) != null) {
0588: return references;
0589: }
0590:
0591: Iterator it = pkg.getWorkflowProcesses().toElements()
0592: .iterator();
0593: while (it.hasNext()) {
0594: WorkflowProcess wp = (WorkflowProcess) it.next();
0595: references.addAll(getReferences(wp, referenced));
0596: }
0597:
0598: return references;
0599: }
0600:
0601: public List getWorkflowProcessReferences(Package pkg,
0602: String referencedId) {
0603: List references = new ArrayList();
0604: if (referencedId.equals("")) {
0605: return references;
0606: }
0607:
0608: Iterator it = pkg.getWorkflowProcesses().toElements()
0609: .iterator();
0610: while (it.hasNext()) {
0611: WorkflowProcess wp = (WorkflowProcess) it.next();
0612: references.addAll(getWorkflowProcessReferences(wp,
0613: referencedId));
0614: }
0615:
0616: return references;
0617: }
0618:
0619: public List getReferences(WorkflowProcess wp,
0620: WorkflowProcess referenced) {
0621: return getWorkflowProcessReferences(wp, referenced.getId());
0622: }
0623:
0624: public List getWorkflowProcessReferences(WorkflowProcess wp,
0625: String referencedId) {
0626: List references = new ArrayList();
0627: if (referencedId.equals("")) {
0628: return references;
0629: }
0630:
0631: references.addAll(tGetWorkflowProcessReferences(wp,
0632: referencedId));
0633:
0634: Iterator it = wp.getActivitySets().toElements().iterator();
0635: while (it.hasNext()) {
0636: ActivitySet as = (ActivitySet) it.next();
0637: references.addAll(tGetWorkflowProcessReferences(as,
0638: referencedId));
0639: }
0640:
0641: return references;
0642: }
0643:
0644: protected List tGetWorkflowProcessReferences(
0645: XMLCollectionElement wpOrAs, String referencedId) {
0646: List references = new ArrayList();
0647: if (referencedId.equals("")) {
0648: return references;
0649: }
0650:
0651: List types = new ArrayList();
0652: types.add(new Integer(XPDLConstants.ACTIVITY_TYPE_SUBFLOW));
0653: Iterator it = getActivities(
0654: (Activities) wpOrAs.get("Activities"), types)
0655: .iterator();
0656: while (it.hasNext()) {
0657: Activity act = (Activity) it.next();
0658: SubFlow s = act.getActivityTypes().getImplementation()
0659: .getImplementationTypes().getSubFlow();
0660: if (s.getId().equals(referencedId)) {
0661: references.add(s);
0662: }
0663: }
0664:
0665: return references;
0666: }
0667:
0668: public List getReferences(WorkflowProcess wp,
0669: FormalParameter referenced) {
0670: List references = new ArrayList();
0671: if (!(referenced.getParent().getParent() instanceof WorkflowProcess)) {
0672: return references;
0673: }
0674:
0675: return getFormalParameterReferences(wp, referenced.getId());
0676: }
0677:
0678: public List getFormalParameterReferences(WorkflowProcess wp,
0679: String referencedId) {
0680: List references = new ArrayList();
0681: if (referencedId.equals("")) {
0682: return references;
0683: }
0684: if (wp.getDataField(referencedId) != null) {
0685: return references;
0686: }
0687:
0688: references.addAll(getVariableReferences(wp, referencedId));
0689:
0690: Iterator it = wp.getActivitySets().toElements().iterator();
0691: while (it.hasNext()) {
0692: ActivitySet as = (ActivitySet) it.next();
0693: references.addAll(getVariableReferences(as, referencedId));
0694: }
0695:
0696: return references;
0697: }
0698:
0699: protected List getVariableReferences(XMLCollectionElement wpOrAs,
0700: String dfOrFpId) {
0701: List references = new ArrayList();
0702: if (dfOrFpId.equals("")) {
0703: return references;
0704: }
0705:
0706: Map allVars = XMLUtil.getWorkflowProcess(wpOrAs)
0707: .getAllVariables();
0708: Iterator it = ((Activities) wpOrAs.get("Activities"))
0709: .toElements().iterator();
0710: while (it.hasNext()) {
0711: Activity act = (Activity) it.next();
0712: int type = act.getActivityType();
0713: // actual parameter (can be expression containing variable, or direct variable
0714: // reference)
0715: List aps = new ArrayList();
0716: if (type == XPDLConstants.ACTIVITY_TYPE_SUBFLOW) {
0717: aps.addAll(act.getActivityTypes().getImplementation()
0718: .getImplementationTypes().getSubFlow()
0719: .getActualParameters().toElements());
0720: } else if (type == XPDLConstants.ACTIVITY_TYPE_TOOL) {
0721: Tools tools = act.getActivityTypes()
0722: .getImplementation().getImplementationTypes()
0723: .getTools();
0724: Iterator itt = tools.toElements().iterator();
0725: while (itt.hasNext()) {
0726: Tool t = (Tool) itt.next();
0727: aps.addAll(t.getActualParameters().toElements());
0728: }
0729: }
0730: Iterator itap = aps.iterator();
0731: while (itap.hasNext()) {
0732: ActualParameter ap = (ActualParameter) itap.next();
0733: if (XMLUtil.getUsingPositions(ap.toValue(), dfOrFpId,
0734: allVars).size() > 0) {
0735: references.add(ap);
0736: }
0737: }
0738:
0739: Iterator itdls = act.getDeadlines().toElements().iterator();
0740: while (itdls.hasNext()) {
0741: Deadline dl = (Deadline) itdls.next();
0742: String dcond = dl.getDeadlineCondition();
0743: if (XMLUtil.getUsingPositions(dcond, dfOrFpId, allVars)
0744: .size() > 0) {
0745: references.add(dl.get("DeadlineCondition"));
0746: }
0747: }
0748:
0749: // performer (can be expression containing variable, or direct variable
0750: // reference)
0751: String perf = act.getPerformer();
0752: if (XMLUtil.getUsingPositions(perf, dfOrFpId, allVars)
0753: .size() > 0) {
0754: references.add(act.get("Performer"));
0755: }
0756: }
0757:
0758: // transition condition (can be expression containing variable, or direct variable
0759: // reference)
0760: it = ((Transitions) wpOrAs.get("Transitions")).toElements()
0761: .iterator();
0762: while (it.hasNext()) {
0763: Transition t = (Transition) it.next();
0764: if (XMLUtil.getUsingPositions(t.getCondition().toValue(),
0765: dfOrFpId, allVars).size() > 0) {
0766: references.add(t.getCondition());
0767: }
0768: }
0769:
0770: return references;
0771: }
0772:
0773: public List getReferences(WorkflowProcess wp, ActivitySet referenced) {
0774: return getActivitySetReferences(wp, referenced.getId());
0775: }
0776:
0777: public List getActivitySetReferences(WorkflowProcess wp,
0778: String referencedId) {
0779: List references = new ArrayList();
0780: if (referencedId.equals("")) {
0781: return references;
0782: }
0783:
0784: references.addAll(tGetActivitySetReferences(wp, referencedId));
0785:
0786: Iterator it = wp.getActivitySets().toElements().iterator();
0787: while (it.hasNext()) {
0788: ActivitySet as = (ActivitySet) it.next();
0789: references.addAll(tGetActivitySetReferences(as,
0790: referencedId));
0791: }
0792:
0793: return references;
0794: }
0795:
0796: public List getReferences(ActivitySet as, ActivitySet referenced) {
0797: return tGetActivitySetReferences(as, referenced.getId());
0798: }
0799:
0800: public List getReferences(ActivitySet as, String referencedId) {
0801: return tGetActivitySetReferences(as, referencedId);
0802: }
0803:
0804: public List tGetActivitySetReferences(XMLCollectionElement wpOrAs,
0805: String referencedId) {
0806: List references = new ArrayList();
0807: if (referencedId.equals("")) {
0808: return references;
0809: }
0810:
0811: List types = new ArrayList();
0812: types.add(new Integer(XPDLConstants.ACTIVITY_TYPE_BLOCK));
0813: Iterator it = getActivities(
0814: (Activities) wpOrAs.get("Activities"), types)
0815: .iterator();
0816: while (it.hasNext()) {
0817: Activity act = (Activity) it.next();
0818: BlockActivity ba = act.getActivityTypes()
0819: .getBlockActivity();
0820: if (ba.getBlockId().equals(referencedId)) {
0821: references.add(ba);
0822: }
0823: }
0824:
0825: return references;
0826: }
0827:
0828: public List getReferences(Activity act) {
0829: Set refs = XMLUtil.getIncomingTransitions(act);
0830: refs.addAll(XMLUtil.getOutgoingTransitions(act));
0831: return new ArrayList(refs);
0832: }
0833:
0834: public List getReferences(Transition tra) {
0835: Activities acts = (Activities) ((XMLCollectionElement) tra
0836: .getParent().getParent()).get("Activities");
0837: Activity from = acts.getActivity(tra.getFrom());
0838: Activity to = acts.getActivity(tra.getTo());
0839: Set refs = new HashSet();
0840: if (from != null) {
0841: refs.add(from);
0842: }
0843: if (to != null) {
0844: refs.add(to);
0845: }
0846: return new ArrayList(refs);
0847: }
0848:
0849: public boolean correctSplitsAndJoins(Package pkg) {
0850: boolean changed = false;
0851:
0852: Iterator it = pkg.getWorkflowProcesses().toElements()
0853: .iterator();
0854: while (it.hasNext()) {
0855: WorkflowProcess wp = (WorkflowProcess) it.next();
0856: changed = correctSplitsAndJoins(wp) || changed;
0857: }
0858: return changed;
0859: }
0860:
0861: public boolean correctSplitsAndJoins(WorkflowProcess wp) {
0862: boolean changed = correctSplitsAndJoins(wp.getActivities()
0863: .toElements());
0864: Iterator it = wp.getActivitySets().toElements().iterator();
0865: while (it.hasNext()) {
0866: ActivitySet as = (ActivitySet) it.next();
0867: changed = correctSplitsAndJoins(as.getActivities()
0868: .toElements())
0869: || changed;
0870: }
0871: return changed;
0872: }
0873:
0874: public boolean correctSplitsAndJoins(List acts) {
0875: boolean changed = false;
0876: Iterator it = acts.iterator();
0877: while (it.hasNext()) {
0878: Activity act = (Activity) it.next();
0879: changed = correctSplitAndJoin(act) || changed;
0880: }
0881: return changed;
0882: }
0883:
0884: public boolean correctSplitAndJoin(Activity act) {
0885: Set ogt = XMLUtil.getOutgoingTransitions(act);
0886: Set inct = XMLUtil.getIncomingTransitions(act);
0887: TransitionRestrictions tres = act.getTransitionRestrictions();
0888: TransitionRestriction tr = null;
0889: boolean newTres = false;
0890: boolean changed = false;
0891: // LoggingManager lm=JaWEManager.getInstance().getLoggingManager();
0892: // lm.debug("Correcting split and join for activity "+act.getId()+",
0893: // ogts="+ogt.size()+", incts="+inct.size());
0894: if (tres.size() == 0) {
0895: if (ogt.size() > 1 || inct.size() > 1) {
0896: tr = JaWEManager.getInstance().getXPDLObjectFactory()
0897: .createXPDLObject(tres, "", false);
0898: newTres = true;
0899: } else {
0900: return false;
0901: }
0902: } else {
0903: tr = (TransitionRestriction) tres.get(0);
0904: }
0905:
0906: Split s = tr.getSplit();
0907: Join j = tr.getJoin();
0908:
0909: TransitionRefs trefs = s.getTransitionRefs();
0910: if (ogt.size() <= 1) {
0911: if (trefs.size() > 0) {
0912: trefs.clear();
0913: changed = true;
0914: }
0915: if (!s.getType().equals(XPDLConstants.JOIN_SPLIT_TYPE_NONE)) {
0916: s.setTypeNONE();
0917: changed = true;
0918: }
0919: }
0920: if (ogt.size() > 1) {
0921:
0922: if (s.getType().equals(XPDLConstants.JOIN_SPLIT_TYPE_NONE)) {
0923: s.setTypeXOR();
0924: // lm.debug("--------------------- st set to xor");
0925: changed = true;
0926: }
0927:
0928: List trefIds = new ArrayList();
0929: for (int i = 0; i < trefs.size(); i++) {
0930: TransitionRef tref = (TransitionRef) trefs.get(i);
0931: trefIds.add(tref.getId());
0932: }
0933:
0934: List transitionIds = new ArrayList();
0935: Iterator it = ogt.iterator();
0936: while (it.hasNext()) {
0937: Transition t = (Transition) it.next();
0938: transitionIds.add(t.getId());
0939: }
0940:
0941: List toRem = new ArrayList(trefIds);
0942: toRem.removeAll(transitionIds);
0943: List toAdd = new ArrayList(transitionIds);
0944: toAdd.removeAll(trefIds);
0945:
0946: for (int i = 0; i < toRem.size(); i++) {
0947: TransitionRef tref = trefs
0948: .getTransitionRef((String) toRem.get(i));
0949: trefs.remove(tref);
0950: changed = true;
0951: }
0952: for (int i = 0; i < toAdd.size(); i++) {
0953: TransitionRef tref = JaWEManager.getInstance()
0954: .getXPDLObjectFactory().createXPDLObject(trefs,
0955: "", false);
0956: tref.setId((String) toAdd.get(i));
0957: trefs.add(tref);
0958: changed = true;
0959: }
0960: }
0961:
0962: if (inct.size() <= 1) {
0963: if (!j.getType().equals(XPDLConstants.JOIN_SPLIT_TYPE_NONE)) {
0964: j.setTypeNONE();
0965: changed = true;
0966: }
0967: } else {
0968: if (j.getType().equals(XPDLConstants.JOIN_SPLIT_TYPE_NONE)) {
0969: j.setTypeXOR();
0970: changed = true;
0971: }
0972: }
0973: // lm.debug("--------------------- st="+s.getType()+", jt="+j.getType()+",
0974: // trefss="+trefs.size());
0975:
0976: if (s.getType().equals(XPDLConstants.JOIN_SPLIT_TYPE_NONE)
0977: && j.getType().equals(
0978: XPDLConstants.JOIN_SPLIT_TYPE_NONE)) {
0979: if (!newTres) {
0980: tres.remove(tr);
0981: changed = true;
0982: }
0983: } else if (newTres) {
0984: tres.add(tr);
0985: }
0986:
0987: return changed;
0988: }
0989:
0990: public void updateTransitionsOnActivityIdChange(Transitions tras,
0991: String oldActId, String newActId) {
0992: List inc = getTransitions(tras, oldActId, true);
0993: Iterator it = inc.iterator();
0994: while (it.hasNext()) {
0995: Transition tra = (Transition) it.next();
0996: tra.setTo(newActId);
0997: }
0998: List outg = getTransitions(tras, oldActId, false);
0999: it = outg.iterator();
1000: while (it.hasNext()) {
1001: Transition tra = (Transition) it.next();
1002: tra.setFrom(newActId);
1003: }
1004: }
1005:
1006: public void updateActivityOnTransitionIdChange(Activities acts,
1007: String actFromId, String oldTraId, String newTraId) {
1008: Activity act = acts.getActivity(actFromId);
1009: updateActivityOnTransitionIdChange(act, oldTraId, newTraId);
1010: }
1011:
1012: public void updateActivityOnTransitionIdChange(Activity act,
1013: String oldTraId, String newTraId) {
1014: if (act != null) {
1015: Split s = XMLUtil.getSplit(act);
1016: if (s != null) {
1017: TransitionRef tref = s.getTransitionRefs()
1018: .getTransitionRef(oldTraId);
1019: if (tref != null) {
1020: tref.setId(newTraId);
1021: }
1022: }
1023: }
1024: }
1025:
1026: public void updateActivitiesOnTransitionFromChange(Activities acts,
1027: String traId, String traOldFromId, String traNewFromId) {
1028: if (traOldFromId != null) {
1029: Activity act = acts.getActivity(traOldFromId);
1030: if (act != null) {
1031: correctSplitAndJoin(act);
1032: }
1033: }
1034: if (traNewFromId != null) {
1035: Activity act = acts.getActivity(traNewFromId);
1036: if (act != null) {
1037: correctSplitAndJoin(act);
1038: }
1039: }
1040: }
1041:
1042: public void updateActivitiesOnTransitionToChange(Activities acts,
1043: String traId, String traOldToId, String traNewToId) {
1044: if (traOldToId != null) {
1045: Activity act = acts.getActivity(traOldToId);
1046: if (act != null) {
1047: correctSplitAndJoin(act);
1048: }
1049: }
1050: if (traNewToId != null) {
1051: Activity act = acts.getActivity(traNewToId);
1052: if (act != null) {
1053: correctSplitAndJoin(act);
1054: }
1055: }
1056: }
1057:
1058: public void removeTransitionsForActivity(Activity act) {
1059: Set trasToRemove = getTransitionsForActivity(act);
1060: Transitions trs = (Transitions) ((XMLCollectionElement) act
1061: .getParent().getParent()).get("Transitions");
1062: Activities acs = (Activities) act.getParent();
1063:
1064: if (trasToRemove.size() > 0) {
1065: Iterator itt = trasToRemove.iterator();
1066: while (itt.hasNext()) {
1067: Transition t = (Transition) itt.next();
1068: Activity from = acs.getActivity(t.getFrom());
1069: Activity to = acs.getActivity(t.getTo());
1070: if (from != act && from != null) {
1071: correctSplitAndJoin(from);
1072: }
1073: if (to != act && to != null) {
1074: correctSplitAndJoin(to);
1075: }
1076: }
1077: trs.removeAll(new ArrayList(trasToRemove));
1078: }
1079:
1080: }
1081:
1082: public void removeTransitionsForActivities(List acts) {
1083: if (acts.size() == 0)
1084: return;
1085: Activities acs = (Activities) ((Activity) acts.get(0))
1086: .getParent();
1087: Set trasToRemove = new HashSet();
1088: Iterator it = acts.iterator();
1089: while (it.hasNext()) {
1090: Activity act = (Activity) it.next();
1091: trasToRemove.addAll(getTransitionsForActivity(act));
1092: }
1093: if (trasToRemove.size() > 0) {
1094: Transitions trs = (Transitions) ((XMLCollectionElement) trasToRemove
1095: .toArray()[0]).getParent();
1096: trs.removeAll(new ArrayList(trasToRemove));
1097: Iterator itt = trasToRemove.iterator();
1098: while (itt.hasNext()) {
1099: Transition t = (Transition) itt.next();
1100: Activity from = acs.getActivity(t.getFrom());
1101: Activity to = acs.getActivity(t.getTo());
1102: if (from != null && !acts.contains(from)) {
1103: correctSplitAndJoin(from);
1104: }
1105: if (to != null && !acts.contains(to)) {
1106: correctSplitAndJoin(to);
1107: }
1108: }
1109: }
1110: }
1111:
1112: protected Set getTransitionsForActivity(Activity act) {
1113: Set trasToRemove = XMLUtil.getIncomingTransitions(act);
1114: trasToRemove.addAll(XMLUtil.getOutgoingTransitions(act));
1115: return trasToRemove;
1116: }
1117:
1118: public List getTransitions(Transitions tras, String actId,
1119: boolean isToAct) {
1120: List l = new ArrayList();
1121: Iterator it = tras.toElements().iterator();
1122: while (it.hasNext()) {
1123: Transition t = (Transition) it.next();
1124: if (isToAct) {
1125: if (t.getTo().equals(actId)) {
1126: l.add(t);
1127: }
1128: } else {
1129: if (t.getFrom().equals(actId)) {
1130: l.add(t);
1131: }
1132: }
1133: }
1134: return l;
1135: }
1136:
1137: public void updateTypeDeclarationReferences(List refDeclaredTypes,
1138: String newTdId) {
1139: Iterator it = refDeclaredTypes.iterator();
1140: while (it.hasNext()) {
1141: DeclaredType dt = (DeclaredType) it.next();
1142: dt.setId(newTdId);
1143: }
1144: }
1145:
1146: public void updateApplicationReferences(List refTools,
1147: String newAppId) {
1148: Iterator it = refTools.iterator();
1149: while (it.hasNext()) {
1150: Tool t = (Tool) it.next();
1151: t.setId(newAppId);
1152: }
1153: }
1154:
1155: public void updateParticipantReferences(List refPerfsAndResps,
1156: String newParId) {
1157: Iterator it = refPerfsAndResps.iterator();
1158: while (it.hasNext()) {
1159: XMLElement pOrR = (XMLElement) it.next();
1160: pOrR.setValue(newParId);
1161: }
1162: }
1163:
1164: public void updateWorkflowProcessReferences(List refSbflws,
1165: String newWpId) {
1166: Iterator it = refSbflws.iterator();
1167: while (it.hasNext()) {
1168: SubFlow s = (SubFlow) it.next();
1169: s.setId(newWpId);
1170: }
1171: }
1172:
1173: public void updateActivitySetReferences(List refBlocks,
1174: String newAsId) {
1175: Iterator it = refBlocks.iterator();
1176: while (it.hasNext()) {
1177: BlockActivity ba = (BlockActivity) it.next();
1178: ba.setBlockId(newAsId);
1179: }
1180: }
1181:
1182: public void updateVariableReferences(
1183: List refAPsOrPerfsOrCondsOrDlConds, String oldDfOrFpId,
1184: String newDfOrFpId) {
1185: Iterator it = refAPsOrPerfsOrCondsOrDlConds.iterator();
1186: int varLengthDiff = newDfOrFpId.length() - oldDfOrFpId.length();
1187: while (it.hasNext()) {
1188: XMLElement apOrPerfOrCondOrDlCond = (XMLElement) it.next();
1189: String expr = apOrPerfOrCondOrDlCond.toValue();
1190: List positions = XMLUtil.getUsingPositions(expr,
1191: oldDfOrFpId, XMLUtil.getWorkflowProcess(
1192: apOrPerfOrCondOrDlCond).getAllVariables());
1193: for (int i = 0; i < positions.size(); i++) {
1194: int pos = ((Integer) positions.get(i)).intValue();
1195: int realPos = pos + varLengthDiff * i;
1196: String pref = expr.substring(0, realPos);
1197: String suff = expr.substring(realPos
1198: + oldDfOrFpId.length());
1199: expr = pref + newDfOrFpId + suff;
1200: // System.out.println("Pref="+pref+", suff="+suff+", expr="+expr);
1201: }
1202: apOrPerfOrCondOrDlCond.setValue(expr);
1203: }
1204: }
1205:
1206: public List getActivities(Package pkg, List types) {
1207: List l = new ArrayList();
1208: Iterator it = pkg.getWorkflowProcesses().toElements()
1209: .iterator();
1210: while (it.hasNext()) {
1211: WorkflowProcess wp = (WorkflowProcess) it.next();
1212: l.addAll(getActivities(wp, types));
1213: }
1214: return l;
1215: }
1216:
1217: public List getActivities(WorkflowProcess wp, List types) {
1218: List l = new ArrayList();
1219: l.addAll(getActivities(wp.getActivities(), types));
1220: Iterator it = wp.getActivitySets().toElements().iterator();
1221: while (it.hasNext()) {
1222: ActivitySet as = (ActivitySet) it.next();
1223: l.addAll(getActivities(as.getActivities(), types));
1224: }
1225: return l;
1226: }
1227:
1228: public List getActivities(Activities acts, List types) {
1229: List l = new ArrayList();
1230:
1231: Iterator it = acts.toElements().iterator();
1232: while (it.hasNext()) {
1233: Activity act = (Activity) it.next();
1234: int type = act.getActivityType();
1235: if (types.contains(new Integer(type))) {
1236: l.add(act);
1237: }
1238: }
1239:
1240: return l;
1241: }
1242:
1243: public SequencedHashMap getPossibleResponsibles(Responsibles resp,
1244: Responsible rsp) {
1245: SequencedHashMap choices = null;
1246: if (XMLUtil.getWorkflowProcess(resp) != null) {
1247: choices = XMLUtil.getPossibleParticipants(XMLUtil
1248: .getWorkflowProcess(resp), JaWEManager
1249: .getInstance().getXPDLHandler());
1250: } else {
1251: choices = XMLUtil.getPossibleParticipants(XMLUtil
1252: .getPackage(resp), JaWEManager.getInstance()
1253: .getXPDLHandler());
1254: }
1255: // filter choices: exclude already existing performers
1256: Iterator it = resp.toElements().iterator();
1257: while (it.hasNext()) {
1258: Responsible r = (Responsible) it.next();
1259: if (r != rsp) {
1260: choices.remove(r.toValue());
1261: }
1262: }
1263: return choices;
1264: }
1265:
1266: public boolean doesCrossreferenceExist(Package pkg) {
1267: XPDLHandler xpdlhandler = JaWEManager.getInstance()
1268: .getXPDLHandler();
1269: boolean crossRefs = false;
1270:
1271: Iterator epids = pkg.getExternalPackageIds().iterator();
1272: while (epids.hasNext()) {
1273: try {
1274: Package extP = xpdlhandler
1275: .getPackageById((String) epids.next());
1276: if (XMLUtil.getAllExternalPackageIds(xpdlhandler, extP,
1277: new HashSet()).contains(pkg.getId())) {
1278: crossRefs = true;
1279: break;
1280: }
1281: } catch (Exception ex) {
1282: }
1283: }
1284: return crossRefs;
1285: }
1286:
1287: public Set getAllExtendedAttributeNames(XMLComplexElement cel,
1288: XPDLHandler xpdlh) {
1289: Set extAttribNames = new HashSet();
1290:
1291: Iterator it = xpdlh.getAllPackages().iterator();
1292: while (it.hasNext()) {
1293: extAttribNames.addAll(getAllExtendedAttributeNames(
1294: (Package) it.next(), cel));
1295: }
1296: return extAttribNames;
1297: }
1298:
1299: public Set getAllExtendedAttributeNames(Package pkg,
1300: XMLComplexElement cel) {
1301: Set extAttribNames = new HashSet();
1302: if (cel instanceof Activity) {
1303: Iterator it = pkg.getWorkflowProcesses().toElements()
1304: .iterator();
1305: while (it.hasNext()) {
1306: WorkflowProcess wp = (WorkflowProcess) it.next();
1307: extAttribNames
1308: .addAll(getAllExtendedAttributeNamesForElements(wp
1309: .getActivities().toElements()));
1310:
1311: Iterator asets = wp.getActivitySets().toElements()
1312: .iterator();
1313: while (asets.hasNext()) {
1314: ActivitySet as = (ActivitySet) asets.next();
1315: extAttribNames
1316: .addAll(getAllExtendedAttributeNamesForElements(as
1317: .getActivities().toElements()));
1318: }
1319: }
1320: } else if (cel instanceof Application) {
1321: extAttribNames
1322: .addAll(getAllExtendedAttributeNamesForElements(pkg
1323: .getApplications().toElements()));
1324: Iterator it = pkg.getWorkflowProcesses().toElements()
1325: .iterator();
1326: while (it.hasNext()) {
1327: WorkflowProcess wp = (WorkflowProcess) it.next();
1328: extAttribNames
1329: .addAll(getAllExtendedAttributeNamesForElements(wp
1330: .getApplications().toElements()));
1331: }
1332: } else if (cel instanceof DataField) {
1333: extAttribNames
1334: .addAll(getAllExtendedAttributeNamesForElements(pkg
1335: .getDataFields().toElements()));
1336: Iterator it = pkg.getWorkflowProcesses().toElements()
1337: .iterator();
1338: while (it.hasNext()) {
1339: WorkflowProcess wp = (WorkflowProcess) it.next();
1340: extAttribNames
1341: .addAll(getAllExtendedAttributeNamesForElements(wp
1342: .getDataFields().toElements()));
1343: }
1344: } else if (cel instanceof ExternalPackage) {
1345: extAttribNames
1346: .addAll(getAllExtendedAttributeNamesForElements(pkg
1347: .getExternalPackages().toElements()));
1348: } else if (cel instanceof Package) {
1349: extAttribNames.addAll(getAllExtendedAttributeNames(pkg
1350: .getExtendedAttributes().toElements()));
1351: } else if (cel instanceof Participant) {
1352: extAttribNames
1353: .addAll(getAllExtendedAttributeNamesForElements(pkg
1354: .getParticipants().toElements()));
1355: Iterator it = pkg.getWorkflowProcesses().toElements()
1356: .iterator();
1357: while (it.hasNext()) {
1358: WorkflowProcess wp = (WorkflowProcess) it.next();
1359: extAttribNames
1360: .addAll(getAllExtendedAttributeNamesForElements(wp
1361: .getParticipants().toElements()));
1362: }
1363: } else if (cel instanceof Tool) {
1364: Iterator it = pkg.getWorkflowProcesses().toElements()
1365: .iterator();
1366: while (it.hasNext()) {
1367: WorkflowProcess wp = (WorkflowProcess) it.next();
1368: Iterator acti = wp.getActivities().toElements()
1369: .iterator();
1370: while (acti.hasNext()) {
1371: Activity act = (Activity) acti.next();
1372: if (act.getActivityType() == XPDLConstants.ACTIVITY_TYPE_TOOL) {
1373: Tools ts = act.getActivityTypes()
1374: .getImplementation()
1375: .getImplementationTypes().getTools();
1376: extAttribNames
1377: .addAll(getAllExtendedAttributeNamesForElements(ts
1378: .toElements()));
1379: }
1380: }
1381: Iterator asets = wp.getActivitySets().toElements()
1382: .iterator();
1383: while (asets.hasNext()) {
1384: ActivitySet as = (ActivitySet) asets.next();
1385: acti = as.getActivities().toElements().iterator();
1386: while (acti.hasNext()) {
1387: Activity act = (Activity) acti.next();
1388: if (act.getActivityType() == XPDLConstants.ACTIVITY_TYPE_TOOL) {
1389: Tools ts = act.getActivityTypes()
1390: .getImplementation()
1391: .getImplementationTypes()
1392: .getTools();
1393: extAttribNames
1394: .addAll(getAllExtendedAttributeNamesForElements(ts
1395: .toElements()));
1396: }
1397: }
1398: }
1399: }
1400: } else if (cel instanceof Transition) {
1401: Iterator it = pkg.getWorkflowProcesses().toElements()
1402: .iterator();
1403: while (it.hasNext()) {
1404: WorkflowProcess wp = (WorkflowProcess) it.next();
1405: extAttribNames
1406: .addAll(getAllExtendedAttributeNamesForElements(wp
1407: .getTransitions().toElements()));
1408: Iterator asets = wp.getActivitySets().toElements()
1409: .iterator();
1410: while (asets.hasNext()) {
1411: ActivitySet as = (ActivitySet) asets.next();
1412: extAttribNames
1413: .addAll(getAllExtendedAttributeNamesForElements(as
1414: .getTransitions().toElements()));
1415: }
1416: }
1417: } else if (cel instanceof TypeDeclaration) {
1418: extAttribNames
1419: .addAll(getAllExtendedAttributeNamesForElements(pkg
1420: .getTypeDeclarations().toElements()));
1421: } else if (cel instanceof WorkflowProcess) {
1422: extAttribNames
1423: .addAll(getAllExtendedAttributeNamesForElements(pkg
1424: .getWorkflowProcesses().toElements()));
1425: }
1426: return extAttribNames;
1427: }
1428:
1429: public Set getAllExtendedAttributeNamesForElements(
1430: Collection elements) {
1431: Set s = new HashSet();
1432: Iterator it = elements.iterator();
1433: while (it.hasNext()) {
1434: XMLComplexElement cel = (XMLComplexElement) it.next();
1435: s.addAll(((ExtendedAttributes) cel
1436: .get("ExtendedAttributes")).toElements());
1437: }
1438: return getAllExtendedAttributeNames(s);
1439: }
1440:
1441: public Set getAllExtendedAttributeNames(Collection extAttribs) {
1442: Set eaNames = new HashSet();
1443: Iterator it = extAttribs.iterator();
1444: while (it.hasNext()) {
1445: ExtendedAttribute ea = (ExtendedAttribute) it.next();
1446: String eaName = ea.getName();
1447: XMLElement pp = ea.getParent().getParent();
1448: if (pp instanceof XMLComplexElement
1449: && eaName.equals(JaWEEAHandler.EA_JAWE_TYPE)) {
1450: continue;
1451: }
1452: if (pp instanceof Package
1453: && (eaName.equals(JaWEEAHandler.EA_EDITING_TOOL)
1454: || eaName
1455: .equals(JaWEEAHandler.EA_EDITING_TOOL_VERSION)
1456: || eaName
1457: .equals(JaWEEAHandler.EA_JAWE_CONFIGURATION) || eaName
1458: .equals(JaWEEAHandler.EA_JAWE_EXTERNAL_PACKAGE_ID))) {
1459: continue;
1460: }
1461: if (pp instanceof WorkflowProcess
1462: && (eaName
1463: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION)
1464: || eaName
1465: .equals(GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION)
1466: || eaName
1467: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER)
1468: || eaName
1469: .equals(GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER)
1470: || eaName
1471: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW)
1472: || eaName
1473: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW)
1474: || eaName
1475: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK) || eaName
1476: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK))) {
1477: continue;
1478: }
1479: if (pp instanceof Activity
1480: && (eaName
1481: .equals(GraphEAConstants.EA_JAWE_GRAPH_OFFSET) || eaName
1482: .equals(GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID))) {
1483: continue;
1484: }
1485: if (pp instanceof Transition
1486: && (eaName
1487: .equals(GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS) || eaName
1488: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE))) {
1489: continue;
1490: }
1491: eaNames.add(eaName);
1492: }
1493: return eaNames;
1494: }
1495:
1496: }
|