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: * Code 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: * This generated bean class MetaProperty
043: * matches the schema element 'meta-property'.
044: * The root bean class is MetaDD
045: *
046: * @Generated
047: */package org.netbeans.modules.schema2beansdev.metadd;
048:
049: public class MetaProperty implements
050: org.netbeans.modules.schema2beansdev.metadd.CommonBean {
051: public static final String BEAN_NAME = "BeanName"; // NOI18N
052: public static final String DEFAULT_VALUE = "DefaultValue"; // NOI18N
053: public static final String KNOWN_VALUE = "KnownValue"; // NOI18N
054: public static final String KEY = "Key"; // NOI18N
055: public static final String VETOABLE = "Vetoable"; // NOI18N
056:
057: private String _BeanName;
058: private java.util.List _DefaultValue = new java.util.ArrayList(); // List<String>
059: private java.util.List _KnownValue = new java.util.ArrayList(); // List<String>
060: private boolean _Key;
061: private boolean _isSet_Key = false;
062: private boolean _Vetoable;
063: private boolean _isSet_Vetoable = false;
064:
065: /**
066: * Normal starting point constructor.
067: */
068: public MetaProperty() {
069: _BeanName = "";
070: }
071:
072: /**
073: * Required parameters constructor
074: */
075: public MetaProperty(String beanName) {
076: _BeanName = beanName;
077: }
078:
079: /**
080: * Deep copy
081: */
082: public MetaProperty(
083: org.netbeans.modules.schema2beansdev.metadd.MetaProperty source) {
084: this (source, false);
085: }
086:
087: /**
088: * Deep copy
089: * @param justData just copy the XML relevant data
090: */
091: public MetaProperty(
092: org.netbeans.modules.schema2beansdev.metadd.MetaProperty source,
093: boolean justData) {
094: _BeanName = source._BeanName;
095: for (java.util.Iterator it = source._DefaultValue.iterator(); it
096: .hasNext();) {
097: String srcElement = (String) it.next();
098: _DefaultValue.add(srcElement);
099: }
100: for (java.util.Iterator it = source._KnownValue.iterator(); it
101: .hasNext();) {
102: String srcElement = (String) it.next();
103: _KnownValue.add(srcElement);
104: }
105: _Key = source._Key;
106: _isSet_Key = source._isSet_Key;
107: _Vetoable = source._Vetoable;
108: _isSet_Vetoable = source._isSet_Vetoable;
109: }
110:
111: // This attribute is mandatory
112: public void setBeanName(String value) {
113: _BeanName = value;
114: }
115:
116: public String getBeanName() {
117: return _BeanName;
118: }
119:
120: // This attribute is an array, possibly empty
121: public void setDefaultValue(String[] value) {
122: if (value == null)
123: value = new String[0];
124: _DefaultValue.clear();
125: ((java.util.ArrayList) _DefaultValue)
126: .ensureCapacity(value.length);
127: for (int i = 0; i < value.length; ++i) {
128: _DefaultValue.add(value[i]);
129: }
130: }
131:
132: public void setDefaultValue(int index, String value) {
133: _DefaultValue.set(index, value);
134: }
135:
136: public String[] getDefaultValue() {
137: String[] arr = new String[_DefaultValue.size()];
138: return (String[]) _DefaultValue.toArray(arr);
139: }
140:
141: public java.util.List fetchDefaultValueList() {
142: return _DefaultValue;
143: }
144:
145: public String getDefaultValue(int index) {
146: return (String) _DefaultValue.get(index);
147: }
148:
149: // Return the number of defaultValue
150: public int sizeDefaultValue() {
151: return _DefaultValue.size();
152: }
153:
154: public int addDefaultValue(String value) {
155: _DefaultValue.add(value);
156: int positionOfNewItem = _DefaultValue.size() - 1;
157: return positionOfNewItem;
158: }
159:
160: /**
161: * Search from the end looking for @param value, and then remove it.
162: */
163: public int removeDefaultValue(String value) {
164: int pos = _DefaultValue.indexOf(value);
165: if (pos >= 0) {
166: _DefaultValue.remove(pos);
167: }
168: return pos;
169: }
170:
171: // This attribute is an array, possibly empty
172: public void setKnownValue(String[] value) {
173: if (value == null)
174: value = new String[0];
175: _KnownValue.clear();
176: ((java.util.ArrayList) _KnownValue)
177: .ensureCapacity(value.length);
178: for (int i = 0; i < value.length; ++i) {
179: _KnownValue.add(value[i]);
180: }
181: }
182:
183: public void setKnownValue(int index, String value) {
184: _KnownValue.set(index, value);
185: }
186:
187: public String[] getKnownValue() {
188: String[] arr = new String[_KnownValue.size()];
189: return (String[]) _KnownValue.toArray(arr);
190: }
191:
192: public java.util.List fetchKnownValueList() {
193: return _KnownValue;
194: }
195:
196: public String getKnownValue(int index) {
197: return (String) _KnownValue.get(index);
198: }
199:
200: // Return the number of knownValue
201: public int sizeKnownValue() {
202: return _KnownValue.size();
203: }
204:
205: public int addKnownValue(String value) {
206: _KnownValue.add(value);
207: int positionOfNewItem = _KnownValue.size() - 1;
208: return positionOfNewItem;
209: }
210:
211: /**
212: * Search from the end looking for @param value, and then remove it.
213: */
214: public int removeKnownValue(String value) {
215: int pos = _KnownValue.indexOf(value);
216: if (pos >= 0) {
217: _KnownValue.remove(pos);
218: }
219: return pos;
220: }
221:
222: // This attribute is optional
223: public void setKey(boolean value) {
224: _Key = value;
225: _isSet_Key = true;
226: }
227:
228: public boolean isKey() {
229: return _Key;
230: }
231:
232: // This attribute is optional
233: public void setVetoable(boolean value) {
234: _Vetoable = value;
235: _isSet_Vetoable = true;
236: }
237:
238: public boolean isVetoable() {
239: return _Vetoable;
240: }
241:
242: public void writeNode(java.io.Writer out)
243: throws java.io.IOException {
244: String myName;
245: myName = "meta-property";
246: writeNode(out, myName, ""); // NOI18N
247: }
248:
249: public void writeNode(java.io.Writer out, String nodeName,
250: String indent) throws java.io.IOException {
251: writeNode(out, nodeName, null, indent, new java.util.HashMap());
252: }
253:
254: /**
255: * It's not recommended to call this method directly.
256: */
257: public void writeNode(java.io.Writer out, String nodeName,
258: String namespace, String indent, java.util.Map namespaceMap)
259: throws java.io.IOException {
260: out.write(indent);
261: out.write("<");
262: if (namespace != null) {
263: out.write((String) namespaceMap.get(namespace));
264: out.write(":");
265: }
266: out.write(nodeName);
267: out.write(">\n");
268: String nextIndent = indent + " ";
269: if (_BeanName != null) {
270: out.write(nextIndent);
271: out.write("<bean-name"); // NOI18N
272: out.write(">"); // NOI18N
273: org.netbeans.modules.schema2beansdev.metadd.MetaDD
274: .writeXML(out, _BeanName, false);
275: out.write("</bean-name>\n"); // NOI18N
276: }
277: for (java.util.Iterator it = _DefaultValue.iterator(); it
278: .hasNext();) {
279: String element = (String) it.next();
280: if (element != null) {
281: out.write(nextIndent);
282: out.write("<default-value"); // NOI18N
283: out.write(">"); // NOI18N
284: org.netbeans.modules.schema2beansdev.metadd.MetaDD
285: .writeXML(out, element, false);
286: out.write("</default-value>\n"); // NOI18N
287: }
288: }
289: for (java.util.Iterator it = _KnownValue.iterator(); it
290: .hasNext();) {
291: String element = (String) it.next();
292: if (element != null) {
293: out.write(nextIndent);
294: out.write("<known-value"); // NOI18N
295: out.write(">"); // NOI18N
296: org.netbeans.modules.schema2beansdev.metadd.MetaDD
297: .writeXML(out, element, false);
298: out.write("</known-value>\n"); // NOI18N
299: }
300: }
301: if (_isSet_Key) {
302: if (_Key) {
303: out.write(nextIndent);
304: out.write("<key"); // NOI18N
305: out.write("/>\n"); // NOI18N
306: }
307: }
308: if (_isSet_Vetoable) {
309: if (_Vetoable) {
310: out.write(nextIndent);
311: out.write("<vetoable"); // NOI18N
312: out.write("/>\n"); // NOI18N
313: }
314: }
315: out.write(indent);
316: out.write("</");
317: if (namespace != null) {
318: out.write((String) namespaceMap.get(namespace));
319: out.write(":");
320: }
321: out.write(nodeName);
322: out.write(">\n");
323: }
324:
325: public void readNode(org.w3c.dom.Node node) {
326: readNode(node, new java.util.HashMap());
327: }
328:
329: public void readNode(org.w3c.dom.Node node,
330: java.util.Map namespacePrefixes) {
331: if (node.hasAttributes()) {
332: org.w3c.dom.NamedNodeMap attrs = node.getAttributes();
333: org.w3c.dom.Attr attr;
334: java.lang.String attrValue;
335: boolean firstNamespaceDef = true;
336: for (int attrNum = 0; attrNum < attrs.getLength(); ++attrNum) {
337: attr = (org.w3c.dom.Attr) attrs.item(attrNum);
338: String attrName = attr.getName();
339: if (attrName.startsWith("xmlns:")) {
340: if (firstNamespaceDef) {
341: firstNamespaceDef = false;
342: // Dup prefix map, so as to not write over previous values, and to make it easy to clear out our entries.
343: namespacePrefixes = new java.util.HashMap(
344: namespacePrefixes);
345: }
346: String attrNSPrefix = attrName.substring(6,
347: attrName.length());
348: namespacePrefixes
349: .put(attrNSPrefix, attr.getValue());
350: }
351: }
352: }
353: org.w3c.dom.NodeList children = node.getChildNodes();
354: for (int i = 0, size = children.getLength(); i < size; ++i) {
355: org.w3c.dom.Node childNode = children.item(i);
356: String childNodeName = (childNode.getLocalName() == null ? childNode
357: .getNodeName().intern()
358: : childNode.getLocalName().intern());
359: String childNodeValue = "";
360: if (childNode.getFirstChild() != null) {
361: childNodeValue = childNode.getFirstChild()
362: .getNodeValue();
363: }
364: if (childNodeName == "bean-name") {
365: _BeanName = childNodeValue;
366: } else if (childNodeName == "default-value") {
367: String aDefaultValue;
368: aDefaultValue = childNodeValue;
369: _DefaultValue.add(aDefaultValue);
370: } else if (childNodeName == "known-value") {
371: String aKnownValue;
372: aKnownValue = childNodeValue;
373: _KnownValue.add(aKnownValue);
374: } else if (childNodeName == "key") {
375: if (childNode.getFirstChild() == null)
376: _Key = true;
377: else
378: _Key = java.lang.Boolean.valueOf(childNodeValue)
379: .booleanValue();
380: _isSet_Key = true;
381: } else if (childNodeName == "vetoable") {
382: if (childNode.getFirstChild() == null)
383: _Vetoable = true;
384: else
385: _Vetoable = java.lang.Boolean.valueOf(
386: childNodeValue).booleanValue();
387: _isSet_Vetoable = true;
388: } else {
389: // Found extra unrecognized childNode
390: }
391: }
392: }
393:
394: public void validate()
395: throws org.netbeans.modules.schema2beansdev.metadd.MetaDD.ValidateException {
396: boolean restrictionFailure = false;
397: boolean restrictionPassed = false;
398: // Validating property beanName
399: if (getBeanName() == null) {
400: throw new org.netbeans.modules.schema2beansdev.metadd.MetaDD.ValidateException(
401: "getBeanName() == null",
402: org.netbeans.modules.schema2beansdev.metadd.MetaDD.ValidateException.FailureType.NULL_VALUE,
403: "beanName", this ); // NOI18N
404: }
405: // Validating property defaultValue
406: // Validating property knownValue
407: // Validating property key
408: // Validating property vetoable
409: }
410:
411: public void changePropertyByName(String name, Object value) {
412: if (name == null)
413: return;
414: name = name.intern();
415: if (name == "beanName")
416: setBeanName((String) value);
417: else if (name == "defaultValue")
418: addDefaultValue((String) value);
419: else if (name == "defaultValue[]")
420: setDefaultValue((String[]) value);
421: else if (name == "knownValue")
422: addKnownValue((String) value);
423: else if (name == "knownValue[]")
424: setKnownValue((String[]) value);
425: else if (name == "key")
426: setKey(((java.lang.Boolean) value).booleanValue());
427: else if (name == "vetoable")
428: setVetoable(((java.lang.Boolean) value).booleanValue());
429: else
430: throw new IllegalArgumentException(name
431: + " is not a valid property name for MetaProperty");
432: }
433:
434: public Object fetchPropertyByName(String name) {
435: if (name == "beanName")
436: return getBeanName();
437: if (name == "defaultValue[]")
438: return getDefaultValue();
439: if (name == "knownValue[]")
440: return getKnownValue();
441: if (name == "key")
442: return (isKey() ? java.lang.Boolean.TRUE
443: : java.lang.Boolean.FALSE);
444: if (name == "vetoable")
445: return (isVetoable() ? java.lang.Boolean.TRUE
446: : java.lang.Boolean.FALSE);
447: throw new IllegalArgumentException(name
448: + " is not a valid property name for MetaProperty");
449: }
450:
451: public String nameSelf() {
452: return "MetaProperty";
453: }
454:
455: public String nameChild(Object childObj) {
456: return nameChild(childObj, false, false);
457: }
458:
459: /**
460: * @param childObj The child object to search for
461: * @param returnSchemaName Whether or not the schema name should be returned or the property name
462: * @return null if not found
463: */
464: public String nameChild(Object childObj, boolean returnConstName,
465: boolean returnSchemaName) {
466: return nameChild(childObj, returnConstName, returnSchemaName,
467: false);
468: }
469:
470: /**
471: * @param childObj The child object to search for
472: * @param returnSchemaName Whether or not the schema name should be returned or the property name
473: * @return null if not found
474: */
475: public String nameChild(Object childObj, boolean returnConstName,
476: boolean returnSchemaName, boolean returnXPathName) {
477: if (childObj instanceof java.lang.String) {
478: java.lang.String child = (java.lang.String) childObj;
479: if (child == _BeanName) {
480: if (returnConstName) {
481: return BEAN_NAME;
482: } else if (returnSchemaName) {
483: return "bean-name";
484: } else if (returnXPathName) {
485: return "bean-name";
486: } else {
487: return "BeanName";
488: }
489: }
490: int index = 0;
491: for (java.util.Iterator it = _DefaultValue.iterator(); it
492: .hasNext();) {
493: String element = (String) it.next();
494: if (child == element) {
495: if (returnConstName) {
496: return DEFAULT_VALUE;
497: } else if (returnSchemaName) {
498: return "default-value";
499: } else if (returnXPathName) {
500: return "default-value[position()=" + index
501: + "]";
502: } else {
503: return "DefaultValue."
504: + Integer.toHexString(index);
505: }
506: }
507: ++index;
508: }
509: index = 0;
510: for (java.util.Iterator it = _KnownValue.iterator(); it
511: .hasNext();) {
512: String element = (String) it.next();
513: if (child == element) {
514: if (returnConstName) {
515: return KNOWN_VALUE;
516: } else if (returnSchemaName) {
517: return "known-value";
518: } else if (returnXPathName) {
519: return "known-value[position()=" + index + "]";
520: } else {
521: return "KnownValue."
522: + Integer.toHexString(index);
523: }
524: }
525: ++index;
526: }
527: }
528: if (childObj instanceof java.lang.Boolean) {
529: java.lang.Boolean child = (java.lang.Boolean) childObj;
530: if (((java.lang.Boolean) child).booleanValue() == _Key) {
531: if (returnConstName) {
532: return KEY;
533: } else if (returnSchemaName) {
534: return "key";
535: } else if (returnXPathName) {
536: return "key";
537: } else {
538: return "Key";
539: }
540: }
541: if (((java.lang.Boolean) child).booleanValue() == _Vetoable) {
542: if (returnConstName) {
543: return VETOABLE;
544: } else if (returnSchemaName) {
545: return "vetoable";
546: } else if (returnXPathName) {
547: return "vetoable";
548: } else {
549: return "Vetoable";
550: }
551: }
552: }
553: return null;
554: }
555:
556: /**
557: * Return an array of all of the properties that are beans and are set.
558: */
559: public org.netbeans.modules.schema2beansdev.metadd.CommonBean[] childBeans(
560: boolean recursive) {
561: java.util.List children = new java.util.LinkedList();
562: childBeans(recursive, children);
563: org.netbeans.modules.schema2beansdev.metadd.CommonBean[] result = new org.netbeans.modules.schema2beansdev.metadd.CommonBean[children
564: .size()];
565: return (org.netbeans.modules.schema2beansdev.metadd.CommonBean[]) children
566: .toArray(result);
567: }
568:
569: /**
570: * Put all child beans into the beans list.
571: */
572: public void childBeans(boolean recursive, java.util.List beans) {
573: }
574:
575: public boolean equals(Object o) {
576: return o instanceof org.netbeans.modules.schema2beansdev.metadd.MetaProperty
577: && equals((org.netbeans.modules.schema2beansdev.metadd.MetaProperty) o);
578: }
579:
580: public boolean equals(
581: org.netbeans.modules.schema2beansdev.metadd.MetaProperty inst) {
582: if (inst == this ) {
583: return true;
584: }
585: if (inst == null) {
586: return false;
587: }
588: if (!(_BeanName == null ? inst._BeanName == null : _BeanName
589: .equals(inst._BeanName))) {
590: return false;
591: }
592: if (sizeDefaultValue() != inst.sizeDefaultValue())
593: return false;
594: // Compare every element.
595: for (java.util.Iterator it = _DefaultValue.iterator(), it2 = inst._DefaultValue
596: .iterator(); it.hasNext() && it2.hasNext();) {
597: String element = (String) it.next();
598: String element2 = (String) it2.next();
599: if (!(element == null ? element2 == null : element
600: .equals(element2))) {
601: return false;
602: }
603: }
604: if (sizeKnownValue() != inst.sizeKnownValue())
605: return false;
606: // Compare every element.
607: for (java.util.Iterator it = _KnownValue.iterator(), it2 = inst._KnownValue
608: .iterator(); it.hasNext() && it2.hasNext();) {
609: String element = (String) it.next();
610: String element2 = (String) it2.next();
611: if (!(element == null ? element2 == null : element
612: .equals(element2))) {
613: return false;
614: }
615: }
616: if (_isSet_Key != inst._isSet_Key) {
617: return false;
618: }
619: if (_isSet_Key) {
620: if (!(_Key == inst._Key)) {
621: return false;
622: }
623: }
624: if (_isSet_Vetoable != inst._isSet_Vetoable) {
625: return false;
626: }
627: if (_isSet_Vetoable) {
628: if (!(_Vetoable == inst._Vetoable)) {
629: return false;
630: }
631: }
632: return true;
633: }
634:
635: public int hashCode() {
636: int result = 17;
637: result = 37 * result
638: + (_BeanName == null ? 0 : _BeanName.hashCode());
639: result = 37
640: * result
641: + (_DefaultValue == null ? 0 : _DefaultValue.hashCode());
642: result = 37 * result
643: + (_KnownValue == null ? 0 : _KnownValue.hashCode());
644: result = 37 * result + (_isSet_Key ? 0 : (_Key ? 0 : 1));
645: result = 37 * result
646: + (_isSet_Vetoable ? 0 : (_Vetoable ? 0 : 1));
647: return result;
648: }
649:
650: public String toString() {
651: java.io.StringWriter sw = new java.io.StringWriter();
652: try {
653: writeNode(sw);
654: } catch (java.io.IOException e) {
655: // How can we actually get an IOException on a StringWriter?
656: throw new RuntimeException(e);
657: }
658: return sw.toString();
659: }
660:
661: }
662:
663: /*
664: The following schema file has been used for generation:
665:
666: <!-- This holds data about the schema that is not part of DTDs and/or XML Schemas.
667: -->
668:
669: <!--
670: -->
671: <!ELEMENT metaDD (meta-element*, implements?, extends?, import*, vetoable?, throw-exceptions?, schemaLocation?, finder*)>
672:
673: <!--
674: -->
675: <!ELEMENT meta-element (dtd-name, namespace?, bean-name?, bean-class?, wrapper-class?, default-value*, known-value*, meta-property*, comparator-class*, implements?, extends?, import*, user-code?, vetoable?, skip-generation?, delegator-name?, delegator-extends?, bean-interface-extends?, can-be-empty?>
676:
677: <!--
678: -->
679: <!ELEMENT meta-property (bean-name, default-value*, known-value*, key?, vetoable?)>
680:
681: <!ELEMENT delegator-name (#PCDATA)>
682:
683: <!--
684: -->
685: <!ELEMENT implements (#PCDATA)>
686:
687: <!--
688: -->
689: <!ELEMENT extends (#PCDATA)>
690:
691: <!--
692: -->
693: <!ELEMENT import (#PCDATA)>
694:
695: <!--
696: -->
697: <!ELEMENT dtd-name (#PCDATA)>
698:
699: <!ELEMENT namespace (#PCDATA)>
700:
701: <!--
702: -->
703: <!ELEMENT default-value (#PCDATA)>
704:
705: <!--
706: -->
707: <!ELEMENT skip-generation EMPTY>
708:
709: <!--
710: -->
711: <!ELEMENT key EMPTY>
712:
713: <!--
714: -->
715: <!ELEMENT vetoable EMPTY>
716:
717: <!--
718: -->
719: <!ELEMENT known-value (#PCDATA)>
720:
721: <!--
722: -->
723: <!ELEMENT bean-name (#PCDATA)>
724:
725: <!--
726: -->
727: <!ELEMENT bean-class (#PCDATA)>
728:
729: <!--
730: -->
731: <!ELEMENT wrapper-class (#PCDATA)>
732:
733: <!--
734: -->
735: <!ELEMENT comparator-class (#PCDATA)>
736:
737: <!--
738: -->
739: <!ELEMENT user-code (#PCDATA)>
740:
741: <!ELEMENT throw-exceptions EMPTY>
742:
743: <!-- Automatically set the schemaLocation -->
744: <!ELEMENT schemaLocation (#PCDATA)>
745:
746: <!ELEMENT finder (#PCDATA)>
747:
748: <!ELEMENT bean-interface-extends (#PCDATA)>
749:
750: <!ELEMENT can-be-empty EMPTY>
751:
752: */
|