KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > elements > FormalParameters


1 /* FormalParameters.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe.xml.elements;
12
13 import org.enhydra.jawe.xml.*;
14 import org.enhydra.jawe.xml.panels.*;
15
16 import java.util.*;
17
18 /**
19 * Represents a WfMC DTD element that has the similar name.
20 * This class is a collection of class <b>FormalParameter</b> instances.
21 *
22 * @see XML
23 */

24 public class FormalParameters extends XMLCollection {
25    /** The package which elements holds instance of this class. */
26    private transient Package JavaDoc myPackage=null;
27
28    int[] invisibleTableFieldOrdinals;
29
30    /**
31    * Creates a new instance of the class.
32    *
33    * @param myPackage The package which elements holds instance
34    * of this class.
35    */

36    public FormalParameters (XMLComplexElement myOwner,Package JavaDoc myPackage) {
37       super(myOwner);
38       this.myPackage=myPackage;
39
40       initInvisibleTableFieldOrdinals();
41    }
42
43    /**
44    * Generates a new element of the class which instances
45    * are members of collection of this class.
46    *
47    * return The generated instance of class that makes collection.
48    */

49    public XMLElement generateNewElement() {
50       FormalParameter fp=new FormalParameter(this,myPackage);
51       fp.setRequired(true);
52       return fp;
53    }
54
55    /**
56    * It is overriden to set the read-only property of Id attribute
57    * to the proper value in the case of formal parameters of workflow process:
58    * if FormalParameter instance is used in transition conditions,
59    * it is set to be read only, otherwise, it is set to be editable.
60    */

61    public Collection getTableElements () {
62       if (myOwner instanceof WorkflowProcess) {
63          if (!((WorkflowProcess)myOwner).getPackage().isReadOnly()) {
64             Iterator i = refCollectionElements.iterator();
65             while (i.hasNext()) {
66                FormalParameter fp=(FormalParameter)i.next();
67                // Checks for formal parameter if it is used inside some
68
// transition condition expression, and if it isn't, set
69
// it's ID attribute not to be read only.
70
if (!isUsedWithinTransitionConditions(fp)) {
71                   fp.get("Id").setReadOnly(false);
72                } else {
73                   fp.get("Id").setReadOnly(true);
74                }
75             }
76          }
77       }
78       return super.getTableElements();
79    }
80
81    /**
82    * Returns a formal parameter with specified ID.
83    *
84    * @param ID The 'Id' attribute of wanted instance of
85    * FormalParameter element defined within collection.
86    * @return The instance of FormalParameter element that
87    * have the specified ID as an 'Id' attribute
88    * if it exist among all defined formal parameters within
89    * collection, if it doesn't exist, <tt>null</tt> is
90    * returned.
91    */

92    public FormalParameter getFormalParameter (String JavaDoc ID) {
93       return (FormalParameter)super.getCollectionElement(ID);
94    }
95
96    /**
97    * Checks if specified formal parameter can be removed. FormalParameter
98    * can be removed only if it is not used anywhere.
99    */

100    public boolean canRemoveElement (XMLElement el) {
101       boolean remove=true;
102       FormalParameter toRemove=(FormalParameter)el;
103       // if this is FormalParameter from workflow process, check if it is
104
// used by any activity of subflow or generic type, or if it
105
// is used within transition conditions within workflow process
106
if (myOwner instanceof WorkflowProcess) {
107          Activities acts=(Activities)myOwner.get("Activities");
108          remove=acts.canRemoveDataFieldOrFormalParameter(toRemove);
109          // if it claims to be removed, check transitions
110
if (remove==true) {
111             Transitions ts=(Transitions)myOwner.get("Transitions");
112             remove=ts.canRemoveDataFieldOrFormalParameter(toRemove);
113          }
114          // if it claims to be removed, check activity sets
115
if (remove==true) {
116             ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets");
117             remove=actsts.canRemoveDataFieldOrFormalParameter(toRemove);
118          }
119       }
120       return remove;
121    }
122
123    protected boolean isUsedWithinTransitionConditions (FormalParameter fp) {
124       boolean inUse=false;
125       // if this is formal parameter from workflow process, check all transitions
126
// within this workflow process
127
if (myOwner instanceof WorkflowProcess) {
128          Transitions ts=(Transitions)myOwner.get("Transitions");
129          inUse=!ts.canRemoveDataFieldOrFormalParameter(fp);
130          // if it claims not to be used, check activity sets
131
if (inUse==false) {
132             ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets");
133             inUse=actsts.isDataFieldOrFormalParameterUsedWithinTransitionConditions(fp);
134          }
135       }
136       return inUse;
137    }
138
139    public int[] getInvisibleTableFieldOrdinals () {
140       return invisibleTableFieldOrdinals;
141    }
142
143    public XMLPanel getMiniContentPanel () {
144       invisibleTableFieldOrdinals=new int[2];
145       invisibleTableFieldOrdinals[0]=1;
146       invisibleTableFieldOrdinals[1]=4;
147       XMLPanel cpMini=new XMLTablePanel(this,toLabel(),false,true,true,coloringTable,true);
148       initInvisibleTableFieldOrdinals();
149       return cpMini;
150    }
151
152    private void initInvisibleTableFieldOrdinals () {
153       invisibleTableFieldOrdinals=new int[1];
154       invisibleTableFieldOrdinals[0]=4;
155    }
156
157 }
158
Popular Tags