001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.xpdl.model.pkg;
046:
047: import org.obe.xpdl.PackageVisitor;
048: import org.obe.xpdl.model.XPDLProperties;
049: import org.obe.xpdl.model.data.TypeDeclaration;
050: import org.obe.xpdl.model.misc.ConformanceClass;
051: import org.obe.xpdl.model.misc.ResourceContainer;
052: import org.obe.xpdl.model.misc.Script;
053: import org.obe.xpdl.model.workflow.WorkflowProcess;
054:
055: import java.beans.PropertyVetoException;
056: import java.util.HashMap;
057: import java.util.Map;
058:
059: /**
060: * A XPDLPackage is the top-level element in an XPDL document.
061: *
062: * @author Adrian Price
063: */
064: public final class XPDLPackage extends ResourceContainer {
065: private static final long serialVersionUID = -6038418003633747926L;
066: private static final ExternalPackage[] EMPTY_EXT_PKG = {};
067: private static final TypeDeclaration[] EMPTY_TYPE_DECL = {};
068: private static final WorkflowProcess[] EMPTY_WF_PROC = {};
069: public static final String COMPLETION_STRATEGY = XPDLProperties.COMPLETION_STRATEGY;
070: public static final String CONFORMANCE_CLASS = XPDLProperties.CONFORMANCE_CLASS;
071: public static final String EXTERNAL_PACKAGE = XPDLProperties.EXTERNAL_PACKAGE;
072: public static final String NAMESPACES = XPDLProperties.NAMESPACES;
073: public static final String PACKAGE_HEADER = XPDLProperties.PACKAGE_HEADER;
074: public static final String PACKAGE_ID = XPDLProperties.PACKAGE_ID;
075: public static final String SCRIPT = XPDLProperties.SCRIPT;
076: public static final String TYPE_DECLARATION = XPDLProperties.TYPE_DECLARATION;
077: public static final String WORKFLOW_PROCESS = XPDLProperties.WORKFLOW_PROCESS;
078: private static final String[] _indexedPropertyNames = {
079: APPLICATION, DATA_FIELD, PARTICIPANT, EXTERNAL_PACKAGE,
080: TYPE_DECLARATION, WORKFLOW_PROCESS };
081: private static final Object[] _indexedPropertyValues = {
082: EMPTY_APPLICATION, EMPTY_DATA_FIELD, EMPTY_PARTICIPANT,
083: EMPTY_EXT_PKG, EMPTY_TYPE_DECL, EMPTY_WF_PROC };
084: private static final int EXTERNAL_PACKAGE_IDX = 3;
085: private static final int TYPE_DECLARATION_IDX = 4;
086: private static final int WORKFLOW_PROCESS_IDX = 5;
087:
088: private String _completionStrategy;
089: private ConformanceClass _conformanceClass;
090: private ExternalPackage[] _externalPackage = EMPTY_EXT_PKG;
091: private PackageHeader _packageHeader;
092: private Script _script;
093: private TypeDeclaration[] _typeDeclaration = EMPTY_TYPE_DECL;
094: private WorkflowProcess[] _workflowProcess = EMPTY_WF_PROC;
095: private final Map _namespaces = new HashMap();
096:
097: public XPDLPackage() {
098: super (_indexedPropertyNames, _indexedPropertyValues);
099: setPackageHeader(new PackageHeader());
100: }
101:
102: /**
103: * Construct a new XPDLPackage.
104: *
105: * @param id The package ID
106: * @param name The package name
107: * @param packageHeader The PackageHeader object
108: */
109: public XPDLPackage(String id, String name,
110: PackageHeader packageHeader) {
111: super (_indexedPropertyNames, _indexedPropertyValues, id, name);
112:
113: setPackageHeader(packageHeader);
114: }
115:
116: public void accept(PackageVisitor visitor) {
117: visitor.visit(this );
118: super .accept(visitor);
119: for (int i = 0; i < _externalPackage.length; i++)
120: _externalPackage[i].accept(visitor);
121: for (int i = 0; i < _typeDeclaration.length; i++)
122: _typeDeclaration[i].accept(visitor);
123: for (int i = 0; i < _workflowProcess.length; i++)
124: _workflowProcess[i].accept(visitor);
125: }
126:
127: /**
128: * Returns all XML namespace prefix:URI mappings declared on the Package
129: * element of the XPDL document.
130: *
131: * @return XML namespace prefix:URI mappings.
132: */
133: public Map getNamespaces() {
134: return _namespaces;
135: }
136:
137: /**
138: * Synonym for {@link #getId()}. Required for compatibility between
139: * in-memory and EJB process repositories.
140: *
141: * @return the package ID.
142: */
143: public String getPackageId() {
144: return getId();
145: }
146:
147: public String getCompletionStrategy() {
148: return _completionStrategy;
149: }
150:
151: public void setCompletionStrategy(String completionStrategy) {
152: _completionStrategy = completionStrategy;
153: }
154:
155: /**
156: * Get the ConformanceClass.
157: *
158: * @return The ConformanceClass
159: */
160: public ConformanceClass getConformanceClass() {
161: return _conformanceClass;
162: }
163:
164: /**
165: * Set the ConformanceClass.
166: *
167: * @param conformanceClass
168: */
169: public void setConformanceClass(ConformanceClass conformanceClass) {
170: _conformanceClass = conformanceClass;
171: }
172:
173: public void add(ExternalPackage extPkg)
174: throws PropertyVetoException {
175: _externalPackage = (ExternalPackage[]) add(
176: EXTERNAL_PACKAGE_IDX, extPkg);
177: }
178:
179: public void remove(ExternalPackage extPkg)
180: throws PropertyVetoException {
181: _externalPackage = (ExternalPackage[]) remove(
182: EXTERNAL_PACKAGE_IDX, extPkg);
183: }
184:
185: public ExternalPackage[] getExternalPackage() {
186: return (ExternalPackage[]) get(EXTERNAL_PACKAGE_IDX);
187: }
188:
189: public ExternalPackage getExternalPackage(int i) {
190: return _externalPackage[i];
191: }
192:
193: public ExternalPackage getExternalPackage(String id) {
194: if (_externalPackage != null) {
195: for (int i = 0; i < _externalPackage.length; i++) {
196: ExternalPackage pkg = _externalPackage[i];
197: if (pkg.getPackage().getId().equals(id))
198: return pkg;
199: }
200: }
201: return null;
202: }
203:
204: public void setExternalPackage(ExternalPackage[] externalPackages)
205: throws PropertyVetoException {
206:
207: set(
208: EXTERNAL_PACKAGE_IDX,
209: _externalPackage = externalPackages == null ? EMPTY_EXT_PKG
210: : externalPackages);
211: }
212:
213: public void setExternalPackage(int i,
214: ExternalPackage externalPackage)
215: throws PropertyVetoException {
216:
217: set(EXTERNAL_PACKAGE_IDX, i, externalPackage);
218: }
219:
220: /**
221: * Get the PackageHeader.
222: *
223: * @return The PackageHeader
224: */
225: public PackageHeader getPackageHeader() {
226: return _packageHeader;
227: }
228:
229: /**
230: * Set the PackageHeader. This method will throw an
231: * IllegalArgumentException if the argument is null.
232: *
233: * @param packageHeader The new package header
234: */
235: public void setPackageHeader(PackageHeader packageHeader) {
236: if (packageHeader == null)
237: throw new IllegalArgumentException(
238: "Package header cannot be null");
239:
240: _packageHeader = packageHeader;
241: }
242:
243: /**
244: * Get an object defining the scripting language to use for expressions.
245: *
246: * @return The Script
247: */
248: public Script getScript() {
249: return _script;
250: }
251:
252: /**
253: * Set the script language for expressions.
254: *
255: * @param script The new script language
256: */
257: public void setScript(Script script) {
258: _script = script;
259: }
260:
261: public void add(TypeDeclaration typeDecl)
262: throws PropertyVetoException {
263: _typeDeclaration = (TypeDeclaration[]) add(
264: TYPE_DECLARATION_IDX, typeDecl);
265: }
266:
267: public void remove(TypeDeclaration typeDecl)
268: throws PropertyVetoException {
269: _typeDeclaration = (TypeDeclaration[]) remove(
270: TYPE_DECLARATION_IDX, typeDecl);
271: }
272:
273: public TypeDeclaration[] getTypeDeclaration() {
274: return (TypeDeclaration[]) get(TYPE_DECLARATION_IDX);
275: }
276:
277: public TypeDeclaration getTypeDeclaration(int i) {
278: return _typeDeclaration[i];
279: }
280:
281: public TypeDeclaration getTypeDeclaration(String id) {
282: if (_typeDeclaration != null) {
283: for (int i = 0; i < _typeDeclaration.length; i++) {
284: TypeDeclaration td = _typeDeclaration[i];
285: if (td.getId().equals(id))
286: return td;
287: }
288: }
289: return null;
290: }
291:
292: public void setTypeDeclaration(TypeDeclaration[] typeDeclarations)
293: throws PropertyVetoException {
294:
295: set(
296: TYPE_DECLARATION_IDX,
297: _typeDeclaration = typeDeclarations == null ? EMPTY_TYPE_DECL
298: : typeDeclarations);
299: }
300:
301: public void setTypeDeclaration(int i,
302: TypeDeclaration typeDeclaration)
303: throws PropertyVetoException {
304:
305: set(TYPE_DECLARATION_IDX, i, typeDeclaration);
306: }
307:
308: public void add(WorkflowProcess workflowProcess)
309: throws PropertyVetoException {
310:
311: _workflowProcess = (WorkflowProcess[]) add(
312: WORKFLOW_PROCESS_IDX, workflowProcess);
313: }
314:
315: public void remove(WorkflowProcess workflowProcess)
316: throws PropertyVetoException {
317:
318: _workflowProcess = (WorkflowProcess[]) remove(
319: WORKFLOW_PROCESS_IDX, workflowProcess);
320: }
321:
322: public WorkflowProcess[] getWorkflowProcess() {
323: return (WorkflowProcess[]) get(WORKFLOW_PROCESS_IDX);
324: }
325:
326: public WorkflowProcess getWorkflowProcess(int i) {
327: return _workflowProcess[i];
328: }
329:
330: public WorkflowProcess getWorkflowProcess(String id) {
331: if (_workflowProcess != null) {
332: for (int i = 0; i < _workflowProcess.length; i++) {
333: WorkflowProcess wf = _workflowProcess[i];
334: if (wf.getId().equals(id))
335: return wf;
336: }
337: }
338: return null;
339: }
340:
341: public void setWorkflowProcess(WorkflowProcess[] workflowProcesses)
342: throws PropertyVetoException {
343:
344: set(
345: WORKFLOW_PROCESS_IDX,
346: _workflowProcess = workflowProcesses == null ? EMPTY_WF_PROC
347: : workflowProcesses);
348: }
349:
350: public void setWorkflowProcess(int i,
351: WorkflowProcess workflowProcess)
352: throws PropertyVetoException {
353:
354: set(WORKFLOW_PROCESS_IDX, i, workflowProcess);
355: }
356:
357: public String toString() {
358: return "XPDLPackage[packageId='" + getId() + "', name='"
359: + getName() + "']";
360: }
361: }
|