KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* TypeDeclarations.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>TypeDeclaration</b> instances.
21 *
22 * @see XML
23 */

24 public class TypeDeclarations extends XMLCollection {
25
26    /**
27    * Creates a new instance of the class.
28    */

29    public TypeDeclarations (Package JavaDoc p) {
30       super(p);
31    }
32
33    // min=0, max=unbounded
34
/**
35    * Generates a new element of the class which instances
36    * are members of collection of this class.
37    *
38    * return The generated instance of class that makes collection.
39    */

40    public XMLElement generateNewElement() {
41       TypeDeclaration td=new TypeDeclaration(this,((Package JavaDoc)myOwner));
42       td.setRequired(true);
43       return td;
44    }
45
46    /**
47    * Returns a type declaration with specified ID.
48    *
49    * @param ID The 'Id' attribute of wanted instance of
50    * TypeDeclaration element defined within a package.
51    * @return Returns the instance of TypeDeclaration element
52    * that have the specified ID as an 'Id' attribute
53    * if it exist among all defined types within
54    * package, if it doesn't exist, <tt>null</tt> is
55    * returned.
56    */

57    public TypeDeclaration getDeclaredType (String JavaDoc ID) {
58       return (TypeDeclaration)getCollectionElement(ID);
59    }
60
61    /**
62    * Checks if specified declared type can be removed. It can be
63    * removed only if it is not used anywhere.
64    */

65    public boolean canRemoveElement (XMLElement el) {
66       TypeDeclaration toRemove=(TypeDeclaration)el;
67
68       // check if it is used within datafields
69

70       // collect all data fields
71
Set allDFS=new HashSet();
72       allDFS.add(myOwner.get("DataFields"));
73       WorkflowProcesses wps=(WorkflowProcesses)myOwner.get("WorkflowProcesses");
74       Iterator it=wps.toCollection().iterator();
75       while (it.hasNext()) {
76          WorkflowProcess wp=(WorkflowProcess)it.next();
77          allDFS.add(wp.get("DataFields"));
78       }
79
80       // Iterate through data fields and check if any data field uses
81
// element that we want to remove
82
it=allDFS.iterator();
83       while (it.hasNext()) {
84          DataFields dfs=(DataFields)it.next();
85          Iterator itDFs=dfs.toCollection().iterator();
86          while (itDFs.hasNext()) {
87             DataField df=(DataField)itDFs.next();
88             DataType dt=(DataType)df.get("DataType");
89             Object JavaDoc choosen=((DataTypes)dt.get("Type")).getChoosen();
90             if (choosen instanceof DeclaredType) {
91                if (((XMLComplexChoice)((DeclaredType)choosen).get("SubType")).
92                   getChoosen()==toRemove) {
93                   return false;
94                }
95             }
96          }
97       }
98
99
100       // check if it is used within formal parameters of apps. or workflows
101

102       // collect all FormalParameters
103
Set allFPs=new HashSet();
104       // application's FPs (from package)
105
Applications aps=(Applications)myOwner.get("Applications");
106       Iterator itApps=aps.toCollection().iterator();
107       while (itApps.hasNext()) {
108          Application app=(Application)itApps.next();
109          XMLComplexChoice ch=(XMLComplexChoice)app.get("Choice");
110          allFPs.add(ch.getChoices()[0]);
111       }
112
113       it=wps.toCollection().iterator();
114       while (it.hasNext()) {
115          WorkflowProcess wp=(WorkflowProcess)it.next();
116          // workflow process FPs
117
allFPs.add(wp.get("FormalParameters"));
118          // application's FPs
119
aps=(Applications)wp.get("Applications");
120          itApps=aps.toCollection().iterator();
121          while (itApps.hasNext()) {
122             Application app=(Application)itApps.next();
123             XMLComplexChoice ch=(XMLComplexChoice)app.get("Choice");
124             allFPs.add(ch.getChoices()[0]);
125          }
126       }
127
128       // Iterate through FPs and check if any FP uses
129
// element that we want to remove
130
it=allFPs.iterator();
131       while (it.hasNext()) {
132          FormalParameters fps=(FormalParameters)it.next();
133          Iterator itFPs=fps.toCollection().iterator();
134          while (itFPs.hasNext()) {
135             FormalParameter fp=(FormalParameter)itFPs.next();
136             DataType dt=(DataType)fp.get("DataType");
137             Object JavaDoc choosen=((DataTypes)dt.get("Type")).getChoosen();
138             if (choosen instanceof DeclaredType) {
139                if (((XMLComplexChoice)((DeclaredType)choosen).get("SubType")).
140                   getChoosen()==toRemove) {
141                   return false;
142                }
143             }
144          }
145       }
146
147       return true;
148    }
149
150
151    public int[] getInvisibleTableFieldOrdinals () {
152       int[] itfo=new int[2];
153       itfo[0]=3;
154       itfo[1]=4;
155       return itfo;
156    }
157
158 }
159
Popular Tags