KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ActualParameter.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 import org.w3c.dom.*;
18
19 /**
20 * Represents a WfMC DTD element that has the similar name.
21 *
22 * @see XML
23 */

24 public class ActualParameter extends XMLSimpleElement {
25    /**
26    * Reference to all defined DataFields, within workflow process
27    * that element which member is instance of this element belongs
28    * to, plus all defined DataFields within Package.
29    * These DataFields are used as ActualParameters.
30    */

31    private transient DataFields definedDataFields=null;
32
33    /**
34    * Creates a new instance of the class.
35    *
36    * @param wp workflow process that defines DataField objects
37    * which are used as actual parameters of an
38    * application or of a process itself.
39    */

40    public ActualParameter (WorkflowProcess wp) {
41       super();
42       try {
43          this.definedDataFields=(DataFields)wp.get("DataFields");
44       }
45       catch (NullPointerException JavaDoc npe) {
46          //
47
}
48    }
49
50    /**
51    * Prepares the panel with a combo box to choose the one of
52    * defined DataFields that will be used as an actual parameter.
53    *
54    * @return XMLPanel to be shown.
55    */

56    public XMLPanel getPanel () {
57       Object JavaDoc[] choices=null;
58       if (definedDataFields!=null) {
59          choices=definedDataFields.getChoosable().toArray();
60       }
61       else {
62          choices=null;
63       }
64       return new XMLComboButtonPanel(this,choices,definedDataFields,true);
65    }
66
67    /**
68    * Overrides super-class method to realize this class specific
69    * writting to XML file.
70    *
71    * @return The string for a WfMC DTD ActualParameter element tag.
72    */

73    public void toXML (Node parent) throws DOMException {
74       // the DataField or FormalParameter object is held in
75
// it's value member - if it isn't, there is no actual param.
76
// or there is one manually defined as expression
77
if (value==null) return;
78       if ((value instanceof DataField) || (value instanceof FormalParameter)) {
79          // prepearing DataField ID (or workflow process FormalParameter ID)
80
Object JavaDoc realValue=value;
81          //value=((DataField)value).getID();
82
value=((XMLCollectionElement)value).getID();
83          super.toXML(parent);
84          value=realValue;
85       } else {
86          super.toXML(parent);
87       }
88
89    }
90
91    /**
92    * Used to create exact copy of instance of this class.
93    * The newly created instance will have all the properties
94    * same as the copied one.
95    *
96    * @return The newly created instance of this class.
97    */

98    public Object JavaDoc clone () {
99       ActualParameter ap=(ActualParameter)super.clone();
100       // set the same datafield - (it was cloned to)
101
ap.setValue(this.toValue());
102       ap.definedDataFields=this.definedDataFields;
103       return ap;
104    }
105
106    /**
107    * Called by Tool or SubFlow object after importing of XML file to set
108    * the proper DataField objects for ActualParameter that correspodents
109    * to Application or WorkflowProcess formal parameter, depending on that
110    * who owns ActualParameter (Tool or Subflow). Data fields are set
111    * according to it's ID's read from XML.
112    */

113    protected void afterImporting () {
114       if (value==null) return;
115       Iterator it=definedDataFields.getChoosable().iterator();
116       while (it.hasNext()) {
117          XMLCollectionElement dfOrFp=(XMLCollectionElement)it.next();
118          //DataField df=(DataField)it.next();
119
if (dfOrFp.getID().equals(value.toString())) {
120             value=dfOrFp;
121             break;
122          }
123       }
124    }
125
126 }
127
Popular Tags