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.values;
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>ValueGroup</code> represents a branch node of a property hierarchy,
033: * that is an object that can be a parent to both other <code>ValueGroup</code>s
034: * and <code>Value</code>s.
035: *
036: * @author Michael Bell
037: * @version $Revision: 1.2 $
038: *
039: */
040: public class ValueGroup extends AbstractParentObject implements
041: DataStoreObject, Editable, Publishable {
042:
043: /**
044: * The <code>String</code> constant for the type field
045: */
046: protected static String TYPE_VALUEGROUP = ValueGroup.class
047: .getName();
048:
049: /**
050: * List of allowable child class names
051: */
052: private static List CHILD_CLASS_NAMES = null;
053:
054: //XML constants
055: /**
056: * The value group XML element name
057: */
058: public static final String TAG_VALUEGROUP = "ValueGroup";
059:
060: //DB constants
061: /**
062: * The value group database table name
063: */
064: private static final String TBL_VALUEGROUP = "value_group";
065:
066: //static initiaiser block
067: static {
068: CHILD_CLASS_NAMES = new Vector();
069: CHILD_CLASS_NAMES.add(Value.class.getName());
070: CHILD_CLASS_NAMES.add(ValueGroup.class.getName());
071:
072: DatabaseInfo.getInstance().registerTableName(
073: ValueGroup.class.getName(), TBL_VALUEGROUP);
074:
075: }
076:
077: /**
078: * Constructs a new <code>ValueGroup</code>.
079: *
080: */
081: public ValueGroup() {
082: super ();
083:
084: }
085:
086: /**
087: * Constructs a new <code>ValueGroup</code> with a data store interface.
088: *
089: * @param dbintrf the data store interface
090: */
091: public ValueGroup(AbstractDataStoreInterface dbintrf) {
092: super (dbintrf);
093:
094: }
095:
096: /**
097: * Constructs an existing <code>ValueGroup</code> identified by its id.
098: *
099: * @param dbintrf the data store interface
100: * @param nId the id of this object
101: */
102: public ValueGroup(AbstractDataStoreInterface dbintrf, int nId) {
103: super (dbintrf, nId);
104:
105: }
106:
107: /**
108: * Constructs an existing <code>ValueGroup</code> which may be historical.
109: *
110: * @param dbintrf the data store interface
111: * @param nId the id of this object
112: * @param nKey the unique key of the resource
113: * @param bIsHist <code>true</code> if the version of the <code>Value</code>
114: * is historical
115: */
116: public ValueGroup(AbstractDataStoreInterface dbintrf, int nId,
117: int nKey, boolean bIsHist) {
118: super (dbintrf, nId, nKey, bIsHist);
119:
120: }
121:
122: /**
123: * Constructs a new <code>ValueGroup</code> which may be historical.
124: *
125: * @param dbintrf the data store interface
126: * @param bIsHist <code>true</code> if the version of the <code>Value</code>
127: * is historical
128: */
129: public ValueGroup(AbstractDataStoreInterface dbintrf,
130: boolean bIsHist) {
131: super (dbintrf);
132:
133: }
134:
135: /**
136: * Returns a list of all the top level, 'root', value groups.
137: *
138: * @param dbinterf the data store interface
139: * @return a list of all the top level, 'root', value groups
140: * @throws 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 ValueGroup());
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_VALUEGROUP;
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("Value") == true) {
182: sChildTableName = dbInfo
183: .getTableName(Value.class.getName());
184: sClassName = Value.class.getName();
185: } else if (sObjectTag.equals("ValueGroup") == true) {
186: sChildTableName = dbInfo.getTableName(ValueGroup.class
187: .getName());
188: sClassName = ValueGroup.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("Value") == true) {
203: joinConditions.addCondition(Value.getColumnRef(Value.class
204: .getName(), AbstractObject.ATTRIB_KEY, false),
205: childKeyCol);
206: } else if (sObjectTag.equals("ValueGroup") == true) {
207: joinConditions.addCondition(getColumnRef(Value.class
208: .getName(), 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: return TAG_VALUEGROUP;
220: }
221:
222: }
|