1 17 18 package org.apache.geronimo.naming.deployment; 19 20 import java.util.Map ; 21 22 import javax.xml.namespace.QName ; 23 24 import org.apache.geronimo.common.DeploymentException; 25 import org.apache.geronimo.gbean.GBeanInfo; 26 import org.apache.geronimo.gbean.GBeanInfoBuilder; 27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 28 import org.apache.geronimo.j2ee.deployment.Module; 29 import org.apache.geronimo.j2ee.deployment.NamingBuilder; 30 import org.apache.geronimo.kernel.config.Configuration; 31 import org.apache.geronimo.kernel.repository.Environment; 32 import org.apache.geronimo.naming.reference.KernelReference; 33 import org.apache.geronimo.xbeans.j2ee.EnvEntryType; 34 import org.apache.geronimo.schema.NamespaceElementConverter; 35 import org.apache.xmlbeans.QNameSet; 36 import org.apache.xmlbeans.XmlObject; 37 38 41 public class EnvironmentEntryBuilder extends AbstractNamingBuilder { 42 43 private final QNameSet envEntryQNameSet; 44 45 public EnvironmentEntryBuilder(String [] eeNamespaces) { 46 envEntryQNameSet = buildQNameSet(eeNamespaces, "env-entry"); 47 } 48 public void buildEnvironment(XmlObject specDD, XmlObject plan, Environment environment) { 49 } 50 51 public void initContext(XmlObject specDD, XmlObject plan, Configuration localConfiguration, Configuration remoteConfiguration, Module module) throws DeploymentException { 52 } 53 54 public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration, Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException { 55 XmlObject[] envEntriesUntyped = convert(specDD.selectChildren(envEntryQNameSet), J2EE_CONVERTER, EnvEntryType.type); 56 for (int i = 0; i < envEntriesUntyped.length; i++) { 57 EnvEntryType envEntry = (EnvEntryType) envEntriesUntyped[i]; 58 String name = envEntry.getEnvEntryName().getStringValue().trim(); 59 String type = envEntry.getEnvEntryType().getStringValue().trim(); 60 String text = envEntry.getEnvEntryValue().getStringValue().trim(); 61 try { 62 Object value; 63 if (text == null) { 64 if ("org.apache.geronimo.kernel.Kernel".equals(type)) { 65 value = new KernelReference(); 66 } else { 67 value = null; 68 } 69 } else if ("java.lang.String".equals(type)) { 70 value = text; 71 } else if ("java.lang.Character".equals(type)) { 72 value = new Character (text.charAt(0)); 73 } else if ("java.lang.Boolean".equals(type)) { 74 value = Boolean.valueOf(text); 75 } else if ("java.lang.Byte".equals(type)) { 76 value = Byte.valueOf(text); 77 } else if ("java.lang.Short".equals(type)) { 78 value = Short.valueOf(text); 79 } else if ("java.lang.Integer".equals(type)) { 80 value = Integer.valueOf(text); 81 } else if ("java.lang.Long".equals(type)) { 82 value = Long.valueOf(text); 83 } else if ("java.lang.Float".equals(type)) { 84 value = Float.valueOf(text); 85 } else if ("java.lang.Double".equals(type)) { 86 value = Double.valueOf(text); 87 } else { 88 throw new DeploymentException("unrecognized type: " + type); 89 } 90 getJndiContextMap(componentContext).put(ENV + name, value); 91 } catch (NumberFormatException e) { 92 throw new DeploymentException("Invalid env-entry value for name: " + name, e); 93 } 94 } 95 96 } 97 98 public QNameSet getSpecQNameSet() { 99 return envEntryQNameSet; 100 } 101 102 public QNameSet getPlanQNameSet() { 103 return QNameSet.EMPTY; 104 } 105 106 public static final GBeanInfo GBEAN_INFO; 107 108 static { 109 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(EnvironmentEntryBuilder.class, NameFactory.MODULE_BUILDER); 110 infoBuilder.addAttribute("eeNamespaces", String [].class, true, true); 111 infoBuilder.setConstructor(new String [] {"eeNamespaces"}); 112 113 GBEAN_INFO = infoBuilder.getBeanInfo(); 114 } 115 116 public static GBeanInfo getGBeanInfo() { 117 return GBEAN_INFO; 118 } 119 120 } 121 | Popular Tags |