KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > jsfext > event > handlers > IODescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.jsfext.event.handlers;
24
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
27
28
29 /**
30  * <p> This class describes an input or output parameter.</p>
31  *
32  * @author Ken Paulsen (ken.paulsen@sun.com)
33  */

34 public class IODescriptor implements java.io.Serializable JavaDoc {
35
36     /**
37      * <p> Constructor.</p>
38      *
39      * @param name The name of the input/output field.
40      * @param type The type of the input/output field.
41      */

42     public IODescriptor(String JavaDoc name, String JavaDoc type) {
43     setName(name);
44     setType(type);
45     }
46
47
48     /**
49      * <p> This method returns the name for this handler definition.</p>
50      */

51     public String JavaDoc getName() {
52     if (_name == null) {
53         throw new NullPointerException JavaDoc("Name cannot be null!");
54     }
55     return _name;
56     }
57
58
59     /**
60      * <p> This method sets the handler definitions name (used by the
61      * contsrutor).</p>
62      */

63     protected void setName(String JavaDoc name) {
64     _name = name;
65     }
66
67
68     /**
69      * <p> For future tool support.</p>
70      */

71     public String JavaDoc getDescription() {
72     return _description;
73     }
74
75
76     /**
77      * <p> For future tool support.</p>
78      */

79     public void setDescription(String JavaDoc desc) {
80     _description = desc;
81     }
82
83
84     /**
85      * <p> This method returns the type for this parameter.</p>
86      */

87     public Class JavaDoc getType() {
88     return _type;
89     }
90
91
92     /**
93      * <p> This method sets the type for this parameter.</p>
94      */

95     public void setType(Class JavaDoc type) {
96     _type = type;
97     }
98
99
100     /**
101      * <p> This method sets the type for this parameter.</p>
102      */

103     public void setType(String JavaDoc type) {
104     if ((type == null) || (type.trim().length() == 0)) {
105         return;
106     }
107     Class JavaDoc cls = (Class JavaDoc) _typeMap.get(type);
108     if (cls == null) {
109         try {
110         cls = Class.forName(type);
111         } catch (Exception JavaDoc ex) {
112         throw new RuntimeException JavaDoc(
113             "Unable to determine parameter type '" + type +
114             "' for parameter named '" + getName() + "'.", ex);
115         }
116     }
117     _type = cls;
118     }
119
120
121     /**
122      * <p> This method returns the default for this parameter (valid for input
123      * only).</p>
124      */

125     public Object JavaDoc getDefault() {
126     return _default;
127     }
128
129
130     /**
131      * <p> This method sets the default for this parameter (valid for input
132      * only).</p>
133      */

134     public void setDefault(Object JavaDoc def) {
135     _default = def;
136     }
137
138     /**
139      * <p> This method inidicates if the input is required (valid for input
140      * only).</p>
141      */

142     public boolean isRequired() {
143     return _required;
144     }
145
146     /**
147      * <p> This method specifies whether this input field is required.</p>
148      */

149     public void setRequired(boolean required) {
150     _required = required;
151     }
152
153     // The following provides some basic pre-defined types
154
private static Map JavaDoc _typeMap = new HashMap JavaDoc();
155     static {
156     _typeMap.put("boolean", Boolean JavaDoc.class);
157     _typeMap.put("Boolean", Boolean JavaDoc.class);
158     _typeMap.put("byte", Byte JavaDoc.class);
159     _typeMap.put("Byte", Byte JavaDoc.class);
160     _typeMap.put("char", Character JavaDoc.class);
161     _typeMap.put("Character", Character JavaDoc.class);
162     _typeMap.put("double", Double JavaDoc.class);
163     _typeMap.put("Double", Double JavaDoc.class);
164     _typeMap.put("float", Float JavaDoc.class);
165     _typeMap.put("Float", Float JavaDoc.class);
166     _typeMap.put("int", Integer JavaDoc.class);
167     _typeMap.put("Integer", Integer JavaDoc.class);
168     _typeMap.put("long", Long JavaDoc.class);
169     _typeMap.put("Long", Long JavaDoc.class);
170     _typeMap.put("short", Short JavaDoc.class);
171     _typeMap.put("Short", Short JavaDoc.class);
172     _typeMap.put("char[]", String JavaDoc.class);
173     _typeMap.put("String", String JavaDoc.class);
174     _typeMap.put("Object", Object JavaDoc.class);
175     }
176
177     private String JavaDoc _name = null;
178     private String JavaDoc _description = null;
179     private Object JavaDoc _default = null; // Input only
180
private Class JavaDoc _type = Object JavaDoc.class;
181     private boolean _required = false; // Input only
182

183     private static final long serialVersionUID = 0xA9B8C7D6E5F40312L;
184 }
185
Popular Tags