KickJava   Java API By Example, From Geeks To Geeks.

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


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

25 public class FormalParameter extends XMLCollectionElement {
26    private DataType refDataType;
27    private Description refDescription=new Description(); // min=0
28

29    private XMLAttribute attrIndex=new XMLAttribute("Index");
30    // default="IN"
31
private XMLAttribute attrMode=new XMLAttribute("Mode",
32       new String JavaDoc[] {
33          "",
34          "IN",
35          "OUT",
36          "INOUT"
37       },1);
38
39
40    /**
41    * Creates a new instance of the class.
42    *
43    * @param fps The reference to collection of formal parameters where
44    * this instance will be put into.
45    * @param p The package which elements holds instance of
46    * of this class.
47    */

48    public FormalParameter (FormalParameters fps,Package JavaDoc p) {
49       super(fps);
50
51       refDataType=new DataType(p);
52       fillStructure();
53    }
54
55    /**
56    * Defines the super-class method. Read the explanation for
57    * this method within XMLComplexElement class.
58    */

59    protected void fillStructure () {
60       super.fillStructure();
61       // allow ID to be modified if this is a formal parameter of workflow process
62
if (myCollection.getOwner() instanceof WorkflowProcess) {
63          attrId.setValue("");
64       }
65       complexStructure.add(attrIndex);
66       attributes.add(attrIndex);
67       complexStructure.add(attrMode);
68       attributes.add(attrMode);
69       refDataType.setRequired(true);
70       complexStructure.add(refDataType);
71       complexStructure.add(refDescription);
72    }
73
74
75    public void fromXML (Node node) {
76       attrMode.setValue("");
77       super.fromXML(node);
78    }
79
80    /**
81    * Checks if an ID entered by the user is unique.
82    */

83    public boolean isIDUniqueAndValid (XMLPanel groupPanel) {
84       XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0);
85       String JavaDoc IDToCheck=tp.getText();
86       // if there is an element with given ID, return false
87
FormalParameter fp=((FormalParameters)getCollection()).getFormalParameter(IDToCheck);
88       boolean isOK=true;
89       String JavaDoc message=null;
90       String JavaDoc dialogTitle=null;
91       if (fp!=null && fp!=this) {
92          message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique");
93          dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique");
94          isOK=false;
95       } else if (!XMLCollection.isIdValid(IDToCheck)) {
96          message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid");
97          dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid");
98          isOK=false;
99       }
100       if (!isOK) {
101          XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message);
102          ((JTextField)tp.getComponent(2)).requestFocus();
103       }
104       return isOK;
105    }
106
107    public String JavaDoc toString () {
108       if (myCollection.getOwner() instanceof WorkflowProcess) {
109          return attrId.toString();
110       } else {
111          return super.toString();
112       }
113    }
114
115    /**
116    * Overrides parent method to display data type details for BasicType and
117    * for DeclaredType.
118    */

119    public Collection toComplexTypeValues () {
120       java.util.List JavaDoc l=new ArrayList();
121       Iterator it=complexStructure.iterator();
122       while (it.hasNext()) {
123          XMLElement el=(XMLElement)it.next();
124          if (el instanceof XMLAttribute) {
125             l.add(el.toString());
126          } else if (el instanceof DataType) {
127             DataType dt=(DataType)el;
128             DataTypes dtt=(DataTypes)dt.get("Type");
129             Object JavaDoc type=dtt.toValue();
130             if (type instanceof BasicType) {
131                l.add(el.toValue()+" - "+((XMLAttribute)((BasicType)type).get("Type")).getChoosen());
132             } else if (type instanceof DeclaredType) {
133                l.add(el.toValue()+" - "+((XMLComplexChoice)((DeclaredType)type).get("SubType")).getChoosen());
134             } else {
135                l.add(el.toValue());
136             }
137          } else {
138             l.add(el.toValue());
139          }
140       }
141       return l;
142    }
143
144
145 }
146
Popular Tags