001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.component.util.event;
042:
043: import java.util.HashMap;
044: import java.util.Map;
045:
046: /**
047: * This class describes an input or output parameter.
048: *
049: * @author Ken Paulsen (ken.paulsen@sun.com)
050: */
051: public class IODescriptor implements java.io.Serializable {
052:
053: /**
054: * Constructor.
055: *
056: * @param name The name of the input/output field
057: * @param type The type of the input/output field
058: */
059: public IODescriptor(String name, String type) {
060: setName(name);
061: setType(type);
062: }
063:
064: /**
065: * This method returns the name for this handler definition.
066: */
067: public String getName() {
068: if (_name == null) {
069: throw new NullPointerException("Name cannot be null!");
070: }
071: return _name;
072: }
073:
074: /**
075: * This method sets the handler definitions name (used by the contsrutor).
076: */
077: protected void setName(String name) {
078: _name = name;
079: }
080:
081: /**
082: * For future tool support
083: */
084: public String getDescription() {
085: return _description;
086: }
087:
088: /**
089: * For future tool support
090: */
091: public void setDescription(String desc) {
092: _description = desc;
093: }
094:
095: /**
096: * This method returns the type for this parameter
097: */
098: public Class getType() {
099: return _type;
100: }
101:
102: /**
103: * This method sets the type for this parameter
104: */
105: public void setType(Class type) {
106: _type = type;
107: }
108:
109: /**
110: * This method sets the type for this parameter
111: */
112: public void setType(String type) {
113: if ((type == null) || (type.trim().length() == 0)) {
114: return;
115: }
116: Class cls = (Class) _typeMap.get(type);
117: if (cls == null) {
118: try {
119: cls = Class.forName(type);
120: } catch (Exception ex) {
121: throw new RuntimeException(
122: "Unable to determine parameter type '" + type
123: + "' for parameter named '" + getName()
124: + "'.", ex);
125: }
126: }
127: _type = cls;
128: }
129:
130: /**
131: * This method returns the default for this parameter (valid for input
132: * only)
133: */
134: public Object getDefault() {
135: return _default;
136: }
137:
138: /**
139: * This method sets the default for this parameter (valid for input only)
140: */
141: public void setDefault(Object def) {
142: _default = def;
143: }
144:
145: /**
146: * This method returns the default for this parameter (valid for input
147: * only)
148: */
149: public boolean isRequired() {
150: return _required;
151: }
152:
153: /**
154: * <P> This method specifies whether this Input field is required.</P>
155: */
156: public void setRequired(boolean required) {
157: _required = required;
158: }
159:
160: // The following provides some basic pre-defined types
161: private static Map _typeMap = new HashMap();
162: static {
163: _typeMap.put("boolean", Boolean.class);
164: _typeMap.put("Boolean", Boolean.class);
165: _typeMap.put("byte", Byte.class);
166: _typeMap.put("Byte", Byte.class);
167: _typeMap.put("char", Character.class);
168: _typeMap.put("Character", Character.class);
169: _typeMap.put("double", Double.class);
170: _typeMap.put("Double", Double.class);
171: _typeMap.put("float", Float.class);
172: _typeMap.put("Float", Float.class);
173: _typeMap.put("int", Integer.class);
174: _typeMap.put("Integer", Integer.class);
175: _typeMap.put("long", Long.class);
176: _typeMap.put("Long", Long.class);
177: _typeMap.put("short", Short.class);
178: _typeMap.put("Short", Short.class);
179: _typeMap.put("char[]", String.class);
180: _typeMap.put("String", String.class);
181: _typeMap.put("Object", Object.class);
182: }
183:
184: private String _name = null;
185: private String _description = null;
186: private Object _default = null; // Input only
187: private Class _type = Object.class;
188: private boolean _required = false; // Input only
189:
190: private static final long serialVersionUID = 0xA9B8C7D6E5F40312L;
191: }
|