Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: ojb/broker/metadata/RepositoryTags.java


1   /*
2    * ObJectRelationalBridge - Bridging Java Objects and Relational Databases
3    * http://objectbridge.sourceforge.net
4    * Copyright (C) 2000, 2001 Thomas Mahler, et al.
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19   */
20  package ojb.broker.metadata; 
21  
22  import ojb.broker.util.DoubleHashtable;
23  
24  /**
25   * this class maintains a table mapping the xml-tags used in the
26   * repository.dtd to their corresponding ids used within OJB.
27   * This table is used in <br>
28   * 1. the RepositoryXmlHandler to identify tags on parsing the 
29   * repository.xml in a large switch statement.
30   * 2. in the RepositoryPersistor to get the proper tag for a
31   * given XmlCapable id during assembling the repository.xml
32   * for output.<br>
33   * <b>Important note: This class is the only place where XML tags from the 
34   * repository.dtd are maintained.
35   * All usages of these tags within OJB must use this table to ease
36   * changes of the DTD.</b>
37   * @author    Thomas Mahler
38   */
39  public class RepositoryTags implements RepositoryElements
40  {
41      /**
42       * the two-way hashtable holding all entries.
43       */
44      private DoubleHashtable table;
45  
46      /**
47       * the singleton instance of this class.
48       */
49      private static RepositoryTags instance = new RepositoryTags();
50  
51      /**
52       * private Constructor, please use getInstance() to obtain 
53       * the singleton instance of this class.
54       */
55      private RepositoryTags()
56      {
57          // construct the mapping table
58          table = new DoubleHashtable();
59          table.put("descriptor-repository", new Integer(MappingRepository));
60          table.put("jdbc-connection-descriptor", new Integer(JdbcConnectionDescriptor));
61          table.put("platform", new Integer(Dbms_name));
62          table.put("schema", new Integer(Schema_name));
63          table.put("driver", new Integer(Driver_name));
64          table.put("protocol", new Integer(Url_protocol));
65          table.put("subprotocol", new Integer(Url_subprotocol));
66          table.put("dbalias", new Integer(Url_dbalias));
67          table.put("username", new Integer(User_name));
68          table.put("password", new Integer(User_passwd));
69          table.put("class-descriptor", new Integer(ClassDescriptor));
70          table.put("class", new Integer(Class_name));
71          table.put("proxy", new Integer(Class_proxy));
72          table.put("extent-class", new Integer(Class_extent));
73          table.put("table", new Integer(Table_name));
74          table.put("orderby", new Integer(Orderby));
75          table.put("conversion", new Integer(FieldConversion));
76          table.put("row-reader", new Integer(RowReader));
77          table.put("field-descriptor", new Integer(FIELDDESCRIPTOR));
78          table.put("name", new Integer(Field_name));
79          table.put("column", new Integer(Column_name));
80          table.put("jdbc-type", new Integer(Jdbc_type));
81          table.put("primarykey", new Integer(PrimaryKey));
82          table.put("autoincrement", new Integer(Autoincrement));
83          table.put("nullable", new Integer(NULLABLE));
84          table.put("indexed", new Integer(INDEXED));
85          table.put("length", new Integer(LENGTH));
86          table.put("precision", new Integer(PRECISION));
87          table.put("scale", new Integer(SCALE));
88          
89          table.put("reference-descriptor", new Integer(ReferenceDescriptor));
90          //table.put("rdfield.name", new Integer(Rdfield_name));
91          table.put("class-ref", new Integer(Referenced_class));
92          table.put("foreignkey", new Integer(FOREIGN_KEY));
93          table.put("field-id-ref", new Integer(Fk_descriptor_id));
94          table.put("auto-retrieve", new Integer(Auto_retrieve));
95          table.put("auto-update", new Integer(Auto_update));
96          table.put("auto-delete", new Integer(Auto_delete));
97          table.put("collection-descriptor", new Integer(CollectionDescriptor));
98          //table.put("cdfield.name", new Integer(Cdfield_name));
99          table.put("element-class-ref", new Integer(Items_class));
100         table.put("inverse-foreignkey", new Integer(Inverse_fk));
101         table.put("collection-class", new Integer(Collection_class));
102         table.put("indirection-table", new Integer(Indirection_table));
103         table.put("fk-pointing-to-element-class", new Integer(Fk_pointing_to_items_class));
104         table.put("fk-pointing-to-this-class", new Integer(Fk_pointing_to_this_class));
105         //table.put("proxyCollection", new Integer(ProxyCollection));
106         //table.put("refreshCollection", new Integer(RefreshCollection));
107         table.put("jndi-datasource-name", new Integer(Datasource_name));
108         table.put("jdbc-level", new Integer(Jdbc_level));
109         table.put("locking", new Integer(Locking));
110         table.put("refresh", new Integer(RefreshReference));
111         table.put("proxy", new Integer(ProxyReference));
112         table.put("isolation-level", new Integer(ISOLATION_LEVEL));
113         table.put("sort", new Integer(SORT));
114         
115         // add new tags here !
116     }
117 
118   /**
119    * returns the singleton instance.
120    */
121     public static RepositoryTags getInstance()
122     {
123         return instance;
124     }
125 
126   /**
127    * returns the xml-tag literal associated with the repository element with 
128    * id <code>elementId</code>.
129    * @return the resulting tag 
130    */
131     public String getTagById(int elementId)
132     {
133         return (String) table.getKeyByValue(new Integer(elementId));
134     }
135 
136   /**
137    * returns the opening xml-tag associated with the repository element with 
138    * id <code>elementId</code>.
139    * @return the resulting tag 
140    */
141     public String getOpeningTagById(int elementId)
142     {
143         return "<" + table.getKeyByValue(new Integer(elementId)) + ">";
144     }
145     
146   /**
147    * returns the opening xml-tag associated with the repository element with 
148    * id <code>elementId</code>.
149    * @return the resulting tag 
150    */
151     public String getOpeningTagById(int elementId, String attributes)
152     {
153         return "<" + table.getKeyByValue(new Integer(elementId)) + " " + attributes + ">";
154     }    
155 
156   /**
157    * returns the closing xml-tag associated with the repository element with 
158    * id <code>elementId</code>.
159    * @return the resulting tag 
160    */
161     public String getClosingTagById(int elementId)
162     {
163         return "</" + table.getKeyByValue(new Integer(elementId)) + ">";
164     }
165 
166   /**
167    * returns the repository element id associated with the xml-tag 
168    * literal <code>tag</code>.
169    * @return the resulting repository element id.
170    */
171     public int getIdByTag(String tag)
172     {
173         return ((Integer) table.getValueByKey(tag)).intValue();
174     }
175     
176   /**
177    * returns the opening xml-tag associated with the repository element with 
178    * id <code>elementId</code>.
179    * @return the resulting tag 
180    */
181     public String getCompleteTagById(int elementId, String characters)
182     {
183         String result = getOpeningTagById(elementId);
184         result += characters;
185         result += getClosingTagById(elementId);
186         return result;
187     }    
188 
189 
190 }