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.workfloweditor.vfs;
020:
021: import java.util.*;
022:
023: import org.openharmonise.him.*;
024: import org.openharmonise.him.context.StateHandler;
025: import org.openharmonise.him.metadata.range.swing.workflowstagepermissions.*;
026: import org.openharmonise.vfs.*;
027: import org.openharmonise.vfs.context.*;
028: import org.openharmonise.vfs.metadata.*;
029: import org.openharmonise.vfs.metadata.range.*;
030: import org.openharmonise.vfs.servers.ServerList;
031: import org.openharmonise.workfloweditor.model.*;
032:
033: /**
034: * Virtual file system implmentation of {@link org.openharmonise.workfloweditor.model.WorkflowModel}.
035: *
036: * @author Matthew Large
037: * @version $Revision: 1.1 $
038: *
039: */
040: public class VFSWorkflowModel extends WorkflowModel {
041:
042: /**
043: * Workflow property.
044: */
045: private Property m_workflowProp = null;
046:
047: /**
048: * Virtual file for the collection containing the workflow stage instances.
049: */
050: private VirtualFile m_valuesCollection = null;
051:
052: /**
053: * Constructs a new virtual file system workflow model.
054: *
055: * @param sTitle Title
056: * @param prop Workflow property
057: */
058: public VFSWorkflowModel(String sTitle, Property prop) {
059: super (sTitle);
060: this .m_workflowProp = prop;
061: this .setup();
062: }
063:
064: /**
065: * Configures this model.
066: *
067: */
068: private void setup() {
069: AbstractVirtualFileSystem vfs = ServerList.getInstance()
070: .getHarmoniseServer().getVFS();
071:
072: VirtualFile vfRoleCollection = vfs.getVirtualFile(
073: "/webdav/RBS_VALS/roles").getResource();
074:
075: WorkflowPermissionsResourceFilter resourceFilter = new WorkflowPermissionsResourceFilter();
076:
077: Iterator itor = vfRoleCollection.getChildren().iterator();
078: while (itor.hasNext()) {
079: String sRolePath = (String) itor.next();
080: VirtualFile vfRoleFile = vfs.getVirtualFile(sRolePath)
081: .getResource();
082: if (vfRoleFile != null
083: && resourceFilter.showResource(vfRoleFile)) {
084: VFSRole vfsRole = new VFSRole(sRolePath);
085: this .addAvailableRole(vfsRole);
086: }
087: }
088:
089: this .m_valuesCollection = this .getStagesCollection();
090:
091: itor = this .m_valuesCollection.getChildren().iterator();
092: while (itor.hasNext()) {
093: String sChildPath = (String) itor.next();
094: boolean bFound = false;
095: Iterator itor2 = this .getWorkflowStages().iterator();
096: while (itor2.hasNext()) {
097: VFSWorkflowStage tempStage = (VFSWorkflowStage) itor2
098: .next();
099: if (tempStage.getPath().equals(sChildPath)) {
100: bFound = true;
101: break;
102: }
103: }
104: if (!bFound) {
105: VirtualFile vfStageFile = vfs
106: .getVirtualFile(sChildPath).getResource();
107: VFSWorkflowStage vfsWorkflowStage = new VFSWorkflowStage(
108: this , vfStageFile);
109: super .addWorkflowStage(vfsWorkflowStage);
110: }
111: }
112: }
113:
114: /* (non-Javadoc)
115: * @see com.simulacramedia.workfloweditor.model.WorkflowModel#addWorkflowStage(com.simulacramedia.workfloweditor.model.WorkflowStage)
116: */
117: public void addWorkflowStage(WorkflowStage stage) {
118: super .addWorkflowStage(stage);
119: }
120:
121: /* (non-Javadoc)
122: * @see com.simulacramedia.workfloweditor.model.WorkflowModel#removeWorkflowStage(com.simulacramedia.workfloweditor.model.WorkflowStage)
123: */
124: public void removeWorkflowStage(WorkflowStage stage) {
125: StateHandler.getInstance().addWait("WORKFLOWSTAGEDELETE");
126: try {
127: VFSWorkflowStage vfsStage = (VFSWorkflowStage) stage;
128: AbstractVirtualFileSystem vfs = ServerList.getInstance()
129: .getHarmoniseServer().getVFS();
130: VirtualFile vfFile = vfs.getVirtualFile(vfsStage.getPath())
131: .getResource();
132: if (vfFile != null) {
133: vfFile.delete();
134: }
135: } catch (Exception e) {
136: e.printStackTrace();
137: } finally {
138: StateHandler.getInstance()
139: .removeWait("WORKFLOWSTAGEDELETE");
140: super .removeWorkflowStage(stage);
141: }
142: }
143:
144: /**
145: * Returns the workflow property.
146: *
147: * @return Workflow property
148: */
149: public Property getWorkflowProperty() {
150: return this .m_workflowProp;
151: }
152:
153: /**
154: * Returns the collection containing the workflow stage instances.
155: *
156: * @return Workflow stage instances collection
157: */
158: public VirtualFile getStagesCollection() {
159: AbstractVirtualFileSystem vfs = ServerList.getInstance()
160: .getHarmoniseServer().getVFS();
161: String sValueCollectionPath = (String) ((ResourceRange) this .m_workflowProp
162: .getRange()).getHREFs().get(0);
163:
164: return vfs.getVirtualFile(sValueCollectionPath).getResource();
165: }
166:
167: }
|