001: package org.enhydra.shark.xpdl.elements;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006:
007: import org.enhydra.shark.utilities.SequencedHashMap;
008: import org.enhydra.shark.xpdl.XMLAttribute;
009: import org.enhydra.shark.xpdl.XMLComplexElement;
010: import org.enhydra.shark.xpdl.XMLElement;
011: import org.enhydra.shark.xpdl.XMLElementChangeInfo;
012:
013: /**
014: * Represents coresponding element from XPDL schema.
015: *
016: * @author Sasa Bojanic
017: */
018: public class Package extends XMLComplexElement {
019:
020: protected Namespaces namespaces;
021: protected String internalVersion;
022: protected boolean isTransient;
023:
024: protected SequencedHashMap extPkgRefsToIds = new SequencedHashMap();
025:
026: //transient static int pkgno=0;
027: //transient int pno;
028: //transient static ArrayList createdPKGs=new ArrayList();
029: //transient static ArrayList destroyedPKGs=new ArrayList();
030:
031: public Package() {
032: super (null, true);
033: // pno=++pkgno;
034: // System.err.println("PKG "+(pno)+" created, hc="+hashCode());
035: // createdPKGs.add(new Integer(pno));
036: namespaces = new Namespaces(this );
037: internalVersion = "-1";
038: isTransient = false;
039: }
040:
041: public void makeAs(XMLElement el) {
042: super .makeAs(el);
043: this .namespaces.makeAs(((Package) el).namespaces);
044: extPkgRefsToIds = new SequencedHashMap(
045: ((Package) el).extPkgRefsToIds);
046: this .isTransient = ((Package) el).isTransient;
047: }
048:
049: protected void fillStructure() {
050: XMLAttribute attrId = new XMLAttribute(this , "Id", true); // required
051: XMLAttribute attrName = new XMLAttribute(this , "Name", false);
052: PackageHeader refPackageHeader = new PackageHeader(this );
053: RedefinableHeader refRedefinableHeader = new RedefinableHeader(
054: this ); // min=0
055: ConformanceClass refConformanceClass = new ConformanceClass(
056: this ); // min=0
057: Script refScript = new Script(this ); // min=0
058: ExternalPackages refExternalPackages = new ExternalPackages(
059: this ); // min=0
060: TypeDeclarations refTypeDeclarations = new TypeDeclarations(
061: this ); // min=0
062: Participants refParticipants = new Participants(this );
063: Applications refApplications = new Applications(this ); // min=0
064: DataFields refDataFields = new DataFields(this ); // min=0
065: WorkflowProcesses refWorkflowProcesses = new WorkflowProcesses(
066: this ); // min=0
067: ExtendedAttributes refExtendedAttributes = new ExtendedAttributes(
068: this );
069:
070: add(attrId);
071: add(attrName);
072: add(refPackageHeader);
073: add(refRedefinableHeader);
074: add(refConformanceClass);
075: add(refScript);
076: add(refExternalPackages);
077: add(refTypeDeclarations);
078: add(refParticipants);
079: add(refApplications);
080: add(refDataFields);
081: add(refWorkflowProcesses);
082: add(refExtendedAttributes);
083: }
084:
085: public boolean isTransient() {
086: return isTransient;
087: }
088:
089: public void setTransient(boolean trans) {
090: this .isTransient = trans;
091: }
092:
093: public String getInternalVersion() {
094: return internalVersion;
095: }
096:
097: public void setInternalVersion(String internalVersion) {
098: this .internalVersion = internalVersion;
099: }
100:
101: public void addExternalPackageMapping(String epRef, String epId) {
102: extPkgRefsToIds.put(epRef, epId);
103: }
104:
105: public void removeExternalPackageMapping(String epRef) {
106: extPkgRefsToIds.remove(epRef);
107: }
108:
109: public String getExternalPackageId(String epRef) {
110: return (String) extPkgRefsToIds.get(epRef);
111: }
112:
113: public Collection getExternalPackageIds() {
114: return new ArrayList(extPkgRefsToIds.values());
115: }
116:
117: public ExternalPackage getExternalPackage(String id) {
118: ExternalPackage toRet = null;
119: Iterator it = getExternalPackages().toElements().iterator();
120: while (it.hasNext()) {
121: ExternalPackage ep = (ExternalPackage) it.next();
122: String href = ep.getHref();
123: String epId = getExternalPackageId(href);
124: if (epId != null && epId.equals(id)) {
125: toRet = ep;
126: break;
127: }
128: }
129: return toRet;
130: }
131:
132: public WorkflowProcess getWorkflowProcess(String Id) {
133: return getWorkflowProcesses().getWorkflowProcess(Id);
134: }
135:
136: public Application getApplication(String Id) {
137: return getApplications().getApplication(Id);
138: }
139:
140: public Participant getParticipant(String Id) {
141: return getParticipants().getParticipant(Id);
142: }
143:
144: public DataField getDataField(String Id) {
145: return getDataFields().getDataField(Id);
146: }
147:
148: public TypeDeclaration getTypeDeclaration(String Id) {
149: return getTypeDeclarations().getTypeDeclaration(Id);
150: }
151:
152: public String getId() {
153: return get("Id").toValue();
154: }
155:
156: public void setId(String id) {
157: set("Id", id);
158: }
159:
160: public String getName() {
161: return get("Name").toValue();
162: }
163:
164: public void setName(String name) {
165: set("Name", name);
166: }
167:
168: public Applications getApplications() {
169: return (Applications) get("Applications");
170: }
171:
172: public ConformanceClass getConformanceClass() {
173: return (ConformanceClass) get("ConformanceClass");
174: }
175:
176: public DataFields getDataFields() {
177: return (DataFields) get("DataFields");
178: }
179:
180: public ExtendedAttributes getExtendedAttributes() {
181: return (ExtendedAttributes) get("ExtendedAttributes");
182: }
183:
184: public ExternalPackages getExternalPackages() {
185: return (ExternalPackages) get("ExternalPackages");
186: }
187:
188: public PackageHeader getPackageHeader() {
189: return (PackageHeader) get("PackageHeader");
190: }
191:
192: public Participants getParticipants() {
193: return (Participants) get("Participants");
194: }
195:
196: public RedefinableHeader getRedefinableHeader() {
197: return (RedefinableHeader) get("RedefinableHeader");
198: }
199:
200: public Script getScript() {
201: return (Script) get("Script");
202: }
203:
204: public TypeDeclarations getTypeDeclarations() {
205: return (TypeDeclarations) get("TypeDeclarations");
206: }
207:
208: public WorkflowProcesses getWorkflowProcesses() {
209: return (WorkflowProcesses) get("WorkflowProcesses");
210: }
211:
212: public Namespaces getNamespaces() {
213: return namespaces;
214: }
215:
216: public void setNotifyMainListeners(boolean notify) {
217: super .setNotifyMainListeners(notify);
218: namespaces.setNotifyMainListeners(notify);
219: }
220:
221: public void setReadOnly(boolean ro) {
222: super .setReadOnly(ro);
223: namespaces.setReadOnly(ro);
224: }
225:
226: public Object clone() {
227: // System.out.println("Cloning package "+this.hashCode()+", listeners="+listeners);
228: Package d = (Package) super .clone();
229: // System.out.println("cloned pkg="+d.hashCode()+", list="+listeners);
230: d.namespaces = (Namespaces) this .namespaces.clone();
231: d.namespaces.setParent(d);
232: d.extPkgRefsToIds = new SequencedHashMap(extPkgRefsToIds);
233: d.isTransient = isTransient;
234: d.clearCaches();
235: if (d.isReadOnly)
236: d.initCaches();
237: return d;
238: }
239:
240: public boolean equals(Object e) {
241: boolean equals = super .equals(e);
242: if (equals) {
243: Package el = (Package) e;
244: equals = (this .namespaces.equals(el.namespaces) && this .internalVersion
245: .equals(el.internalVersion));
246: // System.out.println("Package's ns or int ver equal - "+equals);
247: }
248: return equals;
249: }
250:
251: protected boolean isMainElement() {
252: return true;
253: }
254:
255: protected void notifyMainListeners(XMLElementChangeInfo info) {
256: if (parent == null)
257: return;
258: super .notifyMainListeners(info);
259: }
260:
261: // public void finalize () throws Throwable {
262: // super.finalize();
263: // destroyedPKGs.add(new Integer(pno));
264: // System.err.println("PKG "+(pno)+" destroyed, hc="+hashCode());
265: // }
266:
267: public static void dbg() {
268: System.gc();
269: // System.err.println("Created pkgs: "+createdPKGs);
270: // System.err.println("Destroyed pkgs: "+destroyedPKGs);
271: // ArrayList inMem=new ArrayList(createdPKGs);
272: // inMem.removeAll(destroyedPKGs);
273: // System.err.println("Packages in memory: "+inMem);
274: }
275: }
|