KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > xml > XMLResourceGroup


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.xml;
20
21 import java.util.*;
22
23 import org.openharmonise.commons.dsi.*;
24 import org.openharmonise.commons.dsi.dml.*;
25 import org.openharmonise.rm.dsi.*;
26 import org.openharmonise.rm.resources.*;
27
28
29 /**
30  * Parent object to allow hierarchies of <code>XMLResource</code> objects.
31  *
32  * @author Michael Bell
33  * @version $Revision: 1.2 $
34  *
35  */

36 public class XMLResourceGroup extends AbstractParentObject {
37
38     // DB constants
39
private static final String JavaDoc TBL_XML_GROUP = "xml_group";
40
41     //XML constants
42
public static final String JavaDoc TAG_XML_GROUP = "XMLGroup";
43
44     //member variables
45
private static List CHILD_CLASS_NAMES = null;
46
47     static {
48         DatabaseInfo.getInstance().registerTableName(
49                 XMLResourceGroup.class.getName(), TBL_XML_GROUP);
50
51         try {
52             CHILD_CLASS_NAMES = new Vector();
53             CHILD_CLASS_NAMES.add(XMLResourceGroup.class.getName());
54             CHILD_CLASS_NAMES.add(XMLResource.class.getName());
55
56         } catch (Exception JavaDoc e) {
57             throw new RuntimeException JavaDoc(e.getMessage());
58         }
59     }
60
61     /**
62      * Basic constructor.
63      */

64     public XMLResourceGroup() {
65         super();
66     }
67
68     /**
69      * Constructor for an empty resource with an interface to the DB.
70      *
71      * @param dbintrf
72      */

73     public XMLResourceGroup(AbstractDataStoreInterface dbintrf) {
74         super(dbintrf);
75     }
76
77     /**
78      * Constructor for a known historical object.
79      *
80      * @param dbintrf
81      * @param nId
82      * @param bIsHist
83      */

84     public XMLResourceGroup(AbstractDataStoreInterface dbintrf, int nId,
85             int nKey, boolean bIsHist) {
86         super(dbintrf, nId, nKey, bIsHist);
87     }
88
89     /**
90      * Constructor for a known xml resource.
91      *
92      * @param dbintrf
93      * @param nId
94      */

95     public XMLResourceGroup(AbstractDataStoreInterface dbintrf, int nId) {
96         super(dbintrf, nId);
97     }
98
99     /* (non-Javadoc)
100      * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
101      */

102     public String JavaDoc getParentObjectClassName() {
103         return getClass().getName();
104     }
105
106     /* (non-Javadoc)
107      * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
108      */

109     public String JavaDoc getDBTableName() {
110         return TBL_XML_GROUP;
111     }
112
113     /* (non-Javadoc)
114      * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
115      */

116     public JoinConditions getInstanceJoinConditions(String JavaDoc sObjectTag,
117             boolean bIsOuter) throws DataStoreException {
118         JoinConditions joinConditions = new JoinConditions();
119         DatabaseInfo dbInfo = DatabaseInfo.getInstance();
120         String JavaDoc sChildTableName = null;
121         String JavaDoc sClassName = null;
122
123         if (sObjectTag.equals("XMLResource") == true) {
124             sChildTableName = dbInfo.getTableName(XMLResource.class.getName());
125             sClassName = XMLResource.class.getName();
126         } else if (sObjectTag.equals("XMLResourceGroup") == true) {
127             sChildTableName = dbInfo.getTableName(XMLResourceGroup.class
128                     .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(sChildTableName,
136                 CLMN_CHILD_KEY);
137         ColumnRef parentKeyCol = getGroupChildJoinColumnRef(sChildTableName,
138                 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(sClassName,
144                     AbstractObject.ATTRIB_KEY, false), childKeyCol);
145         } else if (sObjectTag.equals("XMLResourceGroup") == true) {
146             joinConditions.addCondition(getColumnRef(sClassName,
147                     AbstractObject.ATTRIB_KEY, false), childKeyCol);
148         }
149
150         return joinConditions;
151     }
152
153     /* (non-Javadoc)
154      * @see org.openharmonise.rm.publishing.Publishable#getTagName()
155      */

156     public String JavaDoc getTagName() {
157
158         return TAG_XML_GROUP;
159     }
160
161     /*----------------------------------------------------------------------------
162      Protected methods
163      -----------------------------------------------------------------------------*/

164
165     /* (non-Javadoc)
166      * @see org.openharmonise.rm.resources.AbstractParentObject#getChildClassNames()
167      */

168     public List getChildClassNames() {
169         return CHILD_CLASS_NAMES;
170     }
171
172 }
Popular Tags