KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > naming > deployment > EnvironmentEntryBuilder


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.naming.deployment;
19
20 import java.util.Map JavaDoc;
21
22 import javax.xml.namespace.QName JavaDoc;
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 /**
39  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
40  */

41 public class EnvironmentEntryBuilder extends AbstractNamingBuilder {
42
43     private final QNameSet envEntryQNameSet;
44
45     public EnvironmentEntryBuilder(String JavaDoc[] 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 JavaDoc 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 JavaDoc name = envEntry.getEnvEntryName().getStringValue().trim();
59             String JavaDoc type = envEntry.getEnvEntryType().getStringValue().trim();
60             String JavaDoc text = envEntry.getEnvEntryValue().getStringValue().trim();
61             try {
62                 Object JavaDoc 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 JavaDoc(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 JavaDoc 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 JavaDoc[].class, true, true);
111         infoBuilder.setConstructor(new String JavaDoc[] {"eeNamespaces"});
112
113         GBEAN_INFO = infoBuilder.getBeanInfo();
114     }
115
116     public static GBeanInfo getGBeanInfo() {
117         return GBEAN_INFO;
118     }
119
120 }
121
Popular Tags