1 28 29 package com.caucho.jca.cfg; 30 31 import com.caucho.config.Config; 32 import com.caucho.config.ConfigException; 33 import com.caucho.log.Log; 34 import com.caucho.util.L10N; 35 36 import java.util.HashMap ; 37 import java.util.Iterator ; 38 import java.util.logging.Logger ; 39 40 43 public class ObjectConfig { 44 private static final L10N L = new L10N(ObjectConfig.class); 45 private static final Logger log = Log.open(ObjectConfig.class); 46 47 private Class _type; 48 private HashMap <String ,ConfigPropertyConfig> _propertyMap = 49 new HashMap <String ,ConfigPropertyConfig>(); 50 51 public ObjectConfig() 52 { 53 } 54 55 58 public void setType(Class type) 59 throws ConfigException 60 { 61 _type = type; 62 63 Config.validate(type, Object .class); 64 } 65 66 69 public Class getType() 70 { 71 return _type; 72 } 73 74 77 public void addConfigProperty(ConfigPropertyConfig property) 78 throws ConfigException 79 { 80 if (_propertyMap.get(property.getName()) != null) 81 throw new ConfigException(L.l("'{0}' is a duplicate property name. Property names must be declared only once.", 82 property.getName())); 83 84 _propertyMap.put(property.getName(), property); 85 } 86 87 90 public Object instantiate() 91 throws Exception 92 { 93 if (_type == null) 94 throw new ConfigException(L.l("The type must be set for an object configuration.")); 95 96 Object object = _type.newInstance(); 97 98 Iterator <ConfigPropertyConfig> iter = _propertyMap.values().iterator(); 99 while (iter.hasNext()) { 100 ConfigPropertyConfig prop = iter.next(); 101 102 if (prop.getValue() != null) { 103 Config.setAttribute(object, prop.getName(), prop.getValue()); 104 } 105 } 106 107 return object; 108 } 109 } 110 | Popular Tags |