1 /***
2 * Copyright (c) 2002, CodeStreet LLC. All rights reserved.<p>
3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4 * conditions are met:<p>
5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
7 * in the documentation and/or other materials provided with the distribution. Neither the name of CodeStreet LLC. nor the
8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written
9 * permission.<p>
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>
16 */
17
18 package com.codestreet.messageforge;
19
20 /***
21 * Factory class to create field instances.
22 * @author Jawaid Hakim.
23 */
24 public class RFldFactory
25 {
26 /***
27 * Create a new field instance of the specified type with the specified name.
28 * @param xmlTag Field type. This is XML tag of the desired field type.
29 * @param name Field name.
30 * @param id Field Id.
31 * @return New field instance.
32 */
33 public static RFld createField(String xmlTag, String name, String id) throws FactoryException
34 {
35 if (xmlTag == null)
36 throw new FactoryException("NULL field tag");
37
38 if (name == null)
39 throw new FactoryException("NULL field name");
40
41 java.lang.Class cls = getClass(xmlTag);
42 if (cls != null)
43 {
44 try
45 {
46 RFld fld = (RFld)cls.newInstance();
47 fld.setName(name);
48 if (id != null)
49 fld.setId(Integer.parseInt(id));
50 return fld;
51 }
52 catch (java.lang.IllegalAccessException ex)
53 {
54 throw new FactoryException(ex);
55 }
56 catch (java.lang.InstantiationException ex)
57 {
58 throw new FactoryException(ex);
59 }
60 }
61
62 throw new FactoryException("Unable to create field: " + xmlTag);
63 }
64
65 /***
66 * Get the <tt>java.lang.class</tt> object corresponding to
67 * the specified XML field tag.
68 * @param xmlTag XML tag of field.
69 * @return <tt>java.lang.class</tt> object corresponding to
70 * the specified XML field tag. Returns <tt>null</tt> if the
71 * corresponding <tt>java.lang.class</tt> is not defined.
72 */
73 public static final java.lang.Class getClass(String xmlTag)
74 {
75 return (java.lang.Class)TAG_TO_CLASS.get(xmlTag);
76 }
77
78 /***
79 * Build XML tag to Class maping.
80 */
81 static final void buildTags() throws FactoryException
82 {
83 try
84 {
85 TAG_TO_CLASS = new java.util.HashMap();
86 TAG_TO_CLASS.put(RFldDatetime.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldDatetime"));
87 TAG_TO_CLASS.put(RFldString.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldString"));
88 TAG_TO_CLASS.put(RFldStringArray.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldStringArray"));
89 TAG_TO_CLASS.put(RFldStringHashtable.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldStringHashtable"));
90 TAG_TO_CLASS.put(RFldI8.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI8"));
91 TAG_TO_CLASS.put(RFldI8Array.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI8Array"));
92 TAG_TO_CLASS.put(RFldI16.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI16"));
93 TAG_TO_CLASS.put(RFldI16Array.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI16Array"));
94 TAG_TO_CLASS.put(RFldI32.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI32"));
95 TAG_TO_CLASS.put(RFldI32Array.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI32Array"));
96 TAG_TO_CLASS.put(RFldI64.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI64"));
97 TAG_TO_CLASS.put(RFldI64Array.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldI64Array"));
98 TAG_TO_CLASS.put(RFldF32.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldF32"));
99 TAG_TO_CLASS.put(RFldF32Array.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldF32Array"));
100 TAG_TO_CLASS.put(RFldF64.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldF64"));
101 TAG_TO_CLASS.put(RFldF64Array.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldF64Array"));
102 TAG_TO_CLASS.put(RFldBool.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldBool"));
103 TAG_TO_CLASS.put(RFldTibrvMsg.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldTibrvMsg"));
104 TAG_TO_CLASS.put(RFldTibrvMsgArray.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldTibrvMsgArray"));
105
106 TAG_TO_CLASS.put(RFldTibrvIPPort.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldTibrvIPPort"));
107 TAG_TO_CLASS.put(RFldTibrvIPAddr.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldTibrvIPAddr"));
108
109 TAG_TO_CLASS.put(RFldOpaque.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldOpaque"));
110 TAG_TO_CLASS.put(RFldMsgObj.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldMsgObj"));
111 TAG_TO_CLASS.put(RFldMsgObjArray.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldMsgObjArray"));
112 TAG_TO_CLASS.put(RFldMsgObjHashtable.XML_TAG, java.lang.Class.forName("com.reuters.rmsg.RFldMsgObjHashtable"));
113 }
114 catch (java.lang.ClassNotFoundException ex)
115 {
116 throw new FactoryException(ex);
117 }
118 }
119
120 private static transient java.util.Map TAG_TO_CLASS;
121 static
122 {
123 try
124 {
125 buildTags();
126 }
127 catch (FactoryException ex)
128 {
129 // TODO
130 }
131 }
132 }
This page was automatically generated by Maven