1 26 27 package org.objectweb.jonas_lib.deployment.api; 28 29 import org.objectweb.jonas_lib.deployment.xml.EnvEntry; 30 31 36 public class EnvEntryDesc { 37 38 41 private String name; 42 43 46 private Class type; 47 48 51 private Object value; 52 53 59 public EnvEntryDesc(EnvEntry env) throws DeploymentDescException { 60 name = env.getEnvEntryName(); 61 String t = env.getEnvEntryType(); 62 String v = null; 63 if (env.getEnvEntryValue() != null) { 64 v = env.getEnvEntryValue(); 65 } 66 try { 67 if (t.equals(Boolean .class.getName())) { 68 type = Boolean .class; 69 if (v != null) { 70 if (v.equalsIgnoreCase("true")) { 71 value = Boolean.TRUE; 72 } else if (v.equalsIgnoreCase("false")) { 73 value = Boolean.FALSE; 74 } else { 75 throw new DeploymentDescException(v + " is not a valid value for env-entry " + name); 76 } 77 } 78 } else if (t.equals(String .class.getName())) { 79 type = String .class; 80 value = v; 81 } else if (t.equals(Integer .class.getName())) { 82 type = Integer .class; 83 if (v != null) { 84 value = new Integer (v); 85 } 86 } else if (t.equals(Character .class.getName())) { 87 type = Character .class; 88 if (v != null) { 89 if (v.length() != 1) { 90 throw new DeploymentDescException("The value '" + v + "' is not a valid value for env-entry of type java.lang.Character."); 91 } 92 value = new Character (v.charAt(0)); 93 } 94 } else if (t.equals(Double .class.getName())) { 95 type = Double .class; 96 if (v != null) { 97 value = new Double (v); 98 } 99 } else if (t.equals(Byte .class.getName())) { 100 type = Byte .class; 101 if (v != null) { 102 value = new Byte (v); 103 } 104 } else if (t.equals(Short .class.getName())) { 105 type = Short .class; 106 if (v != null) { 107 value = new Short (v); 108 } 109 } else if (t.equals(Long .class.getName())) { 110 type = Long .class; 111 if (v != null) { 112 value = new Long (v); 113 } 114 } else if (t.equals(Float .class.getName())) { 115 type = Float .class; 116 if (v != null) { 117 value = new Float (v); 118 } 119 } else { 120 throw new DeploymentDescException(t + " is not a valid type for env-entry " + name); 121 } 122 } catch (NumberFormatException e) { 123 throw new DeploymentDescException(v + " is not a valid value for env-entry " + name, e); 124 } 125 126 } 127 128 132 public String getName() { 133 return name; 134 } 135 136 151 public Class getType() { 152 return type; 153 } 154 155 159 public boolean hasValue() { 160 return value != null; 161 } 162 163 167 public Object getValue() { 168 if (value == null) { 169 throw new Error ("Value not set for env-entry " + name); 170 } 171 return value; 172 } 173 174 178 public String toString() { 179 StringBuffer ret = new StringBuffer (); 180 ret.append("\ngetName()=" + getName()); 181 ret.append("\ngetType()=" + getType()); 182 if (hasValue()) { 183 ret.append("\ngetValue()=" + getValue().toString()); 184 } 185 return ret.toString(); 186 } 187 188 } 189 | Popular Tags |