1 package org.apache.turbine.services.intake.model;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.util.HashMap;
58 import java.util.Map;
59 import org.apache.turbine.services.intake.xmlmodel.XmlField;
60 import org.apache.turbine.util.TurbineException;
61
62 /***
63 * Creates Field objects.
64 *
65 * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
66 * @version $Id: FieldFactory.java,v 1.4 2002/07/11 13:21:40 mpoeschl Exp $
67 */
68 public abstract class FieldFactory
69 {
70 private static Map fieldCtors = initFieldCtors();
71
72 private static Map initFieldCtors()
73 {
74 fieldCtors = new HashMap();
75
76 fieldCtors.put("int", new FieldFactory.FieldCtor()
77 {
78 public Field getInstance(XmlField f, Group g)
79 throws Exception
80 {
81 return new IntegerField(f, g);
82 }
83 }
84 );
85 fieldCtors.put("boolean", new FieldFactory.FieldCtor()
86 {
87 public Field getInstance(XmlField f, Group g)
88 throws Exception
89 {
90 return new BooleanField(f, g);
91 }
92 }
93 );
94 fieldCtors.put("String", new FieldFactory.FieldCtor()
95 {
96 public Field getInstance(XmlField f, Group g)
97 throws Exception
98 {
99 return new StringField(f, g);
100 }
101 }
102 );
103 fieldCtors.put("BigDecimal", new FieldFactory.FieldCtor()
104 {
105 public Field getInstance(XmlField f, Group g)
106 throws Exception
107 {
108 return new BigDecimalField(f, g);
109 }
110 }
111 );
112 fieldCtors.put("NumberKey", new FieldFactory.FieldCtor()
113 {
114 public Field getInstance(XmlField f, Group g)
115 throws Exception
116 {
117 return new NumberKeyField(f, g);
118 }
119 }
120 );
121 fieldCtors.put("ComboKey", new FieldFactory.FieldCtor()
122 {
123 public Field getInstance(XmlField f, Group g)
124 throws Exception
125 {
126 return new ComboKeyField(f, g);
127 }
128 }
129 );
130 fieldCtors.put("StringKey", new FieldFactory.FieldCtor()
131 {
132 public Field getInstance(XmlField f, Group g)
133 throws Exception
134 {
135 return new StringKeyField(f, g);
136 }
137 }
138 );
139 fieldCtors.put("FileItem", new FieldFactory.FieldCtor()
140 {
141 public Field getInstance(XmlField f, Group g)
142 throws Exception
143 {
144 return new FileItemField(f, g);
145 }
146 }
147 );
148 fieldCtors.put("DateString", new FieldFactory.FieldCtor()
149 {
150 public Field getInstance(XmlField f, Group g)
151 throws Exception
152 {
153 return new DateStringField(f, g);
154 }
155 }
156 );
157 fieldCtors.put("float", new FieldFactory.FieldCtor()
158 {
159 public Field getInstance(XmlField f, Group g)
160 throws Exception
161 {
162 return new FloatField(f, g);
163 }
164 }
165 );
166 return fieldCtors;
167 }
168
169 private static abstract class FieldCtor
170 {
171 public Field getInstance(XmlField f, Group g) throws Exception
172 {
173 return null;
174 }
175 }
176
177 /***
178 * Creates a Field object appropriate for the type specified
179 * in the xml file.
180 *
181 * @param f a <code>XmlField</code> value
182 * @return a <code>Field</code> value
183 */
184 public static final Field getInstance(XmlField f, Group g)
185 throws Exception
186 {
187 FieldCtor fieldCtor = null;
188 Field field = null;
189 String type = f.getType();
190
191 fieldCtor = (FieldCtor)fieldCtors.get(type);
192 if ( fieldCtor == null)
193 {
194 throw new TurbineException("Unsupported type: " + type);
195 }
196 else
197 {
198 field = fieldCtor.getInstance(f, g);
199 }
200
201 return field;
202 }
203 }
This page was automatically generated by Maven