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;
020:
021: import java.util.*;
022:
023: import org.openharmonise.commons.dsi.AbstractDataStoreInterface;
024: import org.openharmonise.rm.*;
025: import org.openharmonise.rm.resources.lifecycle.*;
026: import org.openharmonise.rm.resources.metadata.properties.*;
027: import org.openharmonise.rm.resources.metadata.properties.domains.Domain;
028: import org.openharmonise.rm.resources.metadata.properties.ranges.*;
029: import org.openharmonise.rm.resources.workflow.properties.domains.WorkflowPropertyDomain;
030: import org.openharmonise.rm.resources.workflow.properties.ranges.WorkflowRange;
031: import org.openharmonise.rm.resources.workflow.values.WorkflowStageValueGroup;
032:
033: /**
034: * This class represents a definition of a workflow lifecycle, containing references to
035: * workflow stages which must be completed before the workflow is completed.
036: *
037: * The class is implemented as an extension of <code>Property</code>, offering
038: * extra utility methods to manage work flow specific data. The range of this
039: * property object must always be <code>WorkflowRange</code>.
040: *
041: * @author Michael Bell
042: * @version $Revision: 1.2 $
043: *
044: */
045: public class WorkflowProperty extends Property {
046:
047: public static final String TAG_WORKFLOW_PROPERTY = "WorkflowProperty";
048:
049: static {
050: RangeFactory.getInstance().addNewRange(
051: WorkflowRange.class.getName(),
052: WorkflowRange.class.getName());
053: }
054:
055: //initialise range
056: {
057: m_range = new WorkflowRange();
058: }
059:
060: /**
061: * Basic constructor.
062: */
063: public WorkflowProperty() {
064: super ();
065: }
066:
067: /**
068: * Basic constructor which takes a datastore interface.
069: *
070: * @param dbintrf
071: */
072: public WorkflowProperty(AbstractDataStoreInterface dbintrf) {
073: super (dbintrf);
074:
075: }
076:
077: /**
078: * Constructs a specific instance of a workflow definition, defined
079: * by the given identifier.
080: *
081: * @param dbintrf
082: * @param nId
083: */
084: public WorkflowProperty(AbstractDataStoreInterface dbintrf, int nId) {
085: super (dbintrf, nId);
086: }
087:
088: /**
089: * Constructs a specific historical workflow instance.
090: *
091: * @param dbintrf
092: * @param nId
093: * @param bIsHist
094: */
095: public WorkflowProperty(AbstractDataStoreInterface dbintrf,
096: int nId, int nKey, boolean bIsHist) {
097: super (dbintrf, nId, nKey, bIsHist);
098:
099: }
100:
101: /* (non-Javadoc)
102: * @see org.openharmonise.rm.resources.metadata.properties.Property#setRange(org.openharmonise.rm.resources.metadata.properties.ranges.Range)
103: */
104: public void setRange(Range range) throws PopulateException {
105: if (range instanceof WorkflowRange) {
106: super .setRange(range);
107: } else {
108: String sRangeClass = null;
109: if (range != null) {
110: sRangeClass = range.getClass().getName();
111: }
112: throw new InvalidRangeException(
113: "Range has to be instance of workflowrange, not "
114: + sRangeClass);
115: }
116:
117: }
118:
119: public void setWorkflowValueGroup(WorkflowStageValueGroup valGrp)
120: throws PopulateException {
121:
122: try {
123: ((WorkflowRange) m_range).addAllowedParent(valGrp
124: .getFullPath());
125: } catch (DataAccessException e) {
126: throw new PopulateException(e.getLocalizedMessage(), e);
127: }
128: }
129:
130: /* (non-Javadoc)
131: * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
132: */
133: public String getParentObjectClassName() {
134:
135: return WorkflowPropertyGroup.class.getName();
136: }
137:
138: /* (non-Javadoc)
139: * @see org.openharmonise.rm.resources.metadata.properties.Property#checkDomainAndRange(org.openharmonise.rm.resources.metadata.properties.domains.Domain)
140: */
141: protected void checkDomainAndRange(Domain domain)
142: throws EditException {
143: //do nothing as there's no point
144: }
145:
146: /* (non-Javadoc)
147: * @see org.openharmonise.rm.resources.lifecycle.Editable#changeStatus(org.openharmonise.rm.resources.lifecycle.Status)
148: */
149: public Editable changeStatus(Status status) throws EditException {
150:
151: try {
152: List domains = getDomains();
153:
154: ListIterator iter = domains.listIterator();
155:
156: while (iter.hasNext()) {
157: Domain domain = (Domain) iter.next();
158:
159: if (WorkflowPropertyDomain.validate(this , domain) == false) {
160: throw new StatusChangeNotAllowedException(
161: "Domain not valid");
162: }
163:
164: }
165: } catch (DataAccessException e) {
166: throw new EditException(e);
167: }
168:
169: return super .changeStatus(status);
170: }
171:
172: /* (non-Javadoc)
173: * @see org.openharmonise.rm.publishing.Publishable#getTagName()
174: */
175: public String getTagName() {
176: return TAG_WORKFLOW_PROPERTY;
177: }
178: }
|