001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.resources.workflow.properties.ranges;
020:
021: import java.util.*;
022:
023: import org.openharmonise.commons.dsi.*;
024: import org.openharmonise.rm.DataAccessException;
025: import org.openharmonise.rm.dsi.DataStoreInterfaceFactory;
026: import org.openharmonise.rm.factory.*;
027: import org.openharmonise.rm.resources.*;
028: import org.openharmonise.rm.resources.metadata.properties.ranges.AbsoluteChildObjectRange;
029: import org.openharmonise.rm.resources.workflow.values.WorkflowStageValue;
030: import org.openharmonise.rm.workflow.WorkflowPropertyInstance;
031:
032: /**
033: * Range definition for a workflow definition.
034: *
035: * @author Michael Bell
036: * @version $Revision: 1.2 $
037: *
038: */
039: public class WorkflowRange extends AbsoluteChildObjectRange {
040:
041: /**
042: * Default constructor.
043: */
044: public WorkflowRange() {
045: super (WorkflowRange.class.getName());
046: }
047:
048: /**
049: * @param sObjClassName
050: * @param sDetails
051: */
052: public WorkflowRange(String sObjClassName, String sDetails) {
053: super (sObjClassName, sDetails);
054: }
055:
056: /**
057: * Returns the list of stage definitions associated with this range.
058: *
059: * @param dsi
060: * @return
061: * @throws DataAccessException
062: */
063: public List getStageDefinitions() throws DataAccessException {
064: return getAvailableValues();
065: }
066:
067: /* (non-Javadoc)
068: * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#getPropertyInstanceClass()
069: */
070: public Class getPropertyInstanceClass()
071: throws ClassNotFoundException {
072: return WorkflowPropertyInstance.class;
073: }
074:
075: /**
076: * Returns a list of available <code>AbstractChildObject</code> instances this
077: * range defines.
078: *
079: * @return
080: * @throws DataAccessException
081: */
082: public List getAvailableValues() throws DataAccessException {
083: Vector result = new Vector();
084: try {
085: AbstractDataStoreInterface dsi = DataStoreInterfaceFactory
086: .getDataStoreInterface();
087:
088: AbstractChildObject child = (AbstractChildObject) WorkflowStageValue.class
089: .newInstance();
090:
091: String sParentClassName = child.getParentObjectClassName();
092:
093: Iterator iter = getAllowedParents().iterator();
094:
095: while (iter.hasNext()) {
096: String sPath = (String) iter.next();
097:
098: AbstractParentObject parent = (AbstractParentObject) HarmoniseObjectFactory
099: .instantiateHarmoniseObject(dsi,
100: sParentClassName, sPath);
101:
102: addAllChildObjectsToList(result, parent);
103:
104: }
105:
106: } catch (HarmoniseFactoryException e) {
107: throw new DataAccessException(
108: "Error occured getting parent from factory", e);
109: } catch (InstantiationException e) {
110: throw new DataAccessException(
111: "Error occured getting class for child", e);
112: } catch (IllegalAccessException e) {
113: throw new DataAccessException(
114: "Error occured getting class for child", e);
115: } catch (DataStoreException e) {
116: throw new DataAccessException(
117: "Error occured getting class for child:", e);
118: }
119:
120: return result;
121: }
122:
123: /* (non-Javadoc)
124: * @see org.openharmonise.rm.resources.metadata.properties.ranges.Range#isValid(java.lang.Object)
125: */
126: public boolean isValid(Object obj) {
127:
128: return (obj instanceof WorkflowStageValue);
129: }
130:
131: /* (non-Javadoc)
132: * @see org.openharmonise.rm.resources.metadata.properties.ranges.ChildObjectRange#getChildObjectValueClassName(org.openharmonise.rm.resources.AbstractChildObject)
133: */
134: public String getChildObjectValueClassName(AbstractChildObject child) {
135: return WorkflowStageValue.class.getName();
136: }
137:
138: /* (non-Javadoc)
139: * @see org.openharmonise.rm.resources.metadata.properties.ranges.AbsoluteChildObjectRange#setObjectRestriction(java.lang.String)
140: */
141: public void setObjectRestriction(String sClassname) {
142: //do nothing as this can't be reset
143: }
144:
145: }
|