KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > event > descriptors > 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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 package com.sun.enterprise.tools.guiframework.event.descriptors;
23
24 import com.iplanet.jato.RequestContext;
25 import com.iplanet.jato.view.View;
26
27 import com.sun.enterprise.tools.guiframework.FrameworkDescriptor;
28 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
29 import com.sun.enterprise.tools.guiframework.util.Util;
30
31 import java.util.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33
34
35 /**
36  * This class describes an input or output parameter.
37  */

38 public class IODescriptor implements FrameworkDescriptor {
39
40     /**
41      * Constructor.
42      *
43      * @param name The name of the input/output field
44      * @param type The type of the input/output field
45      */

46     public IODescriptor(String JavaDoc name, String JavaDoc type) {
47     setName(name);
48     setType(type);
49     }
50
51
52     /**
53      * This method returns the name for this handler definition.
54      */

55     public String JavaDoc getName() {
56     if (_name == null) {
57         throw new FrameworkException("Name cannot be null!");
58     }
59     return _name;
60     }
61
62
63     /**
64      * This method sets the handler definitions name (used by the contsrutor).
65      */

66     protected void setName(String JavaDoc name) {
67     _name = name;
68     }
69
70
71     /**
72      * For future tool support
73      */

74     public String JavaDoc getDescription() {
75     return _description;
76     }
77
78
79     /**
80      * For future tool support
81      */

82     public void setDescription(String JavaDoc desc) {
83     _description = desc;
84     }
85
86
87     /**
88      * This method returns the type for this parameter
89      */

90     public Class JavaDoc getType() {
91     return _type;
92     }
93
94
95     /**
96      * This method sets the type for this parameter
97      */

98     public void setType(Class JavaDoc type) {
99     _type = type;
100     }
101
102
103     /**
104      * This method sets the type for this parameter
105      */

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

128     public Object JavaDoc getDefault() {
129     return _default;
130     }
131
132
133     /**
134      * This method sets the default for this parameter (valid for input only)
135      */

136     public void setDefault(Object JavaDoc def) {
137     _default = def;
138     }
139
140
141     // The following provides some basic pre-defined types
142
private static Map JavaDoc _typeMap = new HashMap JavaDoc();
143     static {
144     _typeMap.put("boolean", Boolean JavaDoc.class);
145     _typeMap.put("Boolean", Boolean JavaDoc.class);
146     _typeMap.put("byte", Byte JavaDoc.class);
147     _typeMap.put("Byte", Byte JavaDoc.class);
148     _typeMap.put("char", Character JavaDoc.class);
149     _typeMap.put("Character", Character JavaDoc.class);
150     _typeMap.put("double", Double JavaDoc.class);
151     _typeMap.put("Double", Double JavaDoc.class);
152     _typeMap.put("float", Float JavaDoc.class);
153     _typeMap.put("Float", Float JavaDoc.class);
154     _typeMap.put("int", Integer JavaDoc.class);
155     _typeMap.put("Integer", Integer JavaDoc.class);
156     _typeMap.put("long", Long JavaDoc.class);
157     _typeMap.put("Long", Long JavaDoc.class);
158     _typeMap.put("short", Short JavaDoc.class);
159     _typeMap.put("Short", Short JavaDoc.class);
160     _typeMap.put("char[]", String JavaDoc.class);
161     _typeMap.put("String", String JavaDoc.class);
162     _typeMap.put("Object", Object JavaDoc.class);
163     }
164
165     private String JavaDoc _name = null;
166     private String JavaDoc _description = null;
167     private Class JavaDoc _type = Object JavaDoc.class;
168     private Object JavaDoc _default = null;
169 }
170
Popular Tags