1 22 package org.jboss.metadata; 23 24 import javax.naming.Context ; 25 import javax.naming.NamingException ; 26 27 import org.w3c.dom.Element ; 28 29 import org.jboss.deployment.DeploymentException; 30 import org.jboss.naming.Util; 31 32 39 public class EnvEntryMetaData extends Ref 40 { 41 43 private String name; 45 46 private String type; 47 48 private String value; 49 50 52 public EnvEntryMetaData() 54 { 55 } 56 57 59 60 public String getName() 61 { 62 return name; 63 } 64 65 public void setName(String name) 66 { 67 this.name = name; 68 } 69 70 public String getType() 71 { 72 return type; 73 } 74 75 public void setType(String type) 76 { 77 this.type = type; 78 } 79 80 public String getValue() 81 { 82 return value; 83 } 84 85 public void setValue(String value) 86 { 87 this.value = value; 88 } 89 90 public void importEjbJarXml(Element element) throws DeploymentException 91 { 92 name = MetaData.getElementContent(MetaData.getUniqueChild(element, "env-entry-name")); 93 type = MetaData.getElementContent(MetaData.getUniqueChild(element, "env-entry-type")); 94 type = type.trim(); 96 value = MetaData.getElementContent(MetaData.getUniqueChild(element, "env-entry-value")); 97 } 98 99 public static void bindEnvEntry(Context ctx, EnvEntryMetaData entry) 100 throws ClassNotFoundException , NamingException 101 { 102 ClassLoader loader = EnvEntryMetaData.class.getClassLoader(); 103 Class type = loader.loadClass(entry.getType()); 104 if (type == String .class) 105 { 106 Util.bind(ctx, entry.getName(), entry.getValue()); 107 } 108 else if (type == Integer .class) 109 { 110 Util.bind(ctx, entry.getName(), new Integer (entry.getValue())); 111 } 112 else if (type == Long .class) 113 { 114 Util.bind(ctx, entry.getName(), new Long (entry.getValue())); 115 } 116 else if (type == Double .class) 117 { 118 Util.bind(ctx, entry.getName(), new Double (entry.getValue())); 119 } 120 else if (type == Float .class) 121 { 122 Util.bind(ctx, entry.getName(), new Float (entry.getValue())); 123 } 124 else if (type == Byte .class) 125 { 126 Util.bind(ctx, entry.getName(), new Byte (entry.getValue())); 127 } 128 else if (type == Character .class) 129 { 130 Object value = null; 131 String input = entry.getValue(); 132 if (input == null || input.length() == 0) 133 { 134 value = new Character ((char) 0); 135 } 136 else 137 { 138 value = new Character (input.charAt(0)); 139 } 140 Util.bind(ctx, entry.getName(), value); 141 } 142 else if (type == Short .class) 143 { 144 Util.bind(ctx, entry.getName(), new Short (entry.getValue())); 145 } 146 else if (type == Boolean .class) 147 { 148 Util.bind(ctx, entry.getName(), new Boolean (entry.getValue())); 149 } 150 else 151 { 152 Util.bind(ctx, entry.getName(), entry.getValue()); 154 } 155 } 156 157 } 158 | Popular Tags |