KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > workfloweditor > vfs > VFSWorkflowStage


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.workfloweditor.vfs;
20
21 import java.util.*;
22
23 import org.openharmonise.commons.xml.namespace.*;
24 import org.openharmonise.him.*;
25 import org.openharmonise.vfs.*;
26 import org.openharmonise.vfs.metadata.*;
27 import org.openharmonise.vfs.metadata.value.*;
28 import org.openharmonise.vfs.servers.ServerList;
29 import org.openharmonise.workfloweditor.model.*;
30
31 /**
32  * Virtual file system implementation of {@link org.openharmonise.workfloweditor.model.WorkflowStage}.
33  *
34  * @author Matthew Large
35  * @version $Revision: 1.2 $
36  *
37  */

38 public class VFSWorkflowStage extends WorkflowStage {
39
40     /**
41      * Virtual file for the value for this workflow stage.
42      */

43     private VirtualFile m_valueResource = null;
44     
45     /**
46      * Property instance for the definition.
47      */

48     private PropertyInstance m_definitionPropInst = null;
49     
50     /**
51      * Property instance for the roles.
52      */

53     private PropertyInstance m_rolesPropInst = null;
54     
55     /**
56      * Property instance for the dependencies.
57      */

58     private PropertyInstance m_dependenciesPropInst = null;
59     
60     /**
61      * Property instance for the inheritance attribute.
62      */

63     private PropertyInstance m_inheritPropInst = null;
64     
65     /**
66      * Property instance for the mandatory attribute.
67      */

68     private PropertyInstance m_mandatoryPropInst = null;
69
70     /**
71      * Constructs a new vitual file system workflow stage instance.
72      *
73      * @param model Model
74      * @param valueResource Value for the stage
75      */

76     public VFSWorkflowStage(WorkflowModel model, VirtualFile valueResource) {
77         super();
78         this.setModel(model);
79         this.m_valueResource = valueResource;
80         this.setup();
81     }
82
83     /**
84      * Configures this workflow stage.
85      *
86      */

87     private void setup() {
88         m_definitionPropInst = this.m_valueResource.getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_RELN");
89         Iterator itor = m_definitionPropInst.getValues().iterator();
90         while (itor.hasNext()) {
91             ResourceValue value = (ResourceValue) itor.next();
92             String JavaDoc sDefinitionPath = value.getValue();
93             VirtualFile vfDefinitionFile = this.m_valueResource.getVFS().getVirtualFile(sDefinitionPath).getResource();
94             VFSWorkflowStageDefinition stageDefinition = new VFSWorkflowStageDefinition(vfDefinitionFile, (VFSWorkflowModel)this.getModel());
95             super.setDefinition(stageDefinition);
96         }
97         
98         m_rolesPropInst = this.m_valueResource.getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_ROLES");
99         itor = m_rolesPropInst.getValues().iterator();
100         while (itor.hasNext()) {
101             ValueValue value = (ValueValue) itor.next();
102             String JavaDoc sValuePath = value.getValue();
103             Iterator itor2 = this.getModel().getAvailableRoles().iterator();
104             while (itor2.hasNext()) {
105                 VFSRole role = (VFSRole) itor2.next();
106                 if(role.getValuePath().equals(sValuePath)) {
107                     super.addRole(role);
108                 }
109             }
110         }
111         
112         m_dependenciesPropInst = this.m_valueResource.getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_DEPEND");
113         itor = m_dependenciesPropInst.getValues().iterator();
114         while (itor.hasNext()) {
115             ResourceValue value = (ResourceValue) itor.next();
116             String JavaDoc sDependencyPath = value.getValue();
117             VFSWorkflowStage dependencyStage = null;
118             Iterator itor2 = this.getModel().getWorkflowStages().iterator();
119             while (itor2.hasNext()) {
120                 VFSWorkflowStage stage = (VFSWorkflowStage) itor2.next();
121                 if(stage.getPath().equals(sDependencyPath)) {
122                     dependencyStage = stage;
123                 }
124             }
125             if(dependencyStage!=null) {
126                 super.addDependancy(dependencyStage);
127             } else {
128                 dependencyStage = new VFSWorkflowStage(this.getModel(), this.m_valueResource.getVFS().getVirtualFile(sDependencyPath).getResource());
129                 this.getModel().addWorkflowStage(dependencyStage);
130                 super.addDependancy(dependencyStage);
131             }
132         }
133         
134         m_inheritPropInst = this.m_valueResource.getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_INHERIT");
135         itor = m_inheritPropInst.getValues().iterator();
136         while (itor.hasNext()) {
137             BooleanValue value = (BooleanValue) itor.next();
138             super.setInheritable(value.getValue());
139         }
140         m_mandatoryPropInst = this.m_valueResource.getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_MAND");
141         itor = m_mandatoryPropInst.getValues().iterator();
142         while (itor.hasNext()) {
143             BooleanValue value = (BooleanValue) itor.next();
144             super.setMandatory(value.getValue());
145         }
146     }
147     
148     private PropertyInstance getMandatoryPropertyInstance() {
149         return this.getValueResource().getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_MAND");
150     }
151     
152     private PropertyInstance getInheritPropertyInstance() {
153         return this.getValueResource().getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_INHERIT");
154     }
155     
156     private PropertyInstance getDependenciesPropertyInstance() {
157         return this.getValueResource().getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_DEPEND");
158     }
159     
160     private PropertyInstance getRolesPropertyInstance() {
161         return this.getValueResource().getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_ROLES");
162     }
163     
164     private PropertyInstance getDefinitionPropertyInstance() {
165         return this.getValueResource().getProperty(NamespaceType.OHRM.getURI(), "WORKFLOW_RELN");
166     }
167
168     /**
169      * @param definition
170      * @param model
171      */

172     private VFSWorkflowStage(
173         WorkflowStageDefinition definition,
174         WorkflowModel model) {
175         super(definition, model);
176     }
177
178     /**
179      * @param definition
180      * @param dependancies
181      * @param model
182      */

183     private VFSWorkflowStage(
184         WorkflowStageDefinition definition,
185         List dependancies,
186         WorkflowModel model) {
187         super(definition, dependancies, model);
188     }
189     
190     /**
191      * Returns the full path to the virtual file for the value for this
192      * workflow stage.
193      *
194      * @return Full path
195      */

196     public String JavaDoc getPath() {
197         return this.m_valueResource.getFullPath();
198     }
199
200     /* (non-Javadoc)
201      * @see com.simulacramedia.workfloweditor.model.WorkflowStage#addDependancy(com.simulacramedia.workfloweditor.model.WorkflowStage)
202      */

203     public void addDependancy(WorkflowStage stage) {
204         VFSWorkflowStage vfsStage = (VFSWorkflowStage) stage;
205         ResourceValue value = (ResourceValue) this.getDependenciesPropertyInstance().getNewValueInstance();
206         value.setValue(vfsStage.getPath());
207         this.getDependenciesPropertyInstance().addValue(value);
208         super.addDependancy(stage);
209     }
210
211     /* (non-Javadoc)
212      * @see com.simulacramedia.workfloweditor.model.WorkflowStage#addRole(com.simulacramedia.workfloweditor.model.Role)
213      */

214     public void addRole(Role role) {
215         VFSRole vfsRole = (VFSRole) role;
216         ValueValue value = (ValueValue) this.getRolesPropertyInstance().getNewValueInstance();
217         value.setValue(vfsRole.getValuePath());
218         this.getRolesPropertyInstance().addValue(value);
219         super.addRole(role);
220     }
221
222     /* (non-Javadoc)
223      * @see com.simulacramedia.workfloweditor.model.WorkflowStage#removeDependancy(com.simulacramedia.workfloweditor.model.WorkflowStage)
224      */

225     public void removeDependancy(WorkflowStage stage) {
226         VFSWorkflowStage vfsStage = (VFSWorkflowStage) stage;
227         Iterator itor = this.getDependenciesPropertyInstance().getValues().iterator();
228         while (itor.hasNext()) {
229             ResourceValue value = (ResourceValue) itor.next();
230             if(value.getValue().equals(vfsStage.getPath())) {
231                 this.getDependenciesPropertyInstance().removeValue(value);
232                 break;
233             }
234         }
235         super.removeDependancy(stage);
236     }
237
238     /* (non-Javadoc)
239      * @see com.simulacramedia.workfloweditor.model.WorkflowStage#removeRole(com.simulacramedia.workfloweditor.model.Role)
240      */

241     public void removeRole(Role role) {
242         VFSRole vfsRole = (VFSRole) role;
243         Iterator itor = this.getRolesPropertyInstance().getValues().iterator();
244         while (itor.hasNext()) {
245             ValueValue value = (ValueValue) itor.next();
246             if(value.getValue().equals(vfsRole.getValuePath())) {
247                 this.getRolesPropertyInstance().removeValue(value);
248                 break;
249             }
250         }
251         super.removeRole(role);
252     }
253
254     /* (non-Javadoc)
255      * @see com.simulacramedia.workfloweditor.model.WorkflowStage#setInheritable(boolean)
256      */

257     public void setInheritable(boolean bInheritable) {
258         boolean bOkToSet = true;
259         if(bInheritable) {
260             Iterator itor = super.getDependancies().iterator();
261             while (itor.hasNext()) {
262                 WorkflowStage stage = (WorkflowStage) itor.next();
263                 if(!stage.isInheritable()) {
264                     bOkToSet=false;
265                 }
266             }
267         }
268         if(bOkToSet) {
269             this.m_inheritPropInst.clearAllValues();
270             BooleanValue value = (BooleanValue) this.getInheritPropertyInstance().getNewValueInstance();
271             value.setValue(bInheritable);
272             this.getInheritPropertyInstance().addValue(value);
273             super.setInheritable(bInheritable);
274         }
275     }
276
277     /* (non-Javadoc)
278      * @see com.simulacramedia.workfloweditor.model.WorkflowStage#setMandatory(boolean)
279      */

280     public void setMandatory(boolean bMandatory) {
281         this.getMandatoryPropertyInstance().clearAllValues();
282         BooleanValue value = (BooleanValue) this.getMandatoryPropertyInstance().getNewValueInstance();
283         value.setValue(bMandatory);
284         this.getMandatoryPropertyInstance().addValue(value);
285         super.setMandatory(bMandatory);
286     }
287
288     /* (non-Javadoc)
289      * @see com.simulacramedia.workfloweditor.model.WorkflowStage#setDefinition(com.simulacramedia.workfloweditor.model.WorkflowStageDefinition)
290      */

291     public void setDefinition(WorkflowStageDefinition definition) {
292         VFSWorkflowStageDefinition vfsDefinition = (VFSWorkflowStageDefinition) definition;
293         if(this.getDefinitionPropertyInstance().getValues().size()>0) {
294             this.getDefinitionPropertyInstance().clearAllValues();
295         }
296         ResourceValue value = (ResourceValue) this.getDefinitionPropertyInstance().getNewValueInstance();
297         value.setValue(vfsDefinition.getPath());
298         this.getDefinitionPropertyInstance().addValue(value);
299         super.setDefinition(definition);
300     }
301     
302     private VirtualFile getValueResource() {
303         return ServerList.getInstance().getHarmoniseServer().getVFS().getVirtualFile(this.getPath()).getResource();
304     }
305
306 }
307
Popular Tags