KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > content > Section


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.content;
20
21 import java.util.*;
22 import java.util.logging.*;
23
24 import org.openharmonise.commons.dsi.*;
25 import org.openharmonise.commons.dsi.dml.JoinConditions;
26 import org.openharmonise.rm.DataAccessException;
27 import org.openharmonise.rm.dsi.*;
28 import org.openharmonise.rm.metadata.Profile;
29 import org.openharmonise.rm.publishing.Publishable;
30 import org.openharmonise.rm.resources.*;
31 import org.openharmonise.rm.resources.lifecycle.Editable;
32
33
34
35
36
37 /**
38  * Parent object to allow hierarchies of <code>Document</code> and
39  * <code>Asset</code> objects.
40  *
41  * @author Michael Bell
42  * @version $Revision: 1.3 $
43  *
44  */

45 public class Section extends AbstractParentObject implements DataStoreObject,
46                                                     Publishable,
47                                                     Editable, Cloneable JavaDoc, Comparable JavaDoc {
48    
49     //DB constants
50
/**
51      * The <code>Section</code> database table name
52      */

53     private static final String JavaDoc TBL_SECTION = "section";
54     
55     //XML constants
56
/**
57      * The <code>Section</code> XML tag name
58      */

59     public static final String JavaDoc TAG_SECTION = "Section";
60     
61     //member variables
62
/**
63      * List of allowable child class names
64      */

65     private static List CHILD_CLASS_NAMES = null;
66     
67     /**
68      * Logger for this class
69      */

70     private static final Logger m_logger = Logger.getLogger(Section.class.getName());
71
72     //static initialiser block
73
static {
74         DatabaseInfo.getInstance().registerTableName(Section.class.getName(),TBL_SECTION);
75         
76         try {
77             CHILD_CLASS_NAMES = new Vector();
78             CHILD_CLASS_NAMES.add(Document.class.getName());
79             CHILD_CLASS_NAMES.add(Asset.class.getName());
80             CHILD_CLASS_NAMES.add(Section.class.getName());
81             
82         } catch (Exception JavaDoc e) {
83             throw new RuntimeException JavaDoc(e.getMessage());
84         }
85     }
86
87
88     /**
89      * Contructs a new instance with no data store interface
90      */

91     public Section() {
92         super();
93        
94     }
95
96     /**
97      * Constructs a new or anonymous resource.
98      *
99      * @param dbintrf the data store to register
100      */

101     public Section(AbstractDataStoreInterface dbintrf) {
102         super(dbintrf);
103         
104     }
105
106     /**
107      * Constructs a known resource.
108      *
109      * @param dbintrf the data store to register
110      * @param nId the id of this resource
111      */

112     public Section(AbstractDataStoreInterface dbintrf, int nId) {
113         super(dbintrf, nId);
114         
115     }
116
117     /**
118      * Constructs a known resource which may be historical.
119      *
120      * @param dbintrf the data store interface
121      * @param nId the resource identifier
122      * @param nKey the resource unique key
123      * @param bIsHist <code>true</code> if the version of the resoure is historical, otherwise <code>false</code>
124      */

125     public Section(AbstractDataStoreInterface dbintrf, int nId, int nKey, boolean bIsHist) {
126         super(dbintrf, nId, nKey, bIsHist);
127     }
128
129     /**
130      * Constructs a new or anonymous resource which
131      * may be historical.
132      *
133      * @param dbintrf the data store interface
134      * @param bIsHist <code>true</code> if the resoure is historical, otherwise <code>false</code>
135      */

136     public Section(AbstractDataStoreInterface dbintrf, boolean bIsHist) {
137         super(dbintrf);
138         setHistorical(bIsHist);
139     }
140
141     
142     /* (non-Javadoc)
143      * @see java.lang.Object#toString()
144      */

145     public String JavaDoc toString() {
146         StringBuffer JavaDoc strBuff = new StringBuffer JavaDoc();
147
148         try {
149             strBuff.append("Section Title:[" + m_sName + "] ")
150                    .append("Section Summary:[" + m_sSummary + "] ")
151                    .append("Section ID:[" + m_nId + "] ")
152                    .append("Section status:[" + getStatus().getIntValue() + "] ");
153             
154             Profile prof = getProfile();
155             
156             if(prof != null) {
157                 strBuff.append("Profile:" + prof.toString());
158             }
159             
160         } catch (DataAccessException e) {
161             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
162         }
163
164         return strBuff.toString();
165     }
166
167     /* (non-Javadoc)
168      * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
169      */

170     public String JavaDoc getParentObjectClassName() {
171         return getClass().getName();
172     }
173
174     /* (non-Javadoc)
175      * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
176      */

177     public String JavaDoc getDBTableName() {
178         return TBL_SECTION;
179     }
180
181     /* (non-Javadoc)
182      * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
183      */

184     public JoinConditions getInstanceJoinConditions(String JavaDoc sObjectTag, boolean bIsOuter) throws DataStoreException {
185         JoinConditions joinConditions = new JoinConditions();
186         DatabaseInfo dbInfo = DatabaseInfo.getInstance();
187         String JavaDoc sChildTableName = null;
188         String JavaDoc sClassName = null;
189         
190         if (sObjectTag.equals("Document") == true) {
191           sChildTableName = dbInfo.getTableName(Document.class.getName());
192           sClassName = Document.class.getName();
193         } else if (sObjectTag.equals("Asset") == true) {
194           sChildTableName = dbInfo.getTableName(Asset.class.getName());
195           sClassName = Asset.class.getName();
196         } else if (sObjectTag.equals("Section") == true) {
197           sChildTableName = dbInfo.getTableName(Section.class.getName());
198           sClassName = Section.class.getName();
199         } else {
200           throw new DataStoreException("Invalid child object.");
201         }
202         
203         // get the child and parent keys from the join table
204
ColumnRef childKeyCol = getGroupChildJoinColumnRef(sChildTableName, CLMN_CHILD_KEY);
205         ColumnRef parentKeyCol = getGroupChildJoinColumnRef(sChildTableName, CLMN_PARENT_KEY);
206     
207         joinConditions.addCondition(getInstanceColumnRef(AbstractObject.ATTRIB_KEY, false), parentKeyCol);
208         
209         if (sObjectTag.equals("Document") == true) {
210           joinConditions.addCondition(Document.getColumnRef(sClassName, AbstractObject.ATTRIB_KEY, false), childKeyCol);
211         } else if (sObjectTag.equals("Asset") == true) {
212           joinConditions.addCondition(Asset.getColumnRef(sClassName, AbstractObject.ATTRIB_KEY, false), childKeyCol);
213         } else if (sObjectTag.equals("Section") == true) {
214           joinConditions.addCondition(getColumnRef(sClassName, AbstractObject.ATTRIB_KEY, false), childKeyCol);
215         }
216     
217         return joinConditions;
218     }
219
220     /* (non-Javadoc)
221      * @see org.openharmonise.rm.publishing.Publishable#getTagName()
222      */

223     public String JavaDoc getTagName() {
224     
225         return TAG_SECTION;
226     }
227     
228     
229     /* (non-Javadoc)
230      * @see org.openharmonise.rm.resources.AbstractParentObject#getChildClassNames()
231      */

232     public List getChildClassNames() {
233         return CHILD_CLASS_NAMES;
234     }
235
236
237
238 }
Popular Tags