1 18 package org.objectweb.kilim.repository; 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.util.Enumeration ; 22 import java.util.Properties ; 23 24 import org.objectweb.kilim.description.BasicNamedElement; 25 import org.objectweb.kilim.description.KILIM; 26 import org.objectweb.kilim.description.Property; 27 import org.objectweb.kilim.InternalException; 28 import org.objectweb.kilim.KilimException; 29 import org.objectweb.kilim.description.TemplateDescription; 30 31 36 public class ResourceRepository1 extends ResourceRepository { 37 38 41 public ResourceRepository1() { 42 super(); 43 } 44 45 49 public ResourceRepository1(TemplateDescriptionParser aParser) { 50 super(aParser); 51 } 52 53 61 protected TemplateDescription getSingleDescription(String resourceName, ResourceMapping parsingResult) throws ResourceNotFoundException { 62 TemplateDescription toBeReturned = super.getSingleDescription(resourceName, parsingResult); 63 64 String prp_fl_nm = resourceName + ".prop"; 65 66 InputStream is = null; 67 try { 68 is = getResourceLoader().getResource(prp_fl_nm); 69 } catch (ResourceNotFoundException rsnf) { 70 System.err.println("warning : No Properties found for " + prp_fl_nm + "."); 71 } 72 73 if (is == null) { System.err.println("warning : No .prop file found for " + prp_fl_nm + "."); } 74 75 Properties addtnl_prps = new Properties (); 76 try { 77 if (is != null) { addtnl_prps.load(is); } 78 } catch (IOException io) { 79 80 System.err.println("warning : Properties " + prp_fl_nm + "could not be loaded properly."); 81 } 82 83 for (Enumeration it = addtnl_prps.keys() ; it.hasMoreElements() ;) { 84 String crrt_prp = (String ) it.nextElement(); 85 BasicNamedElement prp = null; 86 try { 87 prp = toBeReturned.getAnyProvider(crrt_prp , false); 88 } catch (KilimException exc) { 89 System.err.println("warning : attempt to set an unknown property " + crrt_prp); 90 } 91 92 if (prp == null) { 93 System.err.println("warning : trying to set an unknown property " + crrt_prp); 94 } else if (!(prp instanceof Property)) { 95 System.err.println("warning : attempt to set a provider which is not a property " + crrt_prp + " (" + prp.getClass() + ")"); 96 } 97 98 if (prp != null) { 99 setValue((Property) prp , (String ) addtnl_prps.get(crrt_prp)); 100 } 101 } 102 103 return toBeReturned; 104 } 105 106 private static void setValue(Property property, String value) { 107 108 int tp_knd = property.getTypeKind(); 109 110 switch (tp_knd) { 111 112 case KILIM.BOOLEAN: 113 try { 114 Boolean bln = new Boolean (value); 115 property.setValue(bln); 116 } catch (Exception e) { 117 error(property , value , e); 118 e.printStackTrace(); 119 } 120 break; 121 122 case KILIM.CHAR: 123 try { 124 Character chr = new Character (value.charAt(0)); 125 property.setValue(chr); 126 } catch (Exception e) { 127 error(property, value, e); 128 e.printStackTrace(); 129 } 130 break; 131 132 case KILIM.BYTE: 133 try { 134 Byte bt = new Byte (value); 135 property.setValue(bt); 136 } catch (Exception e) { 137 error(property , value , e); 138 e.printStackTrace(); 139 } 140 break; 141 142 case KILIM.SHORT: 143 try { 144 Short shrt = new Short (value); 145 property.setValue(shrt); 146 } catch (Exception e) { 147 error(property , value , e); 148 e.printStackTrace(); 149 } 150 break; 151 152 case KILIM.INT: 153 try { 154 Integer intgr = new Integer (value); 155 property.setValue(intgr); 156 } catch (Exception e) { 157 error(property , value , e); 158 e.printStackTrace(); 159 } 160 break; 161 162 case KILIM.LONG: 163 try { 164 Long lng = new Long (value); 165 property.setValue(lng); 166 } catch (Exception e) { 167 error(property, value, e); 168 e.printStackTrace(); 169 } 170 break; 171 172 case KILIM.FLOAT: 173 try { 174 Float flt = new Float (value); 175 property.setValue(flt); 176 } catch (Exception e) { 177 error(property , value , e); 178 e.printStackTrace(); 179 } 180 break; 181 182 case KILIM.DOUBLE: 183 try { 184 Double dbl = new Double (value); 185 property.setValue(dbl); 186 } catch (Exception e) { 187 error(property, value, e); 188 e.printStackTrace(); 189 } 190 break; 191 192 case KILIM.OBJECT: 193 case KILIM.STRING: 194 try { 195 property.setValue(value); 196 } catch (Exception e) { 197 error(property , value , e); 198 e.printStackTrace(); 199 } 200 break; 201 202 default: 203 throw new InternalException(); 204 205 } 206 } 207 208 private static void error(Property property, String value, Exception exc) { 209 System.err.println("warning : " + property.getType() + " Property " + property.getLocalName() 210 + " could not be overloaded with provided value " + value + " because of the following exception :"); 211 exc.printStackTrace(); 212 } 213 } | Popular Tags |