1 package org.apache.fulcrum.intake.model; 2 3 56 57 import java.util.HashMap ; 58 import java.util.Map ; 59 import org.apache.fulcrum.intake.xmlmodel.XmlField; 60 import org.apache.fulcrum.ServiceException; 61 62 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("long", new FieldFactory.FieldCtor() 104 { 105 public Field getInstance(XmlField f, Group g) 106 throws Exception 107 { 108 return new LongField(f, g); 109 } 110 } 111 ); 112 fieldCtors.put("BigDecimal", new FieldFactory.FieldCtor() 113 { 114 public Field getInstance(XmlField f, Group g) 115 throws Exception 116 { 117 return new BigDecimalField(f, g); 118 } 119 } 120 ); 121 fieldCtors.put("NumberKey", new FieldFactory.FieldCtor() 122 { 123 public Field getInstance(XmlField f, Group g) 124 throws Exception 125 { 126 return new NumberKeyField(f, g); 127 } 128 } 129 ); 130 fieldCtors.put("ComboKey", new FieldFactory.FieldCtor() 131 { 132 public Field getInstance(XmlField f, Group g) 133 throws Exception 134 { 135 return new ComboKeyField(f, g); 136 } 137 } 138 ); 139 fieldCtors.put("StringKey", new FieldFactory.FieldCtor() 140 { 141 public Field getInstance(XmlField f, Group g) 142 throws Exception 143 { 144 return new StringKeyField(f, g); 145 } 146 } 147 ); 148 fieldCtors.put("FileItem", new FieldFactory.FieldCtor() 149 { 150 public Field getInstance(XmlField f, Group g) 151 throws Exception 152 { 153 return new FileItemField(f, g); 154 } 155 } 156 ); 157 fieldCtors.put("DateString", new FieldFactory.FieldCtor() 158 { 159 public Field getInstance(XmlField f, Group g) 160 throws Exception 161 { 162 return new DateStringField(f, g); 163 } 164 } 165 ); 166 fieldCtors.put("float", new FieldFactory.FieldCtor() 167 { 168 public Field getInstance(XmlField f, Group g) 169 throws Exception 170 { 171 return new FloatField(f, g); 172 } 173 } 174 ); 175 return fieldCtors; 176 } 177 178 private static abstract class FieldCtor 179 { 180 public Field getInstance(XmlField f, Group g) throws Exception 181 { 182 return null; 183 } 184 } 185 186 193 public static final Field getInstance(XmlField f, Group g) 194 throws Exception 195 { 196 FieldCtor fieldCtor = null; 197 Field field = null; 198 String type = f.getType(); 199 200 fieldCtor = (FieldCtor)fieldCtors.get(type); 201 if ( fieldCtor == null) 202 { 203 throw new ServiceException("Unsupported type: " + type); 204 } 205 else 206 { 207 field = fieldCtor.getInstance(f, g); 208 } 209 210 return field; 211 } 212 } 213 | Popular Tags |