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.client.api.model;
046:
047: import org.wfmc.wapi.WAPI;
048: import org.wfmc.wapi.WMFilter;
049: import org.wfmc.wapi.WMProcessInstanceState;
050: import org.obe.util.ClassUtils;
051: import org.obe.spi.model.ProcessInstance;
052: import org.obe.spi.model.AttributedEntity;
053: import org.obe.xpdl.model.data.DataField;
054: import org.obe.xpdl.model.data.DataTypes;
055: import org.obe.xpdl.model.misc.AbstractWFElement;
056:
057: import java.beans.PropertyDescriptor;
058: import java.util.Comparator;
059: import java.util.Arrays;
060:
061: /**
062: * Describes the process instance system attributes supported by OBE. Note that
063: * process instances can also possess custom attributes, defined in the process
064: * definition. The string constants in this interface can be passed to
065: * {@link WAPI#getProcessInstanceAttributeValue} and as the
066: * <code>attributeName</code> argument to
067: * {@link WMFilter#WMFilter(String,int,Boolean)}.
068: *
069: * @author Adrian Price
070: */
071: public class ProcessInstanceAttributes {
072: /**
073: * The date/time by which the earliest of the current activities must be
074: * complete.
075: * <p/>
076: * <table border="1">
077: * <tr><th>Data Type</th><th>Access</th></tr>
078: * <tr><td><code>java.util.Date</code></td><td>ReadOnly</td></tr>
079: * </table>
080: */
081: public static final String ACTIVITY_DUE_DATE = "activityDueDate";
082:
083: /**
084: * The date/time by which the earliest of the current activities is expected
085: * to be complete.
086: * <p/>
087: * <table border="1">
088: * <tr><th>Data Type</th><th>Access</th></tr>
089: * <tr><td><code>java.util.Date</code></td><td>ReadOnly</td></tr>
090: * </table>
091: */
092: public static final String ACTIVITY_TARGET_DATE = "activityTargetDate";
093:
094: /**
095: * The date/time at which the process instance was completed.
096: * <p/>
097: * <table border="1">
098: * <tr><th>Data Type</th><th>Access</th></tr>
099: * <tr><td><code>java.util.Date</code></td><td>ReadOnly</td></tr>
100: * </table>
101: */
102: public static final String COMPLETED_DATE = "completedDate";
103:
104: /**
105: * The date/time at which the process instance was created.
106: * <p/>
107: * <table border="1">
108: * <tr><th>Data Type</th><th>Access</th></tr>
109: * <tr><td><code>java.util.Date</code></td><td>ReadOnly</td></tr>
110: * </table>
111: */
112: public static final String CREATED_DATE = "createdDate";
113:
114: /**
115: * The date/time by which the process instance must be complete.
116: * <p/>
117: * <table border="1">
118: * <tr><th>Data Type</th><th>Access</th></tr>
119: * <tr><td><code>java.util.Date</code></td><td>ReadOnly</td></tr>
120: * </table>
121: */
122: public static final String DUE_DATE = "dueDate";
123:
124: /**
125: * The name of the process instance.
126: * <p/>
127: * <table border="1">
128: * <tr><th>Data Type</th><th>Access</th></tr>
129: * <tr><td><code>java.lang.String</code></td><td>Read/Write</td></tr>
130: * </table>
131: */
132: public static final String NAME = "name";
133:
134: /**
135: * The parent activity instance ID. This is only set for a sub-process.
136: * <p/>
137: * <table border="1">
138: * <tr><th>Data Type</th><th>Access</th></tr>
139: * <tr><td><code>java.lang.String</code></td><td>ReadOnly</td></tr>
140: * </table>
141: */
142: public static final String PARENT_ACTIVITY_INSTANCE_ID = "parentActivityInstanceId";
143:
144: /**
145: * The parent process instance ID. This is only set for a sub-process.
146: * <p/>
147: * <table border="1">
148: * <tr><th>Data Type</th><th>Access</th></tr>
149: * <tr><td><code>java.lang.String</code></td><td>ReadOnly</td></tr>
150: * </table>
151: */
152: public static final String PARENT_PROCESS_INSTANCE_ID = "parentProcessInstanceId";
153:
154: /**
155: * The process instance participant IDs.
156: * <p/>
157: * <table border="1">
158: * <tr><th>Data Type</th><th>Access</th></tr>
159: * <tr><td><code>java.lang.String[]</code></td><td>ReadOnly</td></tr>
160: * </table>
161: */
162: public static final String PARTICIPANTS = "participants";
163:
164: /**
165: * The process instance priority.
166: * <p/>
167: * <table border="1">
168: * <tr><th>Data Type</th><th>Access</th></tr>
169: * <tr><td><code>int</code></td><td>Read/Write</td></tr>
170: * </table>
171: */
172: public static final String PRIORITY = "priority";
173:
174: /**
175: * The ID of the process definition of which this is an instance.
176: * <p/>
177: * <table border="1">
178: * <tr><th>Data Type</th><th>Access</th></tr>
179: * <tr><td><code>java.lang.String</code></td><td>ReadOnly</td></tr>
180: * </table>
181: */
182: public static final String PROCESS_DEFINITION_ID = "processDefinitionId";
183:
184: /**
185: * The unique ID of the process instance.
186: * <p/>
187: * <table border="1">
188: * <tr><th>Data Type</th><th>Access</th></tr>
189: * <tr><td><code>java.lang.String</code></td><td>ReadOnly</td></tr>
190: * </table>
191: */
192: public static final String PROCESS_INSTANCE_ID = "processInstanceId";
193:
194: /**
195: * The date/time at which the process instance was started.
196: * <p/>
197: * <table border="1">
198: * <tr><th>Data Type</th><th>Access</th></tr>
199: * <tr><td><code>java.util.Date</code></td><td>ReadOnly</td></tr>
200: * </table>
201: */
202: public static final String STARTED_DATE = "startedDate";
203:
204: /**
205: * The state of the process instance.
206: * <p/>
207: * <table border="1">
208: * <tr><th>Data Type</th><th>Access</th></tr>
209: * <tr><td><code>int</code></td><td>ReadOnly</td></tr>
210: * </table>
211: *
212: * @see WMProcessInstanceState
213: */
214: public static final String STATE = "state";
215:
216: /**
217: * The date/time by which the process instance is expected to be complete.
218: * <p/>
219: * <table border="1">
220: * <tr><th>Data Type</th><th>Access</th></tr>
221: * <tr><td><code>java.util.Date</code></td><td>ReadOnly</td></tr>
222: * </table>
223: */
224: public static final String TARGET_DATE = "targetDate";
225:
226: /**
227: * The temporal status of the process instance.
228: * <p/>
229: * <table border="1">
230: * <tr><th>Data Type</th><th>Access</th></tr>
231: * <tr><td><code>org.obe.client.api.model.TemporalStatus</code></td><td>ReadOnly</td></tr>
232: * </table>
233: */
234: public static final String TEMPORAL_STATUS = "temporalStatus";
235:
236: /**
237: * Property descriptors for ProcessInstance.
238: * <em>N.B. DO NOT WRITE TO THIS ARRAY!!!</em>
239: */
240: public static final PropertyDescriptor[] SYSTEM_PROPERTIES;
241:
242: /**
243: * Attributes for ProcessInstance.
244: * <em>N.B. DO NOT WRITE TO THIS ARRAY!!!</em>
245: */
246: public static final String[] SYSTEM_ATTRIBUTES;
247:
248: /**
249: * Virtual DataFields corresponding to the system attributes.
250: * <em>N.B. DO NOT WRITE TO THIS ARRAY!!!</em>
251: */
252: public static final DataField[] SYSTEM_DATAFIELDS;
253:
254: private static final Comparator _dataFieldComparator;
255:
256: static {
257: SYSTEM_PROPERTIES = ClassUtils.introspect(
258: ProcessInstance.class, AttributedEntity.class);
259: SYSTEM_ATTRIBUTES = ClassUtils
260: .getPropertyNames(SYSTEM_PROPERTIES);
261: int n = SYSTEM_PROPERTIES.length;
262: SYSTEM_DATAFIELDS = new DataField[n];
263: for (int i = 0; i < n; i++) {
264: PropertyDescriptor propDesc = SYSTEM_PROPERTIES[i];
265: SYSTEM_DATAFIELDS[i] = new DataField(propDesc.getName(),
266: null, DataTypes.dataTypeForClass(propDesc
267: .getPropertyType()));
268: }
269: _dataFieldComparator = new Comparator() {
270: // ORDER BY id ASC
271: public int compare(Object o1, Object o2) {
272: return ((Comparable) (o1 instanceof DataField ? ((AbstractWFElement) o1)
273: .getId()
274: : o1))
275: .compareTo(o2 instanceof DataField ? ((AbstractWFElement) o2)
276: .getId()
277: : o2);
278: }
279: };
280: }
281:
282: public static DataField findSystemDataField(String id) {
283: int i = Arrays.binarySearch(SYSTEM_DATAFIELDS, id,
284: _dataFieldComparator);
285: return i < 0 ? null : SYSTEM_DATAFIELDS[i];
286: }
287:
288: private ProcessInstanceAttributes() {
289: }
290: }
|