1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.geronimo.naming.deployment; 20 21 import java.util.Map; 22 23 import javax.xml.namespace.QName; 24 25 import org.apache.geronimo.common.DeploymentException; 26 import org.apache.geronimo.gbean.GBeanInfo; 27 import org.apache.geronimo.gbean.GBeanInfoBuilder; 28 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 29 import org.apache.geronimo.j2ee.deployment.Module; 30 import org.apache.geronimo.j2ee.deployment.NamingBuilder; 31 import org.apache.geronimo.kernel.config.Configuration; 32 import org.apache.geronimo.kernel.repository.Environment; 33 import org.apache.geronimo.naming.reference.KernelReference; 34 import org.apache.geronimo.xbeans.j2ee.EnvEntryType; 35 import org.apache.xmlbeans.QNameSet; 36 import org.apache.xmlbeans.XmlObject; 37 38 /** 39 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $ 40 */ 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 = specDD.selectChildren(envEntryQNameSet); 56 for (int i = 0; i < envEntriesUntyped.length; i++) { 57 EnvEntryType envEntry = (EnvEntryType) envEntriesUntyped[i].copy().changeType(EnvEntryType.type); 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 }