KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > metadata > values > ValueGroup


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.values;
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>ValueGroup</code> represents a branch node of a property hierarchy,
34  * that is an object that can be a parent to both other <code>ValueGroup</code>s
35  * and <code>Value</code>s.
36  *
37  * @author Michael Bell
38  * @version $Revision: 1.2 $
39  *
40  */

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

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

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

59     public static final String JavaDoc TAG_VALUEGROUP = "ValueGroup";
60
61     //DB constants
62
/**
63      * The value group database table name
64      */

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

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

93     public ValueGroup(AbstractDataStoreInterface dbintrf) {
94         super(dbintrf);
95
96     }
97
98     /**
99      * Constructs an existing <code>ValueGroup</code> identified by its id.
100      *
101      * @param dbintrf the data store interface
102      * @param nId the id of this object
103      */

104     public ValueGroup(AbstractDataStoreInterface dbintrf, int nId) {
105         super(dbintrf, nId);
106
107     }
108
109     /**
110      * Constructs an existing <code>ValueGroup</code> which may be historical.
111      *
112      * @param dbintrf the data store interface
113      * @param nId the id of this object
114      * @param nKey the unique key of the resource
115      * @param bIsHist <code>true</code> if the version of the <code>Value</code>
116      * is historical
117      */

118     public ValueGroup(
119         AbstractDataStoreInterface dbintrf,
120         int nId,
121         int nKey,
122         boolean bIsHist) {
123         super(dbintrf, nId, nKey, bIsHist);
124
125     }
126
127     /**
128      * Constructs a new <code>ValueGroup</code> which may be historical.
129      *
130      * @param dbintrf the data store interface
131      * @param bIsHist <code>true</code> if the version of the <code>Value</code>
132      * is historical
133      */

134     public ValueGroup(AbstractDataStoreInterface dbintrf, boolean bIsHist) {
135         super(dbintrf);
136
137     }
138
139     /**
140      * Returns a list of all the top level, 'root', value groups.
141      *
142      * @param dbinterf the data store interface
143      * @return a list of all the top level, 'root', value groups
144      * @throws 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 ValueGroup());
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_VALUEGROUP;
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("Value") == true) {
188             sChildTableName = dbInfo.getTableName(Value.class.getName());
189             sClassName = Value.class.getName();
190         } else if (sObjectTag.equals("ValueGroup") == true) {
191             sChildTableName = dbInfo.getTableName(ValueGroup.class.getName());
192             sClassName = ValueGroup.class.getName();
193         } else {
194             throw new DataStoreException("Invalid child object");
195         }
196
197         // get the child and parent keys from the join table
198
ColumnRef childKeyCol =
199             getGroupChildJoinColumnRef(sChildTableName, CLMN_CHILD_KEY);
200         ColumnRef parentKeyCol =
201             getGroupChildJoinColumnRef(sChildTableName, CLMN_PARENT_KEY);
202
203         joinConditions.addCondition(
204             getInstanceColumnRef(AbstractObject.ATTRIB_KEY, false),
205             parentKeyCol);
206
207         if (sObjectTag.equals("Value") == true) {
208             joinConditions.addCondition(
209                 Value.getColumnRef(
210                     Value.class.getName(),
211                     AbstractObject.ATTRIB_KEY,
212                     false),
213                 childKeyCol);
214         } else if (sObjectTag.equals("ValueGroup") == true) {
215             joinConditions.addCondition(
216                 getColumnRef(
217                     Value.class.getName(),
218                     AbstractObject.ATTRIB_KEY,
219                     false),
220                 childKeyCol);
221         }
222
223         return joinConditions;
224     }
225
226     /* (non-Javadoc)
227      * @see org.openharmonise.rm.publishing.Publishable#getTagName()
228      */

229     public String JavaDoc getTagName() {
230         return TAG_VALUEGROUP;
231     }
232
233 }
Popular Tags