KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > workflow > properties > domains > WorkflowPropertyDomain


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.resources.workflow.properties.domains;
20
21 import java.sql.*;
22 import java.util.*;
23
24 import org.openharmonise.commons.dsi.*;
25 import org.openharmonise.commons.dsi.dml.*;
26 import org.openharmonise.commons.dsi.dml.functions.*;
27 import org.openharmonise.rm.DataAccessException;
28 import org.openharmonise.rm.resources.*;
29 import org.openharmonise.rm.resources.metadata.properties.Property;
30 import org.openharmonise.rm.resources.metadata.properties.domains.Domain;
31 import org.openharmonise.rm.resources.workflow.properties.WorkflowProperty;
32
33
34 /**
35  * Represents a domain which applies specifically to a <code>WorkflowProperty</code>.
36  *
37  * @author Michael Bell
38  * @version $Revision: 1.2 $
39  *
40  */

41 public class WorkflowPropertyDomain extends Domain {
42
43     public static boolean validate(WorkflowProperty prop, Domain domain) throws DataAccessException {
44         boolean bIsValid = true;
45         
46         List domainDetails = domain.getDetails();
47         
48         if(domainDetails.size() > 0) {
49         
50             ResultSet rs = null;
51             try {
52                 SelectStatement select = new SelectStatement();
53                 
54                 select.addSelectColumn(Domain.getColumnRef(CLMN_DOMAIN_ID, false));
55                 select.addWhereCondition(prop.getInstanceColumnRef(Property.ATTRIB_TYPE,false), "=", WorkflowProperty.class.getName());
56                 select.addJoinCondition(prop.getInstanceColumnRef(AbstractObject.ATTRIB_KEY, false), Domain.getColumnRef(CLMN_PROPERTY_KEY, false));
57                 
58                 ColumnRef domainDetailsCol = Domain.getDetailsColumnRef(CLMN_DOMAIN_DETAILS,false);
59                 if(domainDetails.size() > 1) {
60                     WhereConditionGroup wheres = new WhereConditionGroup();
61                     for (Iterator iter = domainDetails.iterator(); iter
62                             .hasNext();) {
63                         String JavaDoc detail = (String JavaDoc) iter.next();
64                         wheres.addCondition(domainDetailsCol, "STARTS_WITH", detail);
65                         Substring substr = new Substring(detail,new Integer JavaDoc(1),new Length(domainDetailsCol));
66                         wheres.addCondition(domainDetailsCol, "=", substr);
67                     }
68                     wheres.setStringingOperator("or");
69                     select.addWhereCondition(wheres);
70                 } else {
71                     WhereConditionGroup wheres = new WhereConditionGroup();
72                     
73                     Substring substr = new Substring((String JavaDoc)domainDetails.get(0),new Integer JavaDoc(1),new Length(domainDetailsCol));
74                     
75                     wheres.addCondition(domainDetailsCol, "=", substr);
76                     wheres.addCondition(domainDetailsCol, "STARTS_WITH", domainDetails.get(0));
77                 
78                     wheres.setStringingOperator("or");
79                     select.addWhereCondition(wheres);
80                 }
81                 
82                 select.addJoinCondition(Domain.getColumnRef(CLMN_DOMAIN_ID, false), Domain.getDetailsColumnRef(CLMN_DETAILS_DOMAIN_ID, false));
83                 select.addWhereCondition(Domain.getColumnRef(CLMN_DOMAIN_OBJECT, false), "=", domain.getDomainClass());
84                 
85                 if(prop.getKey() != Property.NOTDBSAVED_KEY) {
86                     Property liveVer = (Property) prop.getLiveVersion();
87                     if(liveVer != null) {
88                         select.addWhereCondition(prop.getInstanceColumnRef(AbstractObject.ATTRIB_ID, false), "!=", liveVer.getId());
89                         select.addWhereCondition(prop.getInstanceColumnRef(AbstractEditableObject.TAG_LIVE_VERSION, false), "!=", liveVer.getId());
90                         
91                     } else {
92                         select.addWhereCondition(prop.getInstanceColumnRef(AbstractObject.ATTRIB_ID, false), "!=", prop.getId());
93                         
94                     }
95                 }
96                 rs = prop.getDataStoreInterface().execute(select);
97                 
98                 if(rs.next()) {
99                     bIsValid = false;
100                 }
101             } catch (DataStoreException e) {
102                 throw new DataAccessException(e);
103             } catch (SQLException e) {
104                 throw new DataAccessException(e);
105             } finally {
106                 if(rs != null) {
107                     try {
108                         rs.close();
109                     } catch (SQLException e) {
110                         throw new DataAccessException(e);
111                     }
112                 }
113             }
114         }
115         
116         return bIsValid;
117     }
118
119 }
120
Popular Tags