KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > metadata > RepositoryTags


1 package org.apache.ojb.broker.metadata;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.broker.util.DoubleHashtable;
19 import org.apache.ojb.broker.util.logging.LoggerFactory;
20 import org.apache.ojb.broker.util.pooling.PoolConfiguration;
21
22 /**
23  * this class maintains a table mapping the xml-tags used in the
24  * repository.dtd to their corresponding ids used within OJB.
25  * This table is used in <br>
26  * 1. the RepositoryXmlHandler to identify tags on parsing the
27  * repository.xml in a large switch statement.
28  * 2. in the RepositoryPersistor to get the proper tag for a
29  * given XmlCapable id during assembling the repository.xml
30  * for output.<br>
31  * <b>Important note: This class is the only place where XML tags from the
32  * repository.dtd are maintained.
33  * All usages of these tags within OJB must use this table to ease
34  * changes of the DTD.</b>
35  * @author Thomas Mahler
36  */

37 public class RepositoryTags implements RepositoryElements
38 {
39     /**
40      * the two-way hashtable holding all entries.
41      */

42     private DoubleHashtable table;
43
44     /**
45      * the singleton instance of this class.
46      */

47     private static RepositoryTags instance = new RepositoryTags();
48
49     /**
50      * private Constructor, please use getInstance() to obtain
51      * the singleton instance of this class.
52      */

53     private RepositoryTags()
54     {
55         // construct the mapping table
56
table = new DoubleHashtable();
57         table.put("descriptor-repository", new Integer JavaDoc(MAPPING_REPOSITORY));
58         table.put("version", new Integer JavaDoc(REPOSITORY_VERSION));
59         table.put("isolation-level", new Integer JavaDoc(ISOLATION_LEVEL));
60         table.put("jdbc-connection-descriptor", new Integer JavaDoc(JDBC_CONNECTION_DESCRIPTOR));
61         table.put("platform", new Integer JavaDoc(DBMS_NAME));
62         table.put("schema", new Integer JavaDoc(SCHEMA_NAME));
63         table.put("jcd-alias", new Integer JavaDoc(JCD_ALIAS));
64         table.put("default-connection", new Integer JavaDoc(DEFAULT_CONNECTION));
65         table.put("driver", new Integer JavaDoc(DRIVER_NAME));
66         table.put("protocol", new Integer JavaDoc(URL_PROTOCOL));
67         table.put("subprotocol", new Integer JavaDoc(URL_SUBPROTOCOL));
68         table.put("dbalias", new Integer JavaDoc(URL_DBALIAS));
69         table.put("username", new Integer JavaDoc(USER_NAME));
70         table.put("password", new Integer JavaDoc(USER_PASSWD));
71         table.put("eager-release", new Integer JavaDoc(EAGER_RELEASE));
72         table.put("batch-mode", new Integer JavaDoc(BATCH_MODE));
73         table.put("useAutoCommit", new Integer JavaDoc(USE_AUTOCOMMIT));
74         table.put("ignoreAutoCommitExceptions", new Integer JavaDoc(IGNORE_AUTOCOMMIT_EXCEPTION));
75         table.put("class-descriptor", new Integer JavaDoc(CLASS_DESCRIPTOR));
76         table.put("class", new Integer JavaDoc(CLASS_NAME));
77         table.put("proxy", new Integer JavaDoc(CLASS_PROXY));
78         table.put("extent-class", new Integer JavaDoc(CLASS_EXTENT));
79         table.put("extends", new Integer JavaDoc(EXTENDS));
80         table.put("table", new Integer JavaDoc(TABLE_NAME));
81         table.put("orderby", new Integer JavaDoc(ORDERBY));
82         table.put("conversion", new Integer JavaDoc(FIELD_CONVERSION));
83         table.put("row-reader", new Integer JavaDoc(ROW_READER));
84         table.put("field-descriptor", new Integer JavaDoc(FIELD_DESCRIPTOR));
85         table.put("name", new Integer JavaDoc(FIELD_NAME));
86         table.put("column", new Integer JavaDoc(COLUMN_NAME));
87         table.put("jdbc-type", new Integer JavaDoc(JDBC_TYPE));
88         table.put("primarykey", new Integer JavaDoc(PRIMARY_KEY));
89         table.put("autoincrement", new Integer JavaDoc(AUTO_INCREMENT));
90         table.put("sequence-name", new Integer JavaDoc(SEQUENCE_NAME));
91         table.put("nullable", new Integer JavaDoc(NULLABLE));
92         table.put("indexed", new Integer JavaDoc(INDEXED));
93         table.put("length", new Integer JavaDoc(LENGTH));
94         table.put("precision", new Integer JavaDoc(PRECISION));
95         table.put("scale", new Integer JavaDoc(SCALE));
96         table.put(TAG_ACCESS, new Integer JavaDoc(ACCESS));
97
98         table.put("reference-descriptor", new Integer JavaDoc(REFERENCE_DESCRIPTOR));
99         table.put("class-ref", new Integer JavaDoc(REFERENCED_CLASS));
100         table.put("foreignkey", new Integer JavaDoc(FOREIGN_KEY));
101         table.put("auto-retrieve", new Integer JavaDoc(AUTO_RETRIEVE));
102         table.put("auto-update", new Integer JavaDoc(AUTO_UPDATE));
103         table.put("auto-delete", new Integer JavaDoc(AUTO_DELETE));
104         table.put("collection-descriptor", new Integer JavaDoc(COLLECTION_DESCRIPTOR));
105         table.put("element-class-ref", new Integer JavaDoc(ITEMS_CLASS));
106         table.put("inverse-foreignkey", new Integer JavaDoc(INVERSE_FK));
107         table.put("collection-class", new Integer JavaDoc(COLLECTION_CLASS));
108         table.put("indirection-table", new Integer JavaDoc(INDIRECTION_TABLE));
109         table.put("fk-pointing-to-element-class", new Integer JavaDoc(FK_POINTING_TO_ITEMS_CLASS));
110         table.put("fk-pointing-to-this-class", new Integer JavaDoc(FK_POINTING_TO_THIS_CLASS));
111         table.put("jndi-datasource-name", new Integer JavaDoc(DATASOURCE_NAME));
112         table.put("jdbc-level", new Integer JavaDoc(JDBC_LEVEL));
113         table.put("locking", new Integer JavaDoc(LOCKING));
114         table.put("update-lock", new Integer JavaDoc(UPDATE_LOCK));
115         table.put("refresh", new Integer JavaDoc(REFRESH));
116         table.put("proxy", new Integer JavaDoc(PROXY_REFERENCE));
117         table.put("sort", new Integer JavaDoc(SORT));
118         table.put("otm-dependent", new Integer JavaDoc(OTM_DEPENDENT));
119
120         table.put("index-descriptor", new Integer JavaDoc(INDEX_DESCRIPTOR));
121         table.put("index-column", new Integer JavaDoc(INDEX_COLUMN));
122         table.put("unique", new Integer JavaDoc(UNIQUE));
123         table.put("name", new Integer JavaDoc(NAME));
124
125         table.put(PoolConfiguration.MAX_ACTIVE, new Integer JavaDoc(CON_MAX_ACTIVE));
126         table.put(PoolConfiguration.MAX_IDLE, new Integer JavaDoc(CON_MAX_IDLE));
127         table.put(PoolConfiguration.MAX_WAIT, new Integer JavaDoc(CON_MAX_WAIT));
128         table.put(
129             PoolConfiguration.MIN_EVICTABLE_IDLE_TIME_MILLIS,
130             new Integer JavaDoc(CON_MIN_EVICTABLE_IDLE_TIME_MILLIS));
131         table.put(
132             PoolConfiguration.NUM_TESTS_PER_EVICTION_RUN,
133             new Integer JavaDoc(CON_NUM_TESTS_PER_EVICTION_RUN));
134         table.put(PoolConfiguration.TEST_ON_BORROW, new Integer JavaDoc(CON_TEST_ON_BORROW));
135         table.put(PoolConfiguration.TEST_ON_RETURN, new Integer JavaDoc(CON_TEST_ON_RETURN));
136         table.put(PoolConfiguration.TEST_WHILE_IDLE, new Integer JavaDoc(CON_TEST_WHILE_IDLE));
137         table.put(
138             PoolConfiguration.TIME_BETWEEN_EVICTION_RUNS_MILLIS,
139             new Integer JavaDoc(CON_TIME_BETWEEN_EVICTION_RUNS_MILLIS));
140         table.put(PoolConfiguration.WHEN_EXHAUSTED_ACTION, new Integer JavaDoc(CON_WHEN_EXHAUSTED_ACTION));
141         table.put(PoolConfiguration.VALIDATION_QUERY, new Integer JavaDoc(VALIDATION_QUERY));
142
143         table.put(PoolConfiguration.LOG_ABANDONED, new Integer JavaDoc(CON_LOG_ABANDONED));
144         table.put(PoolConfiguration.REMOVE_ABANDONED, new Integer JavaDoc(CON_REMOVE_ABANDONED));
145         table.put(
146             PoolConfiguration.REMOVE_ABANDONED_TIMEOUT,
147             new Integer JavaDoc(CON_REMOVE_ABANDONED_TIMEOUT));
148
149         table.put("connectionFactory", new Integer JavaDoc(CONNECTION_FACTORY));
150         table.put("connection-pool", new Integer JavaDoc(CONNECTION_POOL));
151         table.put("class-ref", new Integer JavaDoc(CLASS_REF));
152         table.put("id", new Integer JavaDoc(ID));
153         table.put("field-id-ref", new Integer JavaDoc(FIELD_ID_REF));
154         table.put("field-ref", new Integer JavaDoc(FIELD_REF));
155         table.put("attribute", new Integer JavaDoc(ATTRIBUTE));
156         table.put("attribute-name", new Integer JavaDoc(ATTRIBUTE_NAME));
157         table.put("attribute-value", new Integer JavaDoc(ATTRIBUTE_VALUE));
158         table.put("documentation", new Integer JavaDoc(DOCUMENTATION));
159         table.put("accept-locks", new Integer JavaDoc(ACCEPT_LOCKS));
160
161         table.put("sequence-manager", new Integer JavaDoc(SEQUENCE_MANAGER));
162         table.put("className", new Integer JavaDoc(SEQUENCE_MANAGER_CLASS));
163
164         table.put("query-customizer", new Integer JavaDoc(QUERY_CUSTOMIZER));
165         table.put("initialization-method", new Integer JavaDoc(INITIALIZATION_METHOD));
166         table.put("factory-class", new Integer JavaDoc(FACTORY_CLASS));
167         table.put("factory-method", new Integer JavaDoc(FACTORY_METHOD));
168
169         table.put("insert-procedure", new Integer JavaDoc(INSERT_PROCEDURE));
170         table.put("update-procedure", new Integer JavaDoc(UPDATE_PROCEDURE));
171         table.put("delete-procedure", new Integer JavaDoc(DELETE_PROCEDURE));
172         table.put("constant-argument", new Integer JavaDoc(CONSTANT_ARGUMENT));
173         table.put("runtime-argument", new Integer JavaDoc(RUNTIME_ARGUMENT));
174         table.put("return", new Integer JavaDoc(RETURN));
175         table.put("value", new Integer JavaDoc(VALUE));
176         table.put("return-field-ref", new Integer JavaDoc(RETURN_FIELD_REF));
177         table.put("include-pk-only", new Integer JavaDoc(INCLUDE_PK_FIELDS_ONLY));
178         table.put("include-all-fields", new Integer JavaDoc(INCLUDE_ALL_FIELDS));
179
180         table.put("object-cache", new Integer JavaDoc(OBJECT_CACHE));
181
182         table.put("proxy-prefetching-limit", new Integer JavaDoc(PROXY_PREFETCHING_LIMIT));
183
184         // add new tags here !
185
}
186
187     /**
188      * returns the singleton instance.
189      */

190     public static RepositoryTags getInstance()
191     {
192         return instance;
193     }
194
195     /**
196      * returns the xml-tag literal associated with the repository element with
197      * id <code>elementId</code>.
198      * @return the resulting tag
199      */

200     public String JavaDoc getTagById(int elementId)
201     {
202         return (String JavaDoc) table.getKeyByValue(new Integer JavaDoc(elementId));
203     }
204
205     /**
206      * returns the opening xml-tag associated with the repository element with
207      * id <code>elementId</code>.
208      * @return the resulting tag
209      */

210     public String JavaDoc getOpeningTagById(int elementId)
211     {
212         return "<" + table.getKeyByValue(new Integer JavaDoc(elementId)) + ">";
213     }
214
215     /**
216      * returns the opening but non-closing xml-tag
217      * associated with the repository element with
218      * id <code>elementId</code>.
219      * @return the resulting tag
220      */

221     public String JavaDoc getOpeningTagNonClosingById(int elementId)
222     {
223         return "<" + table.getKeyByValue(new Integer JavaDoc(elementId));
224     }
225
226     /**
227      * returns the opening xml-tag associated with the repository element with
228      * id <code>elementId</code>.
229      * @return the resulting tag
230      */

231     public String JavaDoc getOpeningTagById(int elementId, String JavaDoc attributes)
232     {
233         return "<" + table.getKeyByValue(new Integer JavaDoc(elementId)) + " " + attributes + ">";
234     }
235
236     /**
237      * returns the opening but non-closing xml-tag
238      * associated with the repository element with
239      * id <code>elementId</code>.
240      * @return the resulting tag
241      */

242     public String JavaDoc getAttribute(int elementId, String JavaDoc value)
243     {
244         return table.getKeyByValue(new Integer JavaDoc(elementId)) + "=\"" + value + "\"";
245     }
246
247     /**
248      * returns the closing xml-tag associated with the repository element with
249      * id <code>elementId</code>.
250      * @return the resulting tag
251      */

252     public String JavaDoc getClosingTagById(int elementId)
253     {
254         return "</" + table.getKeyByValue(new Integer JavaDoc(elementId)) + ">";
255     }
256
257     /**
258      * returns the repository element id associated with the xml-tag
259      * literal <code>tag</code>.
260      * @return the resulting repository element id.
261      * @throws NullPointerException if no value was found for <b>tag</b>
262      */

263     public int getIdByTag(String JavaDoc tag)
264     {
265         Integer JavaDoc value = (Integer JavaDoc) table.getValueByKey(tag);
266         if (value == null)
267             LoggerFactory.getDefaultLogger().error(
268                 "** " + this.getClass().getName() + ": Tag '" + tag + "' is not defined. **");
269         return value.intValue();
270     }
271
272     /**
273      * returns the opening xml-tag associated with the repository element with
274      * id <code>elementId</code>.
275      * @return the resulting tag
276      */

277     public String JavaDoc getCompleteTagById(int elementId, String JavaDoc characters)
278     {
279         String JavaDoc result = getOpeningTagById(elementId);
280         result += characters;
281         result += getClosingTagById(elementId);
282         return result;
283     }
284 }
285
Popular Tags