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.xml;
020:
021: import java.util.*;
022:
023: import org.openharmonise.commons.dsi.*;
024: import org.openharmonise.commons.dsi.dml.*;
025: import org.openharmonise.rm.dsi.*;
026: import org.openharmonise.rm.resources.*;
027:
028: /**
029: * Parent object to allow hierarchies of <code>XMLResource</code> objects.
030: *
031: * @author Michael Bell
032: * @version $Revision: 1.2 $
033: *
034: */
035: public class XMLResourceGroup extends AbstractParentObject {
036:
037: // DB constants
038: private static final String TBL_XML_GROUP = "xml_group";
039:
040: //XML constants
041: public static final String TAG_XML_GROUP = "XMLGroup";
042:
043: //member variables
044: private static List CHILD_CLASS_NAMES = null;
045:
046: static {
047: DatabaseInfo.getInstance().registerTableName(
048: XMLResourceGroup.class.getName(), TBL_XML_GROUP);
049:
050: try {
051: CHILD_CLASS_NAMES = new Vector();
052: CHILD_CLASS_NAMES.add(XMLResourceGroup.class.getName());
053: CHILD_CLASS_NAMES.add(XMLResource.class.getName());
054:
055: } catch (Exception e) {
056: throw new RuntimeException(e.getMessage());
057: }
058: }
059:
060: /**
061: * Basic constructor.
062: */
063: public XMLResourceGroup() {
064: super ();
065: }
066:
067: /**
068: * Constructor for an empty resource with an interface to the DB.
069: *
070: * @param dbintrf
071: */
072: public XMLResourceGroup(AbstractDataStoreInterface dbintrf) {
073: super (dbintrf);
074: }
075:
076: /**
077: * Constructor for a known historical object.
078: *
079: * @param dbintrf
080: * @param nId
081: * @param bIsHist
082: */
083: public XMLResourceGroup(AbstractDataStoreInterface dbintrf,
084: int nId, int nKey, boolean bIsHist) {
085: super (dbintrf, nId, nKey, bIsHist);
086: }
087:
088: /**
089: * Constructor for a known xml resource.
090: *
091: * @param dbintrf
092: * @param nId
093: */
094: public XMLResourceGroup(AbstractDataStoreInterface dbintrf, int nId) {
095: super (dbintrf, nId);
096: }
097:
098: /* (non-Javadoc)
099: * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
100: */
101: public String getParentObjectClassName() {
102: return getClass().getName();
103: }
104:
105: /* (non-Javadoc)
106: * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
107: */
108: public String getDBTableName() {
109: return TBL_XML_GROUP;
110: }
111:
112: /* (non-Javadoc)
113: * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
114: */
115: public JoinConditions getInstanceJoinConditions(String sObjectTag,
116: boolean bIsOuter) throws DataStoreException {
117: JoinConditions joinConditions = new JoinConditions();
118: DatabaseInfo dbInfo = DatabaseInfo.getInstance();
119: String sChildTableName = null;
120: String sClassName = null;
121:
122: if (sObjectTag.equals("XMLResource") == true) {
123: sChildTableName = dbInfo.getTableName(XMLResource.class
124: .getName());
125: sClassName = XMLResource.class.getName();
126: } else if (sObjectTag.equals("XMLResourceGroup") == true) {
127: sChildTableName = dbInfo
128: .getTableName(XMLResourceGroup.class.getName());
129: sClassName = XMLResourceGroup.class.getName();
130: } else {
131: throw new DataStoreException("Invalid child object.");
132: }
133:
134: // get the child and parent keys from the join table
135: ColumnRef childKeyCol = getGroupChildJoinColumnRef(
136: sChildTableName, CLMN_CHILD_KEY);
137: ColumnRef parentKeyCol = getGroupChildJoinColumnRef(
138: sChildTableName, CLMN_PARENT_KEY);
139:
140: joinConditions.addCondition(getInstanceColumnRef(
141: AbstractObject.ATTRIB_KEY, false), parentKeyCol);
142: if (sObjectTag.equals("XMLResource") == true) {
143: joinConditions.addCondition(XMLResource.getColumnRef(
144: sClassName, AbstractObject.ATTRIB_KEY, false),
145: childKeyCol);
146: } else if (sObjectTag.equals("XMLResourceGroup") == true) {
147: joinConditions.addCondition(getColumnRef(sClassName,
148: AbstractObject.ATTRIB_KEY, false), childKeyCol);
149: }
150:
151: return joinConditions;
152: }
153:
154: /* (non-Javadoc)
155: * @see org.openharmonise.rm.publishing.Publishable#getTagName()
156: */
157: public String getTagName() {
158:
159: return TAG_XML_GROUP;
160: }
161:
162: /*----------------------------------------------------------------------------
163: Protected methods
164: -----------------------------------------------------------------------------*/
165:
166: /* (non-Javadoc)
167: * @see org.openharmonise.rm.resources.AbstractParentObject#getChildClassNames()
168: */
169: public List getChildClassNames() {
170: return CHILD_CLASS_NAMES;
171: }
172:
173: }
|