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-2006 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:
042: package org.netbeans.modules.j2ee.sun.validation.constraints.data;
043:
044: import org.w3c.dom.*;
045: import org.netbeans.modules.schema2beans.*;
046: import java.beans.*;
047: import java.util.*;
048:
049: // BEGIN_NOI18N
050:
051: public class CheckInfo extends
052: org.netbeans.modules.schema2beans.BaseBean {
053:
054: static Vector comparators = new Vector();
055:
056: static public final String NAME = "Name"; // NOI18N
057: static public final String CLASSNAME = "Classname"; // NOI18N
058: static public final String ARGUMENTS = "Arguments"; // NOI18N
059:
060: public CheckInfo() {
061: this (Common.USE_DEFAULT_VALUES);
062: }
063:
064: public CheckInfo(int options) {
065: super (comparators,
066: new org.netbeans.modules.schema2beans.Version(1, 2, 0));
067: // Properties (see root bean comments for the bean graph)
068: this .createProperty("name", // NOI18N
069: NAME, Common.TYPE_1 | Common.TYPE_STRING
070: | Common.TYPE_KEY, String.class);
071: this .createProperty("classname", // NOI18N
072: CLASSNAME, Common.TYPE_1 | Common.TYPE_STRING
073: | Common.TYPE_KEY, String.class);
074: this .createProperty("arguments", // NOI18N
075: ARGUMENTS, Common.TYPE_0_1 | Common.TYPE_BEAN
076: | Common.TYPE_KEY, Arguments.class);
077: this .initialize(options);
078: }
079:
080: // Setting the default values of the properties
081: void initialize(int options) {
082:
083: }
084:
085: // This attribute is mandatory
086: public void setName(String value) {
087: this .setValue(NAME, value);
088: }
089:
090: //
091: public String getName() {
092: return (String) this .getValue(NAME);
093: }
094:
095: // This attribute is mandatory
096: public void setClassname(String value) {
097: this .setValue(CLASSNAME, value);
098: }
099:
100: //
101: public String getClassname() {
102: return (String) this .getValue(CLASSNAME);
103: }
104:
105: // This attribute is optional
106: public void setArguments(Arguments value) {
107: this .setValue(ARGUMENTS, value);
108: }
109:
110: //
111: public Arguments getArguments() {
112: return (Arguments) this .getValue(ARGUMENTS);
113: }
114:
115: //
116: public static void addComparator(
117: org.netbeans.modules.schema2beans.BeanComparator c) {
118: comparators.add(c);
119: }
120:
121: //
122: public static void removeComparator(
123: org.netbeans.modules.schema2beans.BeanComparator c) {
124: comparators.remove(c);
125: }
126:
127: public void validate()
128: throws org.netbeans.modules.schema2beans.ValidateException {
129: boolean restrictionFailure = false;
130: // Validating property name
131: if (getName() == null) {
132: throw new org.netbeans.modules.schema2beans.ValidateException(
133: "getName() == null", "name", this ); // NOI18N
134: }
135: // Validating property classname
136: if (getClassname() == null) {
137: throw new org.netbeans.modules.schema2beans.ValidateException(
138: "getClassname() == null", "classname", this ); // NOI18N
139: }
140: // Validating property arguments
141: if (getArguments() != null) {
142: getArguments().validate();
143: }
144: }
145:
146: // Dump the content of this bean returning it as a String
147: public void dump(StringBuffer str, String indent) {
148: String s;
149: Object o;
150: org.netbeans.modules.schema2beans.BaseBean n;
151: str.append(indent);
152: str.append("Name"); // NOI18N
153: str.append(indent + "\t"); // NOI18N
154: str.append("<"); // NOI18N
155: s = this .getName();
156: str.append((s == null ? "null" : s.trim())); // NOI18N
157: str.append(">\n"); // NOI18N
158: this .dumpAttributes(NAME, 0, str, indent);
159:
160: str.append(indent);
161: str.append("Classname"); // NOI18N
162: str.append(indent + "\t"); // NOI18N
163: str.append("<"); // NOI18N
164: s = this .getClassname();
165: str.append((s == null ? "null" : s.trim())); // NOI18N
166: str.append(">\n"); // NOI18N
167: this .dumpAttributes(CLASSNAME, 0, str, indent);
168:
169: str.append(indent);
170: str.append("Arguments"); // NOI18N
171: n = (org.netbeans.modules.schema2beans.BaseBean) this
172: .getArguments();
173: if (n != null)
174: n.dump(str, indent + "\t"); // NOI18N
175: else
176: str.append(indent + "\tnull"); // NOI18N
177: this .dumpAttributes(ARGUMENTS, 0, str, indent);
178:
179: }
180:
181: public String dumpBeanNode() {
182: StringBuffer str = new StringBuffer();
183: str.append("CheckInfo\n"); // NOI18N
184: this .dump(str, "\n "); // NOI18N
185: return str.toString();
186: }
187: }
188:
189: // END_NOI18N
190:
191: /*
192: The following schema file has been used for generation:
193:
194: <!--
195: XML DTD for for constraints xml.
196: constraints.xml is used to specify provide information of the
197: Constraints to the Validation framework.
198:
199: $Revision$
200: -->
201:
202:
203: <!--
204: This is the root element.
205: -->
206: <!ELEMENT constraints (check-info*)>
207:
208:
209: <!--
210: This represents an information, about a particular Constraint.
211: Provides information of a Constraint represented by corresponding
212: <check> element in validation.xml.
213: Sub element <name> is used to link this element with the
214: corresponding <check> element in validation.xml.
215: -->
216: <!ELEMENT check-info (name, classname, arguments?)>
217:
218:
219: <!--
220: This element represents information of a Constraint class arguments.
221: Number of sub elements, <argument> should match with the number
222: of <parameter> sub elements, of corresponding <arguments> element
223: in validation.xml
224: -->
225: <!ELEMENT arguments (argument+)>
226:
227:
228: <!--
229: This element represents information of a single Constraint class
230: argument.
231: Sub elements <name> should match with the <name> sub element of
232: corresponding <parameter> element in constraints.xml
233: -->
234: <!ELEMENT argument (name, type?)>
235:
236:
237: <!--
238: Used in two elements <check-info> and <argument>
239: In <check-info>, it represents a Constraint name and is the linking
240: element between <check> element in validation.xml and <check-info>
241: element in constraints.xml.
242: In <argument>, it represents argument name and is the linking element
243: between <parameter> element in validation.xml and <argument> element
244: in constraints.xml.
245: -->
246: <!ELEMENT name (#PCDATA)>
247:
248:
249: <!--
250: This element represents Constraint class name.
251: Constraint class should provide the constructor with no arguments.
252: Constraint class should also provide the set* methods for all the
253: required arguments.
254: Constraint class is always created using default constructor and
255: then the arguments are set using set* methods.
256: -->
257: <!ELEMENT classname (#PCDATA)>
258:
259:
260: <!--
261: This element represents the type of an argument.
262: If not specified, it defaults to java.lang.String
263: -->
264: <!ELEMENT type (#PCDATA)>
265:
266: */
|