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.misc;
046:
047: import org.obe.xpdl.PackageVisitor;
048: import org.obe.xpdl.model.XPDLProperties;
049: import org.obe.xpdl.model.application.Application;
050: import org.obe.xpdl.model.data.DataField;
051: import org.obe.xpdl.model.ext.AssignmentStrategyDef;
052: import org.obe.xpdl.model.ext.CalendarRef;
053: import org.obe.xpdl.model.participant.Participant;
054:
055: import java.beans.PropertyVetoException;
056:
057: /**
058: * Abstract container for resources common to XPDLPackage and WorkflowProcess.
059: *
060: * @author Adrian Price
061: */
062: public abstract class ResourceContainer extends AbstractWFElement
063: implements CalendarRef {
064:
065: private static final long serialVersionUID = -5828730717399616392L;
066: public static final String APPLICATION = XPDLProperties.APPLICATION;
067: public static final String ASSIGNMENT_STRATEGY = XPDLProperties.ASSIGNMENT_STRATEGY;
068: public static final String CALENDAR = XPDLProperties.CALENDAR;
069: public static final String DATA_FIELD = XPDLProperties.DATA_FIELD;
070: public static final String PARTICIPANT = XPDLProperties.PARTICIPANT;
071: public static final String REDEFINABLE_HEADER = XPDLProperties.REDEFINABLE_HEADER;
072: protected static final Application[] EMPTY_APPLICATION = {};
073: protected static final DataField[] EMPTY_DATA_FIELD = {};
074: protected static final Participant[] EMPTY_PARTICIPANT = {};
075: private static final int APPLICATION_IDX = 0;
076: private static final int DATA_FIELD_IDX = 1;
077: private static final int PARTICIPANT_IDX = 2;
078:
079: private Application[] _application = EMPTY_APPLICATION;
080: private AssignmentStrategyDef _assignmentStrategy;
081: private String _calendar;
082: private DataField[] _dataField = EMPTY_DATA_FIELD;
083: private Participant[] _participant = EMPTY_PARTICIPANT;
084: private RedefinableHeader _redefinableHeader;
085:
086: protected ResourceContainer(String[] propertyNames,
087: Object[] initalValues) {
088: super (propertyNames, initalValues);
089: }
090:
091: protected ResourceContainer(String[] propertyNames,
092: Object[] initalValues, String id, String name) {
093:
094: super (propertyNames, initalValues, id, name);
095: }
096:
097: protected void accept(PackageVisitor visitor) {
098: for (int i = 0; i < _application.length; i++)
099: _application[i].accept(visitor);
100: for (int i = 0; i < _dataField.length; i++)
101: _dataField[i].accept(visitor);
102: for (int i = 0; i < _participant.length; i++)
103: _participant[i].accept(visitor);
104: }
105:
106: public final void add(Application application)
107: throws PropertyVetoException {
108:
109: _application = (Application[]) add(APPLICATION_IDX, application);
110: }
111:
112: public final void remove(Application application)
113: throws PropertyVetoException {
114:
115: _application = (Application[]) remove(APPLICATION_IDX,
116: application);
117: }
118:
119: public final Application[] getApplication() {
120: return (Application[]) get(APPLICATION_IDX);
121: }
122:
123: public final Application getApplication(int i) {
124: return _application[i];
125: }
126:
127: public final Application getApplication(String id) {
128: if (_application != null) {
129: for (int i = 0; i < _application.length; i++) {
130: Application app = _application[i];
131: if (app.getId().equals(id))
132: return app;
133: }
134: }
135: return null;
136: }
137:
138: public final void setApplication(Application[] applications)
139: throws PropertyVetoException {
140:
141: set(APPLICATION_IDX,
142: _application = applications == null ? EMPTY_APPLICATION
143: : applications);
144: }
145:
146: public final void setApplication(int i, Application application)
147: throws PropertyVetoException {
148:
149: set(APPLICATION_IDX, i, application);
150: }
151:
152: /**
153: * Returns the work item assignment strategy.
154: *
155: * @return Assignment strategy definition, which must have a matching
156: * implementation registered in the AssignmentStrategyRepository.
157: */
158: public final AssignmentStrategyDef getAssignmentStrategy() {
159: return _assignmentStrategy;
160: }
161:
162: /**
163: * Sets the work item assignment strategy. This is an OBE XPDL-1.0 extension.
164: *
165: * @param strategy Assignment strategy definition, which must have a
166: * matching implementation registered in the AssignmentStrategyRepository.
167: */
168: public final void setAssignmentStrategy(
169: AssignmentStrategyDef strategy) {
170: _assignmentStrategy = strategy;
171: }
172:
173: public final String getCalendar() {
174: return _calendar;
175: }
176:
177: public final void setCalendar(String calendar) {
178: _calendar = calendar;
179: }
180:
181: public final void add(DataField dataField)
182: throws PropertyVetoException {
183: _dataField = (DataField[]) add(DATA_FIELD_IDX, dataField);
184: }
185:
186: public final void remove(DataField dataField)
187: throws PropertyVetoException {
188: _dataField = (DataField[]) remove(DATA_FIELD_IDX, dataField);
189: }
190:
191: public final DataField[] getDataField() {
192: return (DataField[]) get(DATA_FIELD_IDX);
193: }
194:
195: public final DataField getDataField(int i) {
196: return _dataField[i];
197: }
198:
199: public final DataField getDataField(String id) {
200: if (_dataField != null) {
201: for (int i = 0; i < _dataField.length; i++) {
202: DataField df = _dataField[i];
203: if (df.getId().equals(id))
204: return df;
205: }
206: }
207: return null;
208: }
209:
210: public final void setDataField(DataField[] dataFields)
211: throws PropertyVetoException {
212:
213: set(DATA_FIELD_IDX,
214: _dataField = dataFields == null ? EMPTY_DATA_FIELD
215: : dataFields);
216: }
217:
218: public final void setDataField(int i, DataField dataField)
219: throws PropertyVetoException {
220:
221: set(DATA_FIELD_IDX, i, dataField);
222: }
223:
224: public final void add(Participant participant)
225: throws PropertyVetoException {
226:
227: _participant = (Participant[]) add(PARTICIPANT_IDX, participant);
228: }
229:
230: public final void remove(Participant participant)
231: throws PropertyVetoException {
232:
233: _participant = (Participant[]) remove(PARTICIPANT_IDX,
234: participant);
235: }
236:
237: public final Participant[] getParticipant() {
238: return (Participant[]) get(PARTICIPANT_IDX);
239: }
240:
241: public final Participant getParticipant(int i) {
242: return _participant[i];
243: }
244:
245: public final Participant getParticipant(String id) {
246: if (_participant != null) {
247: for (int i = 0; i < _participant.length; i++) {
248: Participant p = _participant[i];
249: if (p.getId().equals(id))
250: return p;
251: }
252: }
253: return null;
254: }
255:
256: public final void setParticipant(Participant[] participants)
257: throws PropertyVetoException {
258:
259: set(PARTICIPANT_IDX,
260: _participant = participants == null ? EMPTY_PARTICIPANT
261: : participants);
262: }
263:
264: public final void setParticipant(int i, Participant participant)
265: throws PropertyVetoException {
266:
267: set(PARTICIPANT_IDX, i, participant);
268: }
269:
270: /**
271: * Get the RedefinableHeader.
272: *
273: * @return The RedefinableHeader
274: */
275: public final RedefinableHeader getRedefinableHeader() {
276: return _redefinableHeader;
277: }
278:
279: /**
280: * Set the RedefinableHeader.
281: *
282: * @param header The RedefinableHeader
283: */
284: public final void setRedefinableHeader(RedefinableHeader header) {
285: _redefinableHeader = header;
286: }
287: }
|