KickJava   Java API By Example, From Geeks To Geeks.

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


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.him.*;
24 import org.openharmonise.him.context.StateHandler;
25 import org.openharmonise.him.metadata.range.swing.workflowstagepermissions.*;
26 import org.openharmonise.vfs.*;
27 import org.openharmonise.vfs.context.*;
28 import org.openharmonise.vfs.metadata.*;
29 import org.openharmonise.vfs.metadata.range.*;
30 import org.openharmonise.vfs.servers.ServerList;
31 import org.openharmonise.workfloweditor.model.*;
32
33
34 /**
35  * Virtual file system implmentation of {@link org.openharmonise.workfloweditor.model.WorkflowModel}.
36  *
37  * @author Matthew Large
38  * @version $Revision: 1.1 $
39  *
40  */

41 public class VFSWorkflowModel extends WorkflowModel {
42
43     /**
44      * Workflow property.
45      */

46     private Property m_workflowProp = null;
47
48     /**
49      * Virtual file for the collection containing the workflow stage instances.
50      */

51     private VirtualFile m_valuesCollection = null;
52
53     /**
54      * Constructs a new virtual file system workflow model.
55      *
56      * @param sTitle Title
57      * @param prop Workflow property
58      */

59     public VFSWorkflowModel(String JavaDoc sTitle, Property prop) {
60         super(sTitle);
61         this.m_workflowProp = prop;
62         this.setup();
63     }
64     
65     /**
66      * Configures this model.
67      *
68      */

69     private void setup() {
70         AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS();
71         
72         VirtualFile vfRoleCollection = vfs.getVirtualFile("/webdav/RBS_VALS/roles").getResource();
73         
74         WorkflowPermissionsResourceFilter resourceFilter = new WorkflowPermissionsResourceFilter();
75         
76         Iterator itor = vfRoleCollection.getChildren().iterator();
77         while (itor.hasNext()) {
78             String JavaDoc sRolePath = (String JavaDoc) itor.next();
79             VirtualFile vfRoleFile = vfs.getVirtualFile(sRolePath).getResource();
80             if(vfRoleFile!=null && resourceFilter.showResource(vfRoleFile)) {
81                 VFSRole vfsRole = new VFSRole(sRolePath);
82                 this.addAvailableRole(vfsRole);
83             }
84         }
85         
86         this.m_valuesCollection = this.getStagesCollection();
87         
88         itor = this.m_valuesCollection.getChildren().iterator();
89         while (itor.hasNext()) {
90             String JavaDoc sChildPath = (String JavaDoc) itor.next();
91             boolean bFound = false;
92             Iterator itor2 = this.getWorkflowStages().iterator();
93             while (itor2.hasNext()) {
94                 VFSWorkflowStage tempStage = (VFSWorkflowStage) itor2.next();
95                 if(tempStage.getPath().equals(sChildPath)) {
96                     bFound=true;
97                     break;
98                 }
99             }
100             if(!bFound) {
101                 VirtualFile vfStageFile = vfs.getVirtualFile(sChildPath).getResource();
102                 VFSWorkflowStage vfsWorkflowStage = new VFSWorkflowStage(this, vfStageFile);
103                 super.addWorkflowStage(vfsWorkflowStage);
104             }
105         }
106     }
107
108     /* (non-Javadoc)
109      * @see com.simulacramedia.workfloweditor.model.WorkflowModel#addWorkflowStage(com.simulacramedia.workfloweditor.model.WorkflowStage)
110      */

111     public void addWorkflowStage(WorkflowStage stage) {
112         super.addWorkflowStage(stage);
113     }
114
115     /* (non-Javadoc)
116      * @see com.simulacramedia.workfloweditor.model.WorkflowModel#removeWorkflowStage(com.simulacramedia.workfloweditor.model.WorkflowStage)
117      */

118     public void removeWorkflowStage(WorkflowStage stage) {
119         StateHandler.getInstance().addWait("WORKFLOWSTAGEDELETE");
120         try {
121             VFSWorkflowStage vfsStage = (VFSWorkflowStage) stage;
122             AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS();
123             VirtualFile vfFile = vfs.getVirtualFile(vfsStage.getPath()).getResource();
124             if(vfFile!=null) {
125                 vfFile.delete();
126             }
127         } catch(Exception JavaDoc e) {
128             e.printStackTrace();
129         } finally {
130             StateHandler.getInstance().removeWait("WORKFLOWSTAGEDELETE");
131             super.removeWorkflowStage(stage);
132         }
133     }
134
135     /**
136      * Returns the workflow property.
137      *
138      * @return Workflow property
139      */

140     public Property getWorkflowProperty() {
141         return this.m_workflowProp;
142     }
143     
144     /**
145      * Returns the collection containing the workflow stage instances.
146      *
147      * @return Workflow stage instances collection
148      */

149     public VirtualFile getStagesCollection() {
150         AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS();
151         String JavaDoc sValueCollectionPath = (String JavaDoc) ((ResourceRange)this.m_workflowProp.getRange()).getHREFs().get(0);
152         
153         return vfs.getVirtualFile(sValueCollectionPath).getResource();
154     }
155
156 }
157
Popular Tags