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.content;
020:
021: import java.util.*;
022: import java.util.logging.*;
023:
024: import org.openharmonise.commons.dsi.*;
025: import org.openharmonise.commons.dsi.dml.JoinConditions;
026: import org.openharmonise.rm.DataAccessException;
027: import org.openharmonise.rm.dsi.*;
028: import org.openharmonise.rm.metadata.Profile;
029: import org.openharmonise.rm.publishing.Publishable;
030: import org.openharmonise.rm.resources.*;
031: import org.openharmonise.rm.resources.lifecycle.Editable;
032:
033: /**
034: * Parent object to allow hierarchies of <code>Document</code> and
035: * <code>Asset</code> objects.
036: *
037: * @author Michael Bell
038: * @version $Revision: 1.3 $
039: *
040: */
041: public class Section extends AbstractParentObject implements
042: DataStoreObject, Publishable, Editable, Cloneable, Comparable {
043:
044: //DB constants
045: /**
046: * The <code>Section</code> database table name
047: */
048: private static final String TBL_SECTION = "section";
049:
050: //XML constants
051: /**
052: * The <code>Section</code> XML tag name
053: */
054: public static final String TAG_SECTION = "Section";
055:
056: //member variables
057: /**
058: * List of allowable child class names
059: */
060: private static List CHILD_CLASS_NAMES = null;
061:
062: /**
063: * Logger for this class
064: */
065: private static final Logger m_logger = Logger
066: .getLogger(Section.class.getName());
067:
068: //static initialiser block
069: static {
070: DatabaseInfo.getInstance().registerTableName(
071: Section.class.getName(), TBL_SECTION);
072:
073: try {
074: CHILD_CLASS_NAMES = new Vector();
075: CHILD_CLASS_NAMES.add(Document.class.getName());
076: CHILD_CLASS_NAMES.add(Asset.class.getName());
077: CHILD_CLASS_NAMES.add(Section.class.getName());
078:
079: } catch (Exception e) {
080: throw new RuntimeException(e.getMessage());
081: }
082: }
083:
084: /**
085: * Contructs a new instance with no data store interface
086: */
087: public Section() {
088: super ();
089:
090: }
091:
092: /**
093: * Constructs a new or anonymous resource.
094: *
095: * @param dbintrf the data store to register
096: */
097: public Section(AbstractDataStoreInterface dbintrf) {
098: super (dbintrf);
099:
100: }
101:
102: /**
103: * Constructs a known resource.
104: *
105: * @param dbintrf the data store to register
106: * @param nId the id of this resource
107: */
108: public Section(AbstractDataStoreInterface dbintrf, int nId) {
109: super (dbintrf, nId);
110:
111: }
112:
113: /**
114: * Constructs a known resource which may be historical.
115: *
116: * @param dbintrf the data store interface
117: * @param nId the resource identifier
118: * @param nKey the resource unique key
119: * @param bIsHist <code>true</code> if the version of the resoure is historical, otherwise <code>false</code>
120: */
121: public Section(AbstractDataStoreInterface dbintrf, int nId,
122: int nKey, boolean bIsHist) {
123: super (dbintrf, nId, nKey, bIsHist);
124: }
125:
126: /**
127: * Constructs a new or anonymous resource which
128: * may be historical.
129: *
130: * @param dbintrf the data store interface
131: * @param bIsHist <code>true</code> if the resoure is historical, otherwise <code>false</code>
132: */
133: public Section(AbstractDataStoreInterface dbintrf, boolean bIsHist) {
134: super (dbintrf);
135: setHistorical(bIsHist);
136: }
137:
138: /* (non-Javadoc)
139: * @see java.lang.Object#toString()
140: */
141: public String toString() {
142: StringBuffer strBuff = new StringBuffer();
143:
144: try {
145: strBuff.append("Section Title:[" + m_sName + "] ").append(
146: "Section Summary:[" + m_sSummary + "] ").append(
147: "Section ID:[" + m_nId + "] ").append(
148: "Section status:[" + getStatus().getIntValue()
149: + "] ");
150:
151: Profile prof = getProfile();
152:
153: if (prof != null) {
154: strBuff.append("Profile:" + prof.toString());
155: }
156:
157: } catch (DataAccessException e) {
158: m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
159: }
160:
161: return strBuff.toString();
162: }
163:
164: /* (non-Javadoc)
165: * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
166: */
167: public String getParentObjectClassName() {
168: return getClass().getName();
169: }
170:
171: /* (non-Javadoc)
172: * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
173: */
174: public String getDBTableName() {
175: return TBL_SECTION;
176: }
177:
178: /* (non-Javadoc)
179: * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
180: */
181: public JoinConditions getInstanceJoinConditions(String sObjectTag,
182: boolean bIsOuter) throws DataStoreException {
183: JoinConditions joinConditions = new JoinConditions();
184: DatabaseInfo dbInfo = DatabaseInfo.getInstance();
185: String sChildTableName = null;
186: String sClassName = null;
187:
188: if (sObjectTag.equals("Document") == true) {
189: sChildTableName = dbInfo.getTableName(Document.class
190: .getName());
191: sClassName = Document.class.getName();
192: } else if (sObjectTag.equals("Asset") == true) {
193: sChildTableName = dbInfo
194: .getTableName(Asset.class.getName());
195: sClassName = Asset.class.getName();
196: } else if (sObjectTag.equals("Section") == true) {
197: sChildTableName = dbInfo.getTableName(Section.class
198: .getName());
199: sClassName = Section.class.getName();
200: } else {
201: throw new DataStoreException("Invalid child object.");
202: }
203:
204: // get the child and parent keys from the join table
205: ColumnRef childKeyCol = getGroupChildJoinColumnRef(
206: sChildTableName, CLMN_CHILD_KEY);
207: ColumnRef parentKeyCol = getGroupChildJoinColumnRef(
208: sChildTableName, CLMN_PARENT_KEY);
209:
210: joinConditions.addCondition(getInstanceColumnRef(
211: AbstractObject.ATTRIB_KEY, false), parentKeyCol);
212:
213: if (sObjectTag.equals("Document") == true) {
214: joinConditions.addCondition(Document.getColumnRef(
215: sClassName, AbstractObject.ATTRIB_KEY, false),
216: childKeyCol);
217: } else if (sObjectTag.equals("Asset") == true) {
218: joinConditions.addCondition(Asset.getColumnRef(sClassName,
219: AbstractObject.ATTRIB_KEY, false), childKeyCol);
220: } else if (sObjectTag.equals("Section") == true) {
221: joinConditions.addCondition(getColumnRef(sClassName,
222: AbstractObject.ATTRIB_KEY, false), childKeyCol);
223: }
224:
225: return joinConditions;
226: }
227:
228: /* (non-Javadoc)
229: * @see org.openharmonise.rm.publishing.Publishable#getTagName()
230: */
231: public String getTagName() {
232:
233: return TAG_SECTION;
234: }
235:
236: /* (non-Javadoc)
237: * @see org.openharmonise.rm.resources.AbstractParentObject#getChildClassNames()
238: */
239: public List getChildClassNames() {
240: return CHILD_CLASS_NAMES;
241: }
242:
243: }
|