KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > utils > xml > EnvEntryDesc


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Christophe Ney
22  * --------------------------------------------------------------------------
23  * $Id: EnvEntryDesc.java,v 1.1 2003/10/27 14:46:32 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package com.bull.eclipse.jonas.utils.xml;
28
29
30 /**
31  * This class represents the description of an EnvEntry object
32  * @author Christophe Ney
33  * @author Florent Benoit
34  */

35 public class EnvEntryDesc {
36
37     /**
38      * The env entry name.
39      */

40     private String JavaDoc name;
41     
42     /**
43      * The env entry type.
44      */

45     private Class JavaDoc type;
46
47     /**
48      * The env entry value.
49      */

50     private Object JavaDoc value;
51
52     /**
53      * Construct a descriptor for an env-entry tag.
54      * @param env the env-entry resulting of the xml parsing.
55      * @throws DeploymentDescException when missing information for
56      * creating the EnvEntryDesc.
57      */

58 // public EnvEntryDesc(EnvEntry env) throws DeploymentDescException {
59
// name = env.getEnvEntryName();
60
// String t = env.getEnvEntryType();
61
// String v = (env.getEnvEntryValue() != null) ? env.getEnvEntryValue() : null;
62
// try {
63
// if (t.equals(Boolean.class.getName())) {
64
// type = Boolean.class;
65
// if (v != null) {
66
// if (v.equalsIgnoreCase("true")) {
67
// value = Boolean.TRUE;
68
// } else if (v.equalsIgnoreCase("false")) {
69
// value = Boolean.FALSE;
70
// } else {
71
// throw new DeploymentDescException(v + " is not a valid value for env-entry " + name);
72
// }
73
// }
74
// } else if (t.equals(String.class.getName())) {
75
// type = String.class;
76
// value = v;
77
// } else if (t.equals(Integer.class.getName())) {
78
// type = Integer.class;
79
// value = (v != null) ? new Integer(v) : null;
80
// } else if (t.equals(Double.class.getName())) {
81
// type = Double.class;
82
// value = (v != null) ? new Double(v) : null;
83
// } else if (t.equals(Byte.class.getName())) {
84
// type = Byte.class;
85
// value = (v != null) ? new Byte(v) : null;
86
// } else if (t.equals(Short.class.getName())) {
87
// type = Short.class;
88
// value = (v != null) ? new Short(v) : null;
89
// } else if (t.equals(Long.class.getName())) {
90
// type = Long.class;
91
// value = (v != null) ? new Long(v) : null;
92
// } else if (t.equals(Float.class.getName())) {
93
// type = Float.class;
94
// value = (v != null) ? new Float(v) : null;
95
// } else {
96
// throw new DeploymentDescException(t + " is not a valid type for env-entry " + name);
97
// }
98
// } catch (NumberFormatException e) {
99
// throw new DeploymentDescException(v + " is not a valid value for env-entry " + name, e);
100
// }
101
//
102
// }
103

104     /**
105      * Get the name of the environemt entry.
106      * @return Name for environment entry
107      */

108     public String JavaDoc getName() {
109             return name;
110     }
111
112     /**
113      * Get the fully-qualified Java type of the environemt entry.
114      * Type is needed since value is optional
115      * The possibles values are:
116      * java.lang.Boolean
117      * java.lang.String
118      * java.lang.Integer
119      * java.lang.Double
120      * java.lang.Byte
121      * java.lang.Short
122      * java.lang.Long
123      * java.lang.Float
124      * @return Class the fully-qualified Java type of the environemt entry.
125      */

126     public Class JavaDoc getType() {
127             return type;
128     }
129
130     /**
131      * Assessor for existence of value for the descriptor
132      * @return true if a value is available
133      */

134     public boolean hasValue() {
135             return value != null;
136     }
137
138     /**
139      * Get the value of the environment entry.
140      * @return value for the environment entry (must be set)
141      */

142     public Object JavaDoc getValue() {
143         if (value == null) {
144             throw new Error JavaDoc("Value not set for env-entry " + name);
145         }
146         return value;
147     }
148
149     /**
150      * String representation of the object for test purpose
151      * @return String representation of this object
152      */

153     public String JavaDoc toString() {
154         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
155         ret.append("\ngetName()=" + getName());
156         ret.append("\ngetType()=" + getType());
157         if (hasValue()) {
158             ret.append("\ngetValue()=" + getValue().toString());
159         }
160         return ret.toString();
161     }
162     
163 }
164
Popular Tags