EnvEntryDesc.java

00001 
00027 package org.objectweb.jonas_lib.deployment.api;
00028 
00029 import org.objectweb.jonas_lib.deployment.xml.EnvEntry;
00030 
00036 public class EnvEntryDesc {
00037 
00041     private String name;
00042 
00046     private Class type;
00047 
00051     private Object value;
00052 
00059     public EnvEntryDesc(EnvEntry env) throws DeploymentDescException {
00060         name = env.getEnvEntryName();
00061         String t = env.getEnvEntryType();
00062         String v = null;
00063         if (env.getEnvEntryValue() != null) {
00064             v = env.getEnvEntryValue();
00065         }
00066         try {
00067             if (t.equals(Boolean.class.getName())) {
00068                 type = Boolean.class;
00069                 if (v != null) {
00070                     if (v.equalsIgnoreCase("true")) {
00071                         value = Boolean.TRUE;
00072                     } else if (v.equalsIgnoreCase("false")) {
00073                         value = Boolean.FALSE;
00074                     } else {
00075                         throw new DeploymentDescException(v + " is not a valid value for env-entry " + name);
00076                     }
00077                 }
00078             } else if (t.equals(String.class.getName())) {
00079                 type = String.class;
00080                 value = v;
00081             } else if (t.equals(Integer.class.getName())) {
00082                 type = Integer.class;
00083                 if (v != null) {
00084                     value = new Integer(v);
00085                 }
00086             } else if (t.equals(Character.class.getName())) {
00087                 type = Character.class;
00088                 if (v != null) {
00089                     if (v.length() != 1) {
00090                         throw new DeploymentDescException("The value '" + v + "' is not a valid value for env-entry of type java.lang.Character.");
00091                     }
00092                     value = new Character(v.charAt(0));
00093                 }
00094             } else if (t.equals(Double.class.getName())) {
00095                 type = Double.class;
00096                 if (v != null) {
00097                     value = new Double(v);
00098                 }
00099             } else if (t.equals(Byte.class.getName())) {
00100                 type = Byte.class;
00101                 if (v != null) {
00102                     value = new Byte(v);
00103                 }
00104             } else if (t.equals(Short.class.getName())) {
00105                 type = Short.class;
00106                 if (v != null) {
00107                     value = new Short(v);
00108                 }
00109             } else if (t.equals(Long.class.getName())) {
00110                 type = Long.class;
00111                 if (v != null) {
00112                     value = new Long(v);
00113                 }
00114             } else if (t.equals(Float.class.getName())) {
00115                 type = Float.class;
00116                 if (v != null) {
00117                     value = new Float(v);
00118                 }
00119             } else {
00120                 throw new DeploymentDescException(t + " is not a valid type for env-entry " + name);
00121             }
00122         } catch (NumberFormatException e) {
00123             throw new DeploymentDescException(v + " is not a valid value for env-entry " + name, e);
00124         }
00125 
00126     }
00127 
00132     public String getName() {
00133             return name;
00134     }
00135 
00151     public Class getType() {
00152             return type;
00153     }
00154 
00159     public boolean hasValue() {
00160             return value != null;
00161     }
00162 
00167     public Object getValue() {
00168         if (value == null) {
00169             throw new Error("Value not set for env-entry " + name);
00170         }
00171         return value;
00172     }
00173 
00178     public String toString() {
00179         StringBuffer ret = new StringBuffer();
00180         ret.append("\ngetName()=" + getName());
00181         ret.append("\ngetType()=" + getType());
00182         if (hasValue()) {
00183             ret.append("\ngetValue()=" + getValue().toString());
00184         }
00185         return ret.toString();
00186     }
00187 
00188 }

Generated on Tue Feb 15 15:05:50 2005 for JOnAS by  doxygen 1.3.9.1