001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.resources.metadata.properties;
020:
021: import java.util.*;
022:
023: import org.openharmonise.commons.dsi.*;
024: import org.openharmonise.commons.dsi.dml.JoinConditions;
025: import org.openharmonise.rm.DataAccessException;
026: import org.openharmonise.rm.dsi.*;
027: import org.openharmonise.rm.publishing.Publishable;
028: import org.openharmonise.rm.resources.*;
029: import org.openharmonise.rm.resources.lifecycle.Editable;
030:
031: /**
032: * A <code>PropertyGroup</code> represents a branch node of a property hierarchy,
033: * that is an object that can be a parent to both other <code>PropertyGroup</code>s
034: * and <code>Property</code>s.
035: *
036: * @author Michael Bell
037: * @version $Revision: 1.2 $
038: *
039: */
040: public class PropertyGroup extends AbstractParentObject implements
041: Editable, DataStoreObject, Publishable, Cloneable {
042:
043: /**
044: * The <code>String</code> constant for the type field.
045: */
046: protected static String TYPE_PROPERTYGROUP = PropertyGroup.class
047: .getName();
048: /**
049: * List of allowable child class names
050: */
051: private static List CHILD_CLASS_NAMES = null;
052:
053: //XML constants
054: /**
055: * The property group XML element name
056: */
057: public static final String TAG_PROPERTYGROUP = "PropertyGroup";
058:
059: //DB constants
060: /**
061: * The property group database table name
062: */
063: private static final String TBL_PROPERTYGROUP = "prop_group";
064:
065: //static initialiser block
066: static {
067: CHILD_CLASS_NAMES = new Vector();
068: CHILD_CLASS_NAMES.add(Property.class.getName());
069: CHILD_CLASS_NAMES.add(PropertyGroup.class.getName());
070:
071: DatabaseInfo.getInstance().registerTableName(
072: PropertyGroup.class.getName(), TBL_PROPERTYGROUP);
073:
074: }
075:
076: /**
077: * Constructs a new <code>PropertyGroup</code>.
078: *
079: */
080: public PropertyGroup() {
081: super ();
082: }
083:
084: /**
085: * Constructs a new <code>PropertyGroup</code> with an interface to the data
086: * store.
087: *
088: * @param dbinterf the data store interface
089: */
090: public PropertyGroup(AbstractDataStoreInterface dbinterf) {
091: super (dbinterf);
092:
093: }
094:
095: /**
096: * Constructs a new <code>PropertyGroup</code> which may be historical with an
097: * interface to the data store.
098: *
099: * @param dbinterf the data store interface
100: * @param bHist <code>true</code> if the <code>PropertyGroup</code> is to be
101: * a historical version
102: */
103: public PropertyGroup(AbstractDataStoreInterface dbinterf,
104: boolean bHist) {
105: super (dbinterf);
106: setHistorical(bHist);
107: }
108:
109: /**
110: * Constructs an existing <code>PropertyGroup</code> with the specified id.
111: *
112: * @param dbinterf the data store interface
113: * @param nId the id of the <code>PropertyGroup</code>
114: */
115: public PropertyGroup(AbstractDataStoreInterface dbinterf, int nId) {
116: super (dbinterf, nId);
117:
118: }
119:
120: /**
121: * Constructs an existing <code>PropertyGroup</code> which may be historical.
122: *
123: * @param dbinterf the data store interface
124: * @param nId the id of the <code>PropertyGroup</code>
125: * @param nKey the unique key for the version of the <code>PropertyGroup</code>
126: * @param bHist <code>true</code> if the <code>PropertyGroup</code> is to be
127: * a historical version
128: */
129: public PropertyGroup(AbstractDataStoreInterface dbinterf, int nId,
130: int nKey, boolean bHist) {
131: super (dbinterf, nId, nKey, bHist);
132:
133: }
134:
135: /**
136: * Returns a list of all the top level, 'root', property groups.
137: *
138: * @param dbinterf the data store interface
139: * @return a list of all the top level, 'root', property groups
140: * @throws DataAccessException if there is any errors building the
141: * list of objects
142: */
143: public static List getTopLevelGroups(
144: AbstractDataStoreInterface dbinterf)
145: throws DataAccessException {
146: return AbstractParentObject.getTopLevelGroups(dbinterf,
147: new PropertyGroup());
148: }
149:
150: /* (non-Javadoc)
151: * @see org.openharmonise.rm.resources.AbstractParentObject#getChildClassNames()
152: */
153: public List getChildClassNames() {
154: return CHILD_CLASS_NAMES;
155: }
156:
157: /* (non-Javadoc)
158: * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
159: */
160: public String getParentObjectClassName() {
161: return getClass().getName();
162: }
163:
164: /* (non-Javadoc)
165: * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
166: */
167: public String getDBTableName() {
168: return TBL_PROPERTYGROUP;
169: }
170:
171: /* (non-Javadoc)
172: * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
173: */
174: public JoinConditions getInstanceJoinConditions(String sObjectTag,
175: boolean bIsOuter) throws DataStoreException {
176: JoinConditions joinConditions = new JoinConditions();
177: DatabaseInfo dbInfo = DatabaseInfo.getInstance();
178: String sChildTableName = null;
179: String sClassName = null;
180:
181: if (sObjectTag.equals("Property") == true) {
182: sChildTableName = dbInfo.getTableName(Property.class
183: .getName());
184: sClassName = Property.class.getName();
185: } else if (sObjectTag.equals("PropertyGroup") == true) {
186: sChildTableName = dbInfo.getTableName(PropertyGroup.class
187: .getName());
188: sClassName = PropertyGroup.class.getName();
189: } else {
190: throw new DataStoreException("Invalid child object");
191: }
192:
193: // get the child and parent keys from the join table
194: ColumnRef childKeyCol = getGroupChildJoinColumnRef(
195: sChildTableName, CLMN_CHILD_KEY);
196: ColumnRef parentKeyCol = getGroupChildJoinColumnRef(
197: sChildTableName, CLMN_PARENT_KEY);
198:
199: joinConditions.addCondition(getInstanceColumnRef(
200: AbstractObject.ATTRIB_KEY, false), parentKeyCol);
201:
202: if (sObjectTag.equals("Property") == true) {
203: joinConditions.addCondition(Property.getColumnRef(
204: sClassName, AbstractObject.ATTRIB_KEY, false),
205: childKeyCol);
206: } else if (sObjectTag.equals("PropertyGroup") == true) {
207: joinConditions.addCondition(PropertyGroup.getColumnRef(
208: sClassName, AbstractObject.ATTRIB_KEY, false),
209: childKeyCol);
210: }
211:
212: return joinConditions;
213: }
214:
215: /* (non-Javadoc)
216: * @see org.openharmonise.rm.publishing.Publishable#getTagName()
217: */
218: public String getTagName() {
219:
220: return TAG_PROPERTYGROUP;
221: }
222:
223: }
|