KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > workflow > WorkflowProfile


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.rm.workflow;
20
21 import java.sql.*;
22 import java.util.*;
23 import java.util.logging.*;
24
25 import org.openharmonise.commons.dsi.*;
26 import org.openharmonise.commons.dsi.dml.SelectStatement;
27 import org.openharmonise.rm.*;
28 import org.openharmonise.rm.factory.*;
29 import org.openharmonise.rm.metadata.*;
30 import org.openharmonise.rm.resources.*;
31 import org.openharmonise.rm.resources.metadata.properties.Property;
32 import org.openharmonise.rm.resources.metadata.properties.domains.Domain;
33 import org.openharmonise.rm.resources.workflow.properties.WorkflowProperty;
34 import org.openharmonise.rm.resources.workflow.values.WorkflowStageValue;
35
36
37 /**
38  * Profile specifically for holding <code>WorkflowPropertyInstances</code>.
39  *
40  * @author Michael Bell
41  * @version $Revision: 1.2 $
42  *
43  */

44 public class WorkflowProfile extends Profile {
45
46     public static final String JavaDoc WORKFLOW_PROFILE_NAME = "Workflow";
47     
48     private static final Logger m_logger = Logger.getLogger(WorkflowProfile.class.getName());
49     
50     {
51         try {
52             super.setName(WORKFLOW_PROFILE_NAME);
53         } catch (InvalidNameException e) {
54             // shouldn't be a problem but log exception anyway
55
m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
56         }
57     }
58
59     /**
60      *
61      */

62     public WorkflowProfile() {
63         super();
64         
65     }
66
67     /**
68      * @param dbintrf
69      */

70     public WorkflowProfile(AbstractDataStoreInterface dbintrf) {
71         super(dbintrf);
72         
73     }
74
75     /**
76      * @param dbintrf
77      * @param obj
78      */

79     public WorkflowProfile(
80         AbstractDataStoreInterface dbintrf,
81         AbstractProfiledObject obj) {
82         super(dbintrf, obj);
83         
84     }
85
86     /**
87      * @param dbintrf
88      * @param nId
89      * @param obj
90      */

91     public WorkflowProfile(
92         AbstractDataStoreInterface dbintrf,
93         int nId,
94         AbstractProfiledObject obj) {
95         super(dbintrf, nId, obj);
96         
97     }
98
99     /* (non-Javadoc)
100      * @see org.openharmonise.rm.resources.AbstractObject#getName()
101      */

102     public String JavaDoc getName() throws DataAccessException {
103         return WORKFLOW_PROFILE_NAME;
104     }
105
106     /* (non-Javadoc)
107      * @see org.openharmonise.rm.resources.AbstractObject#setName(java.lang.String)
108      */

109     public void setName(String JavaDoc sName) {
110         //no nothing, can't set name
111
}
112
113     /* (non-Javadoc)
114      * @see org.openharmonise.rm.metadata.Profile#isValid(org.openharmonise.rm.resources.AbstractProfiledObject)
115      */

116     public boolean isValid(AbstractProfiledObject profObj)
117         throws DataAccessException {
118
119         //don't make any restriction - at most should only allow RBS props
120
return true;
121     }
122
123     /**
124      * @param dsi
125      * @return
126      * @throws DataAccessException
127      */

128     static public List getWorkflowProperties(AbstractDataStoreInterface dsi) throws DataAccessException {
129         List wkflw_props = new ArrayList();
130         String JavaDoc sClassname = WorkflowProperty.class.getName();
131         ResultSet rs = null;
132         try {
133             SelectStatement select = new SelectStatement();
134             
135             select.addSelectColumn(AbstractObject.getColumnRef(sClassname,AbstractObject.ATTRIB_ID));
136             
137             select.addWhereCondition(AbstractObject.getColumnRef(sClassname,AbstractObject.ATTRIB_TYPE), "=",WorkflowProperty.class.getName());
138             
139             rs = dsi.execute(select);
140             
141             while(rs.next()) {
142                 WorkflowProperty prop = (WorkflowProperty) HarmoniseObjectFactory.instantiateHarmoniseObject(dsi, sClassname, rs.getInt(1));
143                 wkflw_props.add(prop);
144             }
145             
146         } catch (DataStoreException e) {
147             throw new DataAccessException(e.getLocalizedMessage(),e);
148         } catch (SQLException e) {
149             throw new DataAccessException(e.getLocalizedMessage(),e);
150         } catch (HarmoniseFactoryException e) {
151             throw new DataAccessException(e.getLocalizedMessage(),e);
152         } finally {
153             try {
154                 rs.close();
155             } catch (SQLException e) {
156                 throw new DataAccessException(e.getLocalizedMessage(),e);
157             }
158         }
159
160         return wkflw_props;
161     }
162     
163     /**
164      * Returns the available workflow properties for the given profiled
165      * object.
166      *
167      * @param profObj
168      * @return
169      * @throws DataAccessException
170      */

171     public static List getAvailableWorkflowProperties(AbstractProfiledObject profObj) throws DataAccessException {
172         List props = new ArrayList();
173         
174         List normProps = Domain.getAvailableProperties(profObj.getDataStoreInterface(), profObj);
175         
176         Iterator iter = normProps.iterator();
177         
178         while (iter.hasNext()) {
179             Property tmpProp = (Property) iter.next();
180             
181             if(tmpProp instanceof WorkflowProperty) {
182                 props.add(tmpProp);
183             }
184         }
185         
186         return props;
187     }
188
189     /* (non-Javadoc)
190      * @see org.openharmonise.rm.metadata.Profile#getAvailableProperties()
191      */

192     public List getAvailableProperties() throws DataAccessException {
193         return getWorkflowProperties(m_dsi);
194     }
195
196     /* (non-Javadoc)
197      * @see org.openharmonise.rm.resources.AbstractObject#markAsNew()
198      */

199     public void markAsNew() throws PopulateException {
200         
201         try {
202             List propInsts = getPropertyInstances();
203             
204             Iterator iter = propInsts.iterator();
205             
206             while(iter.hasNext()) {
207                 WorkflowPropertyInstance propInst = (WorkflowPropertyInstance) iter.next();
208                 
209                 List vals = propInst.getValues();
210                 
211                 Iterator valIter = vals.iterator();
212                 
213                 while (valIter.hasNext()) {
214                     WorkflowStageValue stage = (WorkflowStageValue) valIter.next();
215                     
216                     if(stage.isInheritable() == false) {
217                         propInst.removeValue(stage);
218                     }
219                 }
220             }
221         } catch (DataAccessException e) {
222             throw new PopulateException(e.getLocalizedMessage(),e);
223         } catch (InvalidPropertyValueException e) {
224             throw new PopulateException(e.getLocalizedMessage(),e);
225         }
226         
227         super.markAsNew();
228     }
229   
230   /**
231    * Returns the workflow property instance sPropName from the profiled object profObj
232    * if the object has that workflow property instance. otherwise, it returns null.
233    * @param profObj The Profiled object
234    * @param sPropName The name of the property instance to be returned
235    * @return A WorkflowPropertyInstance if the object has it, or null otherwise.
236    * @throws InvalidPropertyInstanceException
237    * @throws DataAccessException
238    */

239   public static WorkflowPropertyInstance getWorkflowPropertyInstance(AbstractProfiledObject profObj, String JavaDoc sPropName) throws InvalidPropertyInstanceException, DataAccessException {
240     WorkflowProfile workflowProf = (WorkflowProfile) profObj.getProfile(WORKFLOW_PROFILE_NAME);
241     return (WorkflowPropertyInstance) workflowProf.getPropertyInstance(sPropName);
242   }
243 }
244
Popular Tags