1 64 package com.jcorporate.expresso.kernel.metadata; 65 66 import com.jcorporate.expresso.core.dbobj.ValidValue; 67 import com.jcorporate.expresso.kernel.Configuration; 68 import com.jcorporate.expresso.kernel.digester.ComponentConfig; 69 import com.jcorporate.expresso.kernel.internal.DefaultConfigBean; 70 import com.jcorporate.expresso.kernel.util.ClassLocator; 71 import org.apache.commons.beanutils.ConvertUtils; 72 import org.apache.log4j.Logger; 73 74 import java.util.ArrayList ; 75 import java.util.List ; 76 77 83 84 public class SimpleProperty extends Property { 85 List validValues; 86 String value; 87 88 91 public SimpleProperty() { 92 super(); 93 validValues = new ArrayList (); 94 } 95 96 101 public void setValue(String value) { 102 this.value = value; 103 } 104 105 110 public String getValue() { 111 return value; 112 } 113 114 120 public void addValidValue(String key, String value) { 121 ValidValue vv = new ValidValue(key, value); 122 validValues.add(vv); 123 } 124 125 130 public List retrieveValidValues() { 131 return validValues; 132 } 133 134 144 public Configuration createConfigBean(DefaultConfigBean targetBean, 145 ComponentConfig config, 146 ComponentMetadata metadata) { 147 String newValue = config.getProperty(this.getName()); 148 if (newValue == null || newValue.length() == 0) { 149 newValue = this.getValue(); 150 } 151 152 String type = this.getType(); 153 154 try { 155 targetBean.set(this.getName(), ConvertUtils.convert(newValue, ClassLocator.loadClass(type))); 156 } catch (ClassNotFoundException ex) { 157 Logger log = Logger.getLogger(this.getClass()); 158 log.error("Error converting value " + value 159 + " to class : " + type + " class not found.", ex); 160 throw new IllegalArgumentException ("Class not found: " + type); 161 } 162 163 return targetBean; 164 } 165 166 } | Popular Tags |