KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > metadata > properties > PropertyGroup


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.metadata.properties;
20
21 import java.util.*;
22
23 import org.openharmonise.commons.dsi.*;
24 import org.openharmonise.commons.dsi.dml.JoinConditions;
25 import org.openharmonise.rm.DataAccessException;
26 import org.openharmonise.rm.dsi.*;
27 import org.openharmonise.rm.publishing.Publishable;
28 import org.openharmonise.rm.resources.*;
29 import org.openharmonise.rm.resources.lifecycle.Editable;
30
31
32 /**
33  * A <code>PropertyGroup</code> represents a branch node of a property hierarchy,
34  * that is an object that can be a parent to both other <code>PropertyGroup</code>s
35  * and <code>Property</code>s.
36  *
37  * @author Michael Bell
38  * @version $Revision: 1.2 $
39  *
40  */

41 public class PropertyGroup
42     extends AbstractParentObject
43     implements Editable, DataStoreObject, Publishable, Cloneable JavaDoc {
44
45     /**
46      * The <code>String</code> constant for the type field.
47      */

48     protected static String JavaDoc TYPE_PROPERTYGROUP = PropertyGroup.class.getName();
49     /**
50      * List of allowable child class names
51      */

52     private static List CHILD_CLASS_NAMES = null;
53
54     //XML constants
55
/**
56      * The property group XML element name
57      */

58     public static final String JavaDoc TAG_PROPERTYGROUP = "PropertyGroup";
59
60     //DB constants
61
/**
62      * The property group database table name
63      */

64     private static final String JavaDoc TBL_PROPERTYGROUP = "prop_group";
65
66     //static initialiser block
67
static {
68         CHILD_CLASS_NAMES = new Vector();
69         CHILD_CLASS_NAMES.add(Property.class.getName());
70         CHILD_CLASS_NAMES.add(PropertyGroup.class.getName());
71
72         DatabaseInfo.getInstance().registerTableName(
73             PropertyGroup.class.getName(),
74             TBL_PROPERTYGROUP);
75
76     }
77
78     /**
79      * Constructs a new <code>PropertyGroup</code>.
80      *
81      */

82     public PropertyGroup() {
83         super();
84     }
85
86     /**
87      * Constructs a new <code>PropertyGroup</code> with an interface to the data
88      * store.
89      *
90      * @param dbinterf the data store interface
91      */

92     public PropertyGroup(AbstractDataStoreInterface dbinterf) {
93         super(dbinterf);
94
95     }
96
97     /**
98      * Constructs a new <code>PropertyGroup</code> which may be historical with an
99      * interface to the data store.
100      *
101      * @param dbinterf the data store interface
102      * @param bHist <code>true</code> if the <code>PropertyGroup</code> is to be
103      * a historical version
104      */

105     public PropertyGroup(AbstractDataStoreInterface dbinterf, boolean bHist) {
106         super(dbinterf);
107         setHistorical(bHist);
108     }
109
110     /**
111      * Constructs an existing <code>PropertyGroup</code> with the specified id.
112      *
113      * @param dbinterf the data store interface
114      * @param nId the id of the <code>PropertyGroup</code>
115      */

116     public PropertyGroup(AbstractDataStoreInterface dbinterf, int nId) {
117         super(dbinterf, nId);
118
119     }
120
121     /**
122      * Constructs an existing <code>PropertyGroup</code> which may be historical.
123      *
124      * @param dbinterf the data store interface
125      * @param nId the id of the <code>PropertyGroup</code>
126      * @param nKey the unique key for the version of the <code>PropertyGroup</code>
127      * @param bHist <code>true</code> if the <code>PropertyGroup</code> is to be
128      * a historical version
129      */

130     public PropertyGroup(
131         AbstractDataStoreInterface dbinterf,
132         int nId,
133         int nKey,
134         boolean bHist) {
135         super(dbinterf, nId, nKey, bHist);
136
137     }
138
139     /**
140     * Returns a list of all the top level, 'root', property groups.
141     *
142     * @param dbinterf the data store interface
143     * @return a list of all the top level, 'root', property groups
144     * @throws DataAccessException if there is any errors building the
145     * list of objects
146     */

147     public static List getTopLevelGroups(AbstractDataStoreInterface dbinterf)
148         throws DataAccessException {
149         return AbstractParentObject.getTopLevelGroups(
150             dbinterf,
151             new PropertyGroup());
152     }
153
154     /* (non-Javadoc)
155      * @see org.openharmonise.rm.resources.AbstractParentObject#getChildClassNames()
156      */

157     public List getChildClassNames() {
158         return CHILD_CLASS_NAMES;
159     }
160
161     /* (non-Javadoc)
162      * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
163      */

164     public String JavaDoc getParentObjectClassName() {
165         return getClass().getName();
166     }
167
168     /* (non-Javadoc)
169      * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
170      */

171     public String JavaDoc getDBTableName() {
172         return TBL_PROPERTYGROUP;
173     }
174
175     /* (non-Javadoc)
176      * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
177      */

178     public JoinConditions getInstanceJoinConditions(
179         String JavaDoc sObjectTag,
180         boolean bIsOuter)
181         throws DataStoreException {
182         JoinConditions joinConditions = new JoinConditions();
183         DatabaseInfo dbInfo = DatabaseInfo.getInstance();
184         String JavaDoc sChildTableName = null;
185         String JavaDoc sClassName = null;
186
187         if (sObjectTag.equals("Property") == true) {
188             sChildTableName = dbInfo.getTableName(Property.class.getName());
189             sClassName = Property.class.getName();
190         } else if (sObjectTag.equals("PropertyGroup") == true) {
191             sChildTableName =
192                 dbInfo.getTableName(PropertyGroup.class.getName());
193             sClassName = PropertyGroup.class.getName();
194         } else {
195             throw new DataStoreException("Invalid child object");
196         }
197
198         // get the child and parent keys from the join table
199
ColumnRef childKeyCol =
200             getGroupChildJoinColumnRef(sChildTableName, CLMN_CHILD_KEY);
201         ColumnRef parentKeyCol =
202             getGroupChildJoinColumnRef(sChildTableName, CLMN_PARENT_KEY);
203
204         joinConditions.addCondition(
205             getInstanceColumnRef(AbstractObject.ATTRIB_KEY, false),
206             parentKeyCol);
207
208         if (sObjectTag.equals("Property") == true) {
209             joinConditions.addCondition(
210                 Property.getColumnRef(
211                     sClassName,
212                     AbstractObject.ATTRIB_KEY,
213                     false),
214                 childKeyCol);
215         } else if (sObjectTag.equals("PropertyGroup") == true) {
216             joinConditions.addCondition(
217                 PropertyGroup.getColumnRef(
218                     sClassName,
219                     AbstractObject.ATTRIB_KEY,
220                     false),
221                 childKeyCol);
222         }
223
224         return joinConditions;
225     }
226
227     /* (non-Javadoc)
228      * @see org.openharmonise.rm.publishing.Publishable#getTagName()
229      */

230     public String JavaDoc getTagName() {
231
232         return TAG_PROPERTYGROUP;
233     }
234
235 }
Popular Tags