1 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 38 public class VFSWorkflowStage extends WorkflowStage { 39 40 43 private VirtualFile m_valueResource = null; 44 45 48 private PropertyInstance m_definitionPropInst = null; 49 50 53 private PropertyInstance m_rolesPropInst = null; 54 55 58 private PropertyInstance m_dependenciesPropInst = null; 59 60 63 private PropertyInstance m_inheritPropInst = null; 64 65 68 private PropertyInstance m_mandatoryPropInst = null; 69 70 76 public VFSWorkflowStage(WorkflowModel model, VirtualFile valueResource) { 77 super(); 78 this.setModel(model); 79 this.m_valueResource = valueResource; 80 this.setup(); 81 } 82 83 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 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 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 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 172 private VFSWorkflowStage( 173 WorkflowStageDefinition definition, 174 WorkflowModel model) { 175 super(definition, model); 176 } 177 178 183 private VFSWorkflowStage( 184 WorkflowStageDefinition definition, 185 List dependancies, 186 WorkflowModel model) { 187 super(definition, dependancies, model); 188 } 189 190 196 public String getPath() { 197 return this.m_valueResource.getFullPath(); 198 } 199 200 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 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 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 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 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 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 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 |