KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 public class DeclaredType extends XMLComplexElement {
24    /** Reference to all types declared within this elements package */
25    private transient TypeDeclarations declaredTypes=null;
26
27    private XMLAttribute attrId=new XMLAttribute("Id"); // required
28

29    /** Used to hold reference to the choosen TypeDeclaration. */
30    private transient XMLComplexChoice helperElement;
31
32    /**
33    * Creates a new instance of the class.
34    *
35    * @param p The package which elements holds instance of
36    * of this class.
37    */

38    public DeclaredType (Package JavaDoc p) {
39       super();
40
41       try {
42          declaredTypes=(TypeDeclarations)p.get("TypeDeclarations");
43       }
44       catch (NullPointerException JavaDoc npe) {
45          //
46
}
47
48       helperElement=new XMLComplexChoice("SubType",null,0) {
49          public XMLPanel getPanel () {
50             if (declaredTypes!=null) {
51                choices=declaredTypes.toCollection().toArray();
52                try {
53                   // this is important after reading from XML the
54
// declared type that uses another declared type
55
this.setValue(declaredTypes.
56                      getDeclaredType(attrId.toValue().toString()));
57                } catch (Exception JavaDoc ex) {
58                   //
59
}
60             }
61             else {
62                choices=null;
63             }
64             return new XMLComboButtonPanel(this,declaredTypes);
65          }
66
67          public void setReadOnly (boolean ro) {
68             this.isReadOnly=ro;
69          }
70
71          public void setValue (Object JavaDoc v) {
72             super.setValue(v);
73             try {
74                attrId.setValue(((XMLCollectionElement)this.getChoosen()).
75                   getID());
76             } catch (Exception JavaDoc ex) {}
77          }
78
79       };
80
81       fillStructure();
82    }
83
84    /**
85    * Defines the super-class method. Read the explanation for
86    * this method within XMLComplexElement class.
87    */

88    protected void fillStructure () {
89       attrId.setRequired(true);
90       attributes.add(attrId);
91       complexStructure.add(attrId);
92       helperElement.setLabelName(XMLUtil.getLanguageDependentString("SubTypeKey"));
93       helperElement.setRequired(true);
94       complexStructure.add(helperElement);
95    }
96
97    /**
98    * Overrides super-class method to realize this class specific
99    * writting to XML file.
100    *
101    * @return The string for a WfMC DTD DeclaredType element tag.
102    */

103    public void toXML (Node parent) throws DOMException {
104       // setting attribute Id to be the one of the choosen TypeDeclaration
105
// we must remove helper element after that, generate xml output and
106
// put the helper element and old value for attribute Id back.
107
Object JavaDoc val=attrId.toValue();
108       complexStructure.remove(1);
109       super.toXML(parent);
110       complexStructure.add(1,helperElement);
111    }
112
113    /**
114    * Overrides super-class method to realize this class specific
115    * reading from XML file.
116    *
117    * @param node root node
118    */

119    public void fromXML (Node node) {
120       super.fromXML(node);
121       // initializes helper element to TypeDeclaration with given Id
122
helperElement.setValue(declaredTypes.getDeclaredType(attrId.toValue().toString()));
123    }
124
125    /**
126    * Used to create exact copy of instance of this class.
127    * The newly created instance will have all the properties
128    * same as the copied one.
129    *
130    * @return The newly created instance of this class.
131    */

132    public Object JavaDoc clone () {
133       DeclaredType dt=(DeclaredType)super.clone();
134       dt.helperElement=new XMLComplexChoice("SubType",null,0) {
135          public XMLPanel getPanel () {
136             if (declaredTypes!=null) {
137                choices=declaredTypes.toCollection().toArray();
138             }
139             else {
140                choices=null;
141             }
142             return new XMLComboButtonPanel(this,declaredTypes);
143          }
144       };
145       dt.helperElement.setValue(helperElement.getChoosen());
146
147       dt.declaredTypes=this.declaredTypes;
148
149       dt.fillStructure();
150
151       return dt;
152    }
153
154    /**
155    * Prepares the panel with a combo box to choose the one of
156    * already user-declared types.
157    *
158    * @return XMLPanel to be shown.
159    */

160    public XMLPanel getPanel () {
161       return helperElement.getPanel();
162    }
163
164 }
165
Popular Tags