KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > metadata > values > Value


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.metadata.values;
20
21 import java.util.logging.*;
22
23 import org.openharmonise.commons.dsi.*;
24 import org.openharmonise.commons.dsi.dml.*;
25 import org.openharmonise.rm.*;
26 import org.openharmonise.rm.dsi.*;
27 import org.openharmonise.rm.publishing.*;
28 import org.openharmonise.rm.resources.*;
29 import org.openharmonise.rm.resources.lifecycle.*;
30 import org.w3c.dom.*;
31
32
33 /**
34  * This class represents an element in a metadata vocabulary which will be
35  * part of a <code>Property</code> <code>Range</code>'s set of allowable values.
36  *
37  * @author Michael Bell
38  * @version $Revision: 1.4 $
39  *
40  */

41 public class Value
42     extends AbstractChildObject
43     implements DataStoreObject, Publishable, Editable {
44
45     //XML constants
46
/**
47      * The value XML element name
48      */

49     public static final String JavaDoc TAG_VALUE = "Value";
50     
51     /**
52      * The description XML element name
53      */

54     public static final String JavaDoc TAG_DESCRIPTION = "Description";
55     
56     /**
57      * The code XML element name
58      */

59     public static final String JavaDoc TAG_CODE = "Code";
60     
61     /**
62      * The order XML attribute name
63      */

64     public static final String JavaDoc ATTRIB_ORDER = "order";
65
66     //DB constants
67
/**
68      * The <code>Value</code> database table name
69      */

70     private static final String JavaDoc TBL_VALUE = "value";
71     
72     /**
73      * The order database column name
74      */

75     private static final String JavaDoc CLMN_ORDER = "order";
76     
77     /**
78      * Logger for this class
79      */

80     private static final Logger m_logger = Logger.getLogger(Value.class.getName());
81
82     //static initialiser
83
static {
84         DatabaseInfo.getInstance().registerTableName(
85             Value.class.getName(),
86             TBL_VALUE);
87     }
88
89     /**
90      * Constructs a new <code>Value</code>.
91      *
92      */

93     public Value() {
94         super();
95     }
96
97     /**
98      * Constructs a new <cod>Value</code> with an interface to the data store.
99      *
100      * @param dbintrf the data store interface
101      */

102     public Value(AbstractDataStoreInterface dbintrf) {
103         super(dbintrf);
104
105     }
106
107     /**
108       * Constructs an existing <code>Value</code> identified by its id.
109       *
110       * @param dbintrf the data store interface
111       * @param nId the id of the <code>Value</code>
112       */

113     public Value(AbstractDataStoreInterface dbintrf, int nId) {
114         super(dbintrf, nId);
115
116     }
117
118     /**
119      * Constructs a new <code>Value</code> which may be historical.
120      *
121      * @param dbintrf the data store interface
122      * @param bIsHist <code>true</code> if the new <code>Value</code> is to be
123      * a historical version
124      */

125     public Value(AbstractDataStoreInterface dbintrf, boolean bIsHist) {
126         super(dbintrf);
127         setHistorical(bIsHist);
128     }
129
130     /**
131       * Constructs an existing <code>Value</code> which may be historical.
132       *
133       * @param dbintrf the data store interface
134       * @param nId the id of this object
135       * @param nKey the unique key of the resource
136       * @param bIsHist <code>true</code> if the version of the <code>Value</code>
137       * is historical
138       */

139     public Value(
140         AbstractDataStoreInterface dbintrf,
141         int nId,
142         int nKey,
143         boolean bIsHist) {
144         super(dbintrf, nId, nKey, bIsHist);
145
146     }
147
148     /**
149      * Returns the code of this <code>Value</code>.
150      * Maps to <code>getName</code> in <code>AbstractObject</code>.
151      *
152      * @return the code of this <code>Value</code>.
153      * @throws DataAccessException if there is an error populating this object
154      */

155     public String JavaDoc getCode() throws DataAccessException {
156         return getName();
157     }
158
159     /**
160      * Sets the code of this <code>Value</code>. Maps to <code>setName</code>
161      * in <code>AbstractObject</code>.
162      *
163      * @param sCode the new code of this <code>Value</code>
164      */

165     public void setCode(String JavaDoc sCode) {
166         try {
167             this.setName(sCode);
168         } catch (InvalidNameException e) {
169             m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
170         }
171     }
172
173     /**
174      * Returns the description of this <code>Value</code>.
175      * Maps to <code>getSummary</code> in <code>AbstractObject</code>.
176      *
177      * @return the description of this <code>Value</code>
178      * @throws DataAccessException if there is an error populating this object
179      */

180     public String JavaDoc getDescription() throws DataAccessException {
181         return (getSummary());
182     }
183
184     /**
185      * Sets the description of this <code>Value</code>.
186      * Maps to <code>setSummary</code> in <code>AbstractObject</code>
187      *
188      * @param sDesc the description
189      */

190     public void setDescription(String JavaDoc sDesc) {
191         setSummary(sDesc);
192     }
193
194     /* (non-Javadoc)
195      * @see java.lang.Object#toString()
196      */

197     public String JavaDoc toString() {
198         StringBuffer JavaDoc strBuff = new StringBuffer JavaDoc();
199
200         strBuff
201             .append("Value Name:[" + m_sName + "] ")
202             .append("Value Description:[" + m_sSummary + "] ")
203             .append("Value ID:[" + m_nId + "] ");
204
205         return strBuff.toString();
206     }
207
208     /* (non-Javadoc)
209      * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
210      */

211     public JoinConditions getInstanceJoinConditions(
212         String JavaDoc sObjectTag,
213         boolean bIsOuter)
214         throws DataStoreException {
215         return null;
216     }
217
218     /* (non-Javadoc)
219      * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceColumnRef(java.lang.String, boolean)
220      */

221     public ColumnRef getInstanceColumnRef(String JavaDoc sColumn, boolean bIsHist)
222         throws DataStoreException {
223         ColumnRef colref = null;
224
225         colref = super.getInstanceColumnRef(sColumn, bIsHist);
226
227         return colref;
228     }
229
230     /* (non-Javadoc)
231      * @see org.openharmonise.rm.publishing.Publishable#publish(org.w3c.dom.Element, org.openharmonise.rm.publishing.HarmoniseOutput, org.openharmonise.rm.publishing.State)
232      */

233     public Element publish(Element topEl, HarmoniseOutput xmlDoc, State state)
234         throws PublishException {
235
236         Element docEl = null;
237         Text txt = null;
238         String JavaDoc sTagName = topEl.getTagName();
239
240         if (sTagName.equals(TAG_DESCRIPTION)) {
241             try {
242                 docEl = xmlDoc.createElement(sTagName);
243                 txt = xmlDoc.createTextNode(getDescription());
244                 docEl.appendChild(txt);
245             } catch (DataAccessException e) {
246                 throw new PublishException(
247                     "Error occured getting description", e);
248             }
249         } else if (sTagName.equals(TAG_CODE)) {
250             try {
251                 docEl = xmlDoc.createElement(sTagName);
252                 txt = xmlDoc.createTextNode(getCode());
253                 docEl.appendChild(txt);
254             } catch (DataAccessException e) {
255                 throw new PublishException(
256                     "Error occured getting code", e);
257             }
258         } else {
259             // if we don't know about the tag, pass it up
260
docEl = super.publish(topEl, xmlDoc, state);
261         }
262
263         return docEl;
264     }
265
266     /* (non-Javadoc)
267      * @see org.openharmonise.rm.publishing.Publishable#populate(org.w3c.dom.Element, org.openharmonise.rm.publishing.State)
268      */

269     public void populate(Element xmlElement, State state)
270         throws PopulateException {
271         String JavaDoc sTagName = xmlElement.getTagName();
272         Text txt;
273
274         if (sTagName.equalsIgnoreCase(TAG_CODE)) {
275             txt = (Text) xmlElement.getFirstChild();
276             setCode(txt.getNodeValue());
277         } else if (sTagName.equalsIgnoreCase(TAG_DESCRIPTION)) {
278             txt = (Text) xmlElement.getFirstChild();
279             setDescription(txt.getNodeValue());
280         } else {
281             super.populate(xmlElement, state);
282         }
283     }
284
285     /* (non-Javadoc)
286      * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
287      */

288     public String JavaDoc getParentObjectClassName() {
289         return ValueGroup.class.getName();
290     }
291
292     /* (non-Javadoc)
293      * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
294      */

295     public String JavaDoc getDBTableName() {
296
297         return TBL_VALUE;
298     }
299
300     /* (non-Javadoc)
301      * @see org.openharmonise.rm.publishing.Publishable#getTagName()
302      */

303     public String JavaDoc getTagName() {
304         return TAG_VALUE;
305     }
306
307     /*-----------------------------------------------------------------
308       Protected methods
309       -----------------------------------------------------------------*/

310
311     /* (non-Javadoc)
312      * @see org.openharmonise.rm.resources.AbstractEditableObject#addDataToSave(org.openharmonise.commons.dsi.dml.InsertStatement)
313      */

314     protected void addDataToSave(InsertStatement insert)
315         throws DataStoreException {
316         super.addDataToSave(insert);
317     }
318
319     /* (non-Javadoc)
320      * @see org.openharmonise.rm.resources.AbstractEditableObject#saveNonCoreData()
321      */

322     protected void saveNonCoreData() throws EditException {
323         // no non core data
324

325     }
326 }
Popular Tags