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.workflow;
020:
021: import java.sql.*;
022: import java.util.*;
023: import java.util.logging.*;
024:
025: import org.openharmonise.commons.dsi.*;
026: import org.openharmonise.commons.dsi.dml.SelectStatement;
027: import org.openharmonise.rm.*;
028: import org.openharmonise.rm.factory.*;
029: import org.openharmonise.rm.metadata.*;
030: import org.openharmonise.rm.resources.*;
031: import org.openharmonise.rm.resources.metadata.properties.Property;
032: import org.openharmonise.rm.resources.metadata.properties.domains.Domain;
033: import org.openharmonise.rm.resources.workflow.properties.WorkflowProperty;
034: import org.openharmonise.rm.resources.workflow.values.WorkflowStageValue;
035:
036: /**
037: * Profile specifically for holding <code>WorkflowPropertyInstances</code>.
038: *
039: * @author Michael Bell
040: * @version $Revision: 1.2 $
041: *
042: */
043: public class WorkflowProfile extends Profile {
044:
045: public static final String WORKFLOW_PROFILE_NAME = "Workflow";
046:
047: private static final Logger m_logger = Logger
048: .getLogger(WorkflowProfile.class.getName());
049:
050: {
051: try {
052: super .setName(WORKFLOW_PROFILE_NAME);
053: } catch (InvalidNameException e) {
054: // shouldn't be a problem but log exception anyway
055: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
056: }
057: }
058:
059: /**
060: *
061: */
062: public WorkflowProfile() {
063: super ();
064:
065: }
066:
067: /**
068: * @param dbintrf
069: */
070: public WorkflowProfile(AbstractDataStoreInterface dbintrf) {
071: super (dbintrf);
072:
073: }
074:
075: /**
076: * @param dbintrf
077: * @param obj
078: */
079: public WorkflowProfile(AbstractDataStoreInterface dbintrf,
080: AbstractProfiledObject obj) {
081: super (dbintrf, obj);
082:
083: }
084:
085: /**
086: * @param dbintrf
087: * @param nId
088: * @param obj
089: */
090: public WorkflowProfile(AbstractDataStoreInterface dbintrf, int nId,
091: AbstractProfiledObject obj) {
092: super (dbintrf, nId, obj);
093:
094: }
095:
096: /* (non-Javadoc)
097: * @see org.openharmonise.rm.resources.AbstractObject#getName()
098: */
099: public String getName() throws DataAccessException {
100: return WORKFLOW_PROFILE_NAME;
101: }
102:
103: /* (non-Javadoc)
104: * @see org.openharmonise.rm.resources.AbstractObject#setName(java.lang.String)
105: */
106: public void setName(String sName) {
107: //no nothing, can't set name
108: }
109:
110: /* (non-Javadoc)
111: * @see org.openharmonise.rm.metadata.Profile#isValid(org.openharmonise.rm.resources.AbstractProfiledObject)
112: */
113: public boolean isValid(AbstractProfiledObject profObj)
114: throws DataAccessException {
115:
116: //don't make any restriction - at most should only allow RBS props
117: return true;
118: }
119:
120: /**
121: * @param dsi
122: * @return
123: * @throws DataAccessException
124: */
125: static public List getWorkflowProperties(
126: AbstractDataStoreInterface dsi) throws DataAccessException {
127: List wkflw_props = new ArrayList();
128: String sClassname = WorkflowProperty.class.getName();
129: ResultSet rs = null;
130: try {
131: SelectStatement select = new SelectStatement();
132:
133: select.addSelectColumn(AbstractObject.getColumnRef(
134: sClassname, AbstractObject.ATTRIB_ID));
135:
136: select.addWhereCondition(AbstractObject.getColumnRef(
137: sClassname, AbstractObject.ATTRIB_TYPE), "=",
138: WorkflowProperty.class.getName());
139:
140: rs = dsi.execute(select);
141:
142: while (rs.next()) {
143: WorkflowProperty prop = (WorkflowProperty) HarmoniseObjectFactory
144: .instantiateHarmoniseObject(dsi, sClassname, rs
145: .getInt(1));
146: wkflw_props.add(prop);
147: }
148:
149: } catch (DataStoreException e) {
150: throw new DataAccessException(e.getLocalizedMessage(), e);
151: } catch (SQLException e) {
152: throw new DataAccessException(e.getLocalizedMessage(), e);
153: } catch (HarmoniseFactoryException e) {
154: throw new DataAccessException(e.getLocalizedMessage(), e);
155: } finally {
156: try {
157: rs.close();
158: } catch (SQLException e) {
159: throw new DataAccessException(e.getLocalizedMessage(),
160: e);
161: }
162: }
163:
164: return wkflw_props;
165: }
166:
167: /**
168: * Returns the available workflow properties for the given profiled
169: * object.
170: *
171: * @param profObj
172: * @return
173: * @throws DataAccessException
174: */
175: public static List getAvailableWorkflowProperties(
176: AbstractProfiledObject profObj) throws DataAccessException {
177: List props = new ArrayList();
178:
179: List normProps = Domain.getAvailableProperties(profObj
180: .getDataStoreInterface(), profObj);
181:
182: Iterator iter = normProps.iterator();
183:
184: while (iter.hasNext()) {
185: Property tmpProp = (Property) iter.next();
186:
187: if (tmpProp instanceof WorkflowProperty) {
188: props.add(tmpProp);
189: }
190: }
191:
192: return props;
193: }
194:
195: /* (non-Javadoc)
196: * @see org.openharmonise.rm.metadata.Profile#getAvailableProperties()
197: */
198: public List getAvailableProperties() throws DataAccessException {
199: return getWorkflowProperties(m_dsi);
200: }
201:
202: /* (non-Javadoc)
203: * @see org.openharmonise.rm.resources.AbstractObject#markAsNew()
204: */
205: public void markAsNew() throws PopulateException {
206:
207: try {
208: List propInsts = getPropertyInstances();
209:
210: Iterator iter = propInsts.iterator();
211:
212: while (iter.hasNext()) {
213: WorkflowPropertyInstance propInst = (WorkflowPropertyInstance) iter
214: .next();
215:
216: List vals = propInst.getValues();
217:
218: Iterator valIter = vals.iterator();
219:
220: while (valIter.hasNext()) {
221: WorkflowStageValue stage = (WorkflowStageValue) valIter
222: .next();
223:
224: if (stage.isInheritable() == false) {
225: propInst.removeValue(stage);
226: }
227: }
228: }
229: } catch (DataAccessException e) {
230: throw new PopulateException(e.getLocalizedMessage(), e);
231: } catch (InvalidPropertyValueException e) {
232: throw new PopulateException(e.getLocalizedMessage(), e);
233: }
234:
235: super .markAsNew();
236: }
237:
238: /**
239: * Returns the workflow property instance sPropName from the profiled object profObj
240: * if the object has that workflow property instance. otherwise, it returns null.
241: * @param profObj The Profiled object
242: * @param sPropName The name of the property instance to be returned
243: * @return A WorkflowPropertyInstance if the object has it, or null otherwise.
244: * @throws InvalidPropertyInstanceException
245: * @throws DataAccessException
246: */
247: public static WorkflowPropertyInstance getWorkflowPropertyInstance(
248: AbstractProfiledObject profObj, String sPropName)
249: throws InvalidPropertyInstanceException,
250: DataAccessException {
251: WorkflowProfile workflowProf = (WorkflowProfile) profObj
252: .getProfile(WORKFLOW_PROFILE_NAME);
253: return (WorkflowPropertyInstance) workflowProf
254: .getPropertyInstance(sPropName);
255: }
256: }
|