KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > EnvEntryMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata;
23
24 import javax.naming.Context JavaDoc;
25 import javax.naming.NamingException JavaDoc;
26
27 import org.w3c.dom.Element JavaDoc;
28
29 import org.jboss.deployment.DeploymentException;
30 import org.jboss.naming.Util;
31
32 /**
33  * <description>
34  *
35  * @see <related>
36  * @author <a HREF="mailto:sebastien.alborini@m4x.org">Sebastien Alborini </a>
37  * @version $Revision: 57300 $
38  */

39 public class EnvEntryMetaData extends Ref
40 {
41     // Constants -----------------------------------------------------
42

43     // Attributes ----------------------------------------------------
44
private String JavaDoc name;
45
46     private String JavaDoc type;
47
48     private String JavaDoc value;
49
50     // Static --------------------------------------------------------
51

52     // Constructors --------------------------------------------------
53
public EnvEntryMetaData()
54     {
55     }
56
57     // Public --------------------------------------------------------
58

59
60     public String JavaDoc getName()
61    {
62       return name;
63    }
64
65    public void setName(String JavaDoc name)
66    {
67       this.name = name;
68    }
69
70    public String JavaDoc getType()
71    {
72       return type;
73    }
74
75    public void setType(String JavaDoc type)
76    {
77       this.type = type;
78    }
79
80    public String JavaDoc getValue()
81    {
82       return value;
83    }
84
85    public void setValue(String JavaDoc value)
86    {
87       this.value = value;
88    }
89
90    public void importEjbJarXml(Element JavaDoc 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       // Strip any surrounding spaces
95
type = type.trim();
96       value = MetaData.getElementContent(MetaData.getUniqueChild(element, "env-entry-value"));
97    }
98
99    public static void bindEnvEntry(Context JavaDoc ctx, EnvEntryMetaData entry)
100       throws ClassNotFoundException JavaDoc, NamingException JavaDoc
101     {
102         ClassLoader JavaDoc loader = EnvEntryMetaData.class.getClassLoader();
103         Class JavaDoc type = loader.loadClass(entry.getType());
104         if (type == String JavaDoc.class)
105         {
106             Util.bind(ctx, entry.getName(), entry.getValue());
107         }
108         else if (type == Integer JavaDoc.class)
109         {
110             Util.bind(ctx, entry.getName(), new Integer JavaDoc(entry.getValue()));
111         }
112         else if (type == Long JavaDoc.class)
113         {
114             Util.bind(ctx, entry.getName(), new Long JavaDoc(entry.getValue()));
115         }
116         else if (type == Double JavaDoc.class)
117         {
118             Util.bind(ctx, entry.getName(), new Double JavaDoc(entry.getValue()));
119         }
120         else if (type == Float JavaDoc.class)
121         {
122             Util.bind(ctx, entry.getName(), new Float JavaDoc(entry.getValue()));
123         }
124         else if (type == Byte JavaDoc.class)
125         {
126             Util.bind(ctx, entry.getName(), new Byte JavaDoc(entry.getValue()));
127         }
128         else if (type == Character JavaDoc.class)
129         {
130             Object JavaDoc value = null;
131             String JavaDoc input = entry.getValue();
132             if (input == null || input.length() == 0)
133             {
134                 value = new Character JavaDoc((char) 0);
135             }
136             else
137             {
138                 value = new Character JavaDoc(input.charAt(0));
139             }
140             Util.bind(ctx, entry.getName(), value);
141         }
142         else if (type == Short JavaDoc.class)
143         {
144             Util.bind(ctx, entry.getName(), new Short JavaDoc(entry.getValue()));
145         }
146         else if (type == Boolean JavaDoc.class)
147         {
148             Util.bind(ctx, entry.getName(), new Boolean JavaDoc(entry.getValue()));
149         }
150         else
151         {
152             // Default to a String type
153
Util.bind(ctx, entry.getName(), entry.getValue());
154         }
155     }
156
157 }
158
Popular Tags