0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: /**
0042: * This generated bean class MetaDD
0043: * matches the schema element 'metaDD'.
0044: *
0045: *
0046: * This class matches the root element of the DTD,
0047: * and is the root of the bean graph.
0048: *
0049: * metaDD <metaDD> : MetaDD
0050: * metaElement <meta-element> : MetaElement[0,n]
0051: * dtdName <dtd-name> : String
0052: * namespace <namespace> : String[0,1]
0053: * beanName <bean-name> : String[0,1]
0054: * beanClass <bean-class> : String[0,1]
0055: * wrapperClass <wrapper-class> : String[0,1]
0056: * defaultValue <default-value> : String[0,n]
0057: * knownValue <known-value> : String[0,n]
0058: * metaProperty <meta-property> : MetaProperty[0,n]
0059: * beanName <bean-name> : String
0060: * defaultValue <default-value> : String[0,n]
0061: * knownValue <known-value> : String[0,n]
0062: * key <key> : boolean[0,1]
0063: * EMPTY : String
0064: * vetoable <vetoable> : boolean[0,1]
0065: * EMPTY : String
0066: * comparatorClass <comparator-class> : String[0,n]
0067: * implements <implements> : String[0,1]
0068: * extends <extends> : String[0,1]
0069: * import <import> : String[0,n]
0070: * userCode <user-code> : String[0,1]
0071: * vetoable <vetoable> : boolean[0,1]
0072: * EMPTY : String
0073: * skipGeneration <skip-generation> : boolean[0,1]
0074: * EMPTY : String
0075: * delegatorName <delegator-name> : String[0,1]
0076: * delegatorExtends <delegator-extends> : String[0,1]
0077: * beanInterfaceExtends <bean-interface-extends> : String[0,1]
0078: * canBeEmpty <can-be-empty> : boolean[0,1]
0079: * EMPTY : String
0080: * implements <implements> : String[0,1]
0081: * extends <extends> : String[0,1]
0082: * import <import> : String[0,n]
0083: * vetoable <vetoable> : boolean[0,1]
0084: * EMPTY : String
0085: * throwExceptions <throw-exceptions> : boolean[0,1]
0086: * EMPTY : String
0087: * schemaLocation <schemaLocation> : String[0,1]
0088: * finder <finder> : String[0,n]
0089: *
0090: * @Generated
0091: */package org.netbeans.modules.schema2beansdev.metadd;
0092:
0093: public class MetaDD implements
0094: org.netbeans.modules.schema2beansdev.metadd.CommonBean {
0095: public static final String META_ELEMENT = "MetaElement"; // NOI18N
0096: public static final String IMPLEMENTS = "Implements"; // NOI18N
0097: public static final String EXTENDS = "Extends"; // NOI18N
0098: public static final String IMPORT = "Import"; // NOI18N
0099: public static final String VETOABLE = "Vetoable"; // NOI18N
0100: public static final String THROW_EXCEPTIONS = "ThrowExceptions"; // NOI18N
0101: public static final String SCHEMALOCATION = "SchemaLocation"; // NOI18N
0102: public static final String FINDER = "Finder"; // NOI18N
0103:
0104: private java.util.List _MetaElement = new java.util.ArrayList(); // List<MetaElement>
0105: private String _Implements;
0106: private String _Extends;
0107: private java.util.List _Import = new java.util.ArrayList(); // List<String>
0108: private boolean _Vetoable;
0109: private boolean _isSet_Vetoable = false;
0110: private boolean _ThrowExceptions;
0111: private boolean _isSet_ThrowExceptions = false;
0112: private String _SchemaLocation;
0113: private java.util.List _Finder = new java.util.ArrayList(); // List<String>
0114: private java.lang.String schemaLocation;
0115:
0116: /**
0117: * Normal starting point constructor.
0118: */
0119: public MetaDD() {
0120: }
0121:
0122: /**
0123: * Deep copy
0124: */
0125: public MetaDD(
0126: org.netbeans.modules.schema2beansdev.metadd.MetaDD source) {
0127: this (source, false);
0128: }
0129:
0130: /**
0131: * Deep copy
0132: * @param justData just copy the XML relevant data
0133: */
0134: public MetaDD(
0135: org.netbeans.modules.schema2beansdev.metadd.MetaDD source,
0136: boolean justData) {
0137: for (java.util.Iterator it = source._MetaElement.iterator(); it
0138: .hasNext();) {
0139: org.netbeans.modules.schema2beansdev.metadd.MetaElement srcElement = (org.netbeans.modules.schema2beansdev.metadd.MetaElement) it
0140: .next();
0141: _MetaElement.add((srcElement == null) ? null
0142: : newMetaElement(srcElement, justData));
0143: }
0144: _Implements = source._Implements;
0145: _Extends = source._Extends;
0146: for (java.util.Iterator it = source._Import.iterator(); it
0147: .hasNext();) {
0148: String srcElement = (String) it.next();
0149: _Import.add(srcElement);
0150: }
0151: _Vetoable = source._Vetoable;
0152: _isSet_Vetoable = source._isSet_Vetoable;
0153: _ThrowExceptions = source._ThrowExceptions;
0154: _isSet_ThrowExceptions = source._isSet_ThrowExceptions;
0155: _SchemaLocation = source._SchemaLocation;
0156: for (java.util.Iterator it = source._Finder.iterator(); it
0157: .hasNext();) {
0158: String srcElement = (String) it.next();
0159: _Finder.add(srcElement);
0160: }
0161: schemaLocation = source.schemaLocation;
0162: }
0163:
0164: // This attribute is an array, possibly empty
0165: public void setMetaElement(
0166: org.netbeans.modules.schema2beansdev.metadd.MetaElement[] value) {
0167: if (value == null)
0168: value = new MetaElement[0];
0169: _MetaElement.clear();
0170: ((java.util.ArrayList) _MetaElement)
0171: .ensureCapacity(value.length);
0172: for (int i = 0; i < value.length; ++i) {
0173: _MetaElement.add(value[i]);
0174: }
0175: }
0176:
0177: public void setMetaElement(
0178: int index,
0179: org.netbeans.modules.schema2beansdev.metadd.MetaElement value) {
0180: _MetaElement.set(index, value);
0181: }
0182:
0183: public org.netbeans.modules.schema2beansdev.metadd.MetaElement[] getMetaElement() {
0184: MetaElement[] arr = new MetaElement[_MetaElement.size()];
0185: return (MetaElement[]) _MetaElement.toArray(arr);
0186: }
0187:
0188: public java.util.List fetchMetaElementList() {
0189: return _MetaElement;
0190: }
0191:
0192: public org.netbeans.modules.schema2beansdev.metadd.MetaElement getMetaElement(
0193: int index) {
0194: return (MetaElement) _MetaElement.get(index);
0195: }
0196:
0197: // Return the number of metaElement
0198: public int sizeMetaElement() {
0199: return _MetaElement.size();
0200: }
0201:
0202: public int addMetaElement(
0203: org.netbeans.modules.schema2beansdev.metadd.MetaElement value) {
0204: _MetaElement.add(value);
0205: int positionOfNewItem = _MetaElement.size() - 1;
0206: return positionOfNewItem;
0207: }
0208:
0209: /**
0210: * Search from the end looking for @param value, and then remove it.
0211: */
0212: public int removeMetaElement(
0213: org.netbeans.modules.schema2beansdev.metadd.MetaElement value) {
0214: int pos = _MetaElement.indexOf(value);
0215: if (pos >= 0) {
0216: _MetaElement.remove(pos);
0217: }
0218: return pos;
0219: }
0220:
0221: // This attribute is optional
0222: public void setImplements(String value) {
0223: _Implements = value;
0224: }
0225:
0226: public String getImplements() {
0227: return _Implements;
0228: }
0229:
0230: // This attribute is optional
0231: public void setExtends(String value) {
0232: _Extends = value;
0233: }
0234:
0235: public String getExtends() {
0236: return _Extends;
0237: }
0238:
0239: // This attribute is an array, possibly empty
0240: public void setImport(String[] value) {
0241: if (value == null)
0242: value = new String[0];
0243: _Import.clear();
0244: ((java.util.ArrayList) _Import).ensureCapacity(value.length);
0245: for (int i = 0; i < value.length; ++i) {
0246: _Import.add(value[i]);
0247: }
0248: }
0249:
0250: public void setImport(int index, String value) {
0251: _Import.set(index, value);
0252: }
0253:
0254: public String[] getImport() {
0255: String[] arr = new String[_Import.size()];
0256: return (String[]) _Import.toArray(arr);
0257: }
0258:
0259: public java.util.List fetchImportList() {
0260: return _Import;
0261: }
0262:
0263: public String getImport(int index) {
0264: return (String) _Import.get(index);
0265: }
0266:
0267: // Return the number of import
0268: public int sizeImport() {
0269: return _Import.size();
0270: }
0271:
0272: public int addImport(String value) {
0273: _Import.add(value);
0274: int positionOfNewItem = _Import.size() - 1;
0275: return positionOfNewItem;
0276: }
0277:
0278: /**
0279: * Search from the end looking for @param value, and then remove it.
0280: */
0281: public int removeImport(String value) {
0282: int pos = _Import.indexOf(value);
0283: if (pos >= 0) {
0284: _Import.remove(pos);
0285: }
0286: return pos;
0287: }
0288:
0289: // This attribute is optional
0290: public void setVetoable(boolean value) {
0291: _Vetoable = value;
0292: _isSet_Vetoable = true;
0293: }
0294:
0295: public boolean isVetoable() {
0296: return _Vetoable;
0297: }
0298:
0299: // This attribute is optional
0300: public void setThrowExceptions(boolean value) {
0301: _ThrowExceptions = value;
0302: _isSet_ThrowExceptions = true;
0303: }
0304:
0305: public boolean isThrowExceptions() {
0306: return _ThrowExceptions;
0307: }
0308:
0309: // This attribute is optional
0310: public void setSchemaLocation(String value) {
0311: _SchemaLocation = value;
0312: }
0313:
0314: public String getSchemaLocation() {
0315: return _SchemaLocation;
0316: }
0317:
0318: // This attribute is an array, possibly empty
0319: public void setFinder(String[] value) {
0320: if (value == null)
0321: value = new String[0];
0322: _Finder.clear();
0323: ((java.util.ArrayList) _Finder).ensureCapacity(value.length);
0324: for (int i = 0; i < value.length; ++i) {
0325: _Finder.add(value[i]);
0326: }
0327: }
0328:
0329: public void setFinder(int index, String value) {
0330: _Finder.set(index, value);
0331: }
0332:
0333: public String[] getFinder() {
0334: String[] arr = new String[_Finder.size()];
0335: return (String[]) _Finder.toArray(arr);
0336: }
0337:
0338: public java.util.List fetchFinderList() {
0339: return _Finder;
0340: }
0341:
0342: public String getFinder(int index) {
0343: return (String) _Finder.get(index);
0344: }
0345:
0346: // Return the number of finder
0347: public int sizeFinder() {
0348: return _Finder.size();
0349: }
0350:
0351: public int addFinder(String value) {
0352: _Finder.add(value);
0353: int positionOfNewItem = _Finder.size() - 1;
0354: return positionOfNewItem;
0355: }
0356:
0357: /**
0358: * Search from the end looking for @param value, and then remove it.
0359: */
0360: public int removeFinder(String value) {
0361: int pos = _Finder.indexOf(value);
0362: if (pos >= 0) {
0363: _Finder.remove(pos);
0364: }
0365: return pos;
0366: }
0367:
0368: public void _setSchemaLocation(String location) {
0369: schemaLocation = location;
0370: }
0371:
0372: public String _getSchemaLocation() {
0373: return schemaLocation;
0374: }
0375:
0376: /**
0377: * Create a new bean using it's default constructor.
0378: * This does not add it to any bean graph.
0379: */
0380: public org.netbeans.modules.schema2beansdev.metadd.MetaElement newMetaElement() {
0381: return new org.netbeans.modules.schema2beansdev.metadd.MetaElement();
0382: }
0383:
0384: /**
0385: * Create a new bean, copying from another one.
0386: * This does not add it to any bean graph.
0387: */
0388: public org.netbeans.modules.schema2beansdev.metadd.MetaElement newMetaElement(
0389: MetaElement source, boolean justData) {
0390: return new org.netbeans.modules.schema2beansdev.metadd.MetaElement(
0391: source, justData);
0392: }
0393:
0394: public void write(java.io.File f) throws java.io.IOException {
0395: java.io.OutputStream out = new java.io.FileOutputStream(f);
0396: try {
0397: write(out);
0398: } finally {
0399: out.close();
0400: }
0401: }
0402:
0403: public void write(java.io.OutputStream out)
0404: throws java.io.IOException {
0405: write(out, null);
0406: }
0407:
0408: public void write(java.io.OutputStream out, String encoding)
0409: throws java.io.IOException {
0410: java.io.Writer w;
0411: if (encoding == null) {
0412: encoding = "UTF-8"; // NOI18N
0413: }
0414: w = new java.io.BufferedWriter(new java.io.OutputStreamWriter(
0415: out, encoding));
0416: write(w, encoding);
0417: w.flush();
0418: }
0419:
0420: /**
0421: * Print this Java Bean to @param out including an XML header.
0422: * @param encoding is the encoding style that @param out was opened with.
0423: */
0424: public void write(java.io.Writer out, String encoding)
0425: throws java.io.IOException {
0426: out.write("<?xml version='1.0'"); // NOI18N
0427: if (encoding != null)
0428: out.write(" encoding='" + encoding + "'"); // NOI18N
0429: out.write(" ?>\n"); // NOI18N
0430: writeNode(out, "metaDD", ""); // NOI18N
0431: }
0432:
0433: public void writeNode(java.io.Writer out)
0434: throws java.io.IOException {
0435: String myName;
0436: myName = "metaDD";
0437: writeNode(out, myName, ""); // NOI18N
0438: }
0439:
0440: public void writeNode(java.io.Writer out, String nodeName,
0441: String indent) throws java.io.IOException {
0442: writeNode(out, nodeName, null, indent, new java.util.HashMap());
0443: }
0444:
0445: /**
0446: * It's not recommended to call this method directly.
0447: */
0448: public void writeNode(java.io.Writer out, String nodeName,
0449: String namespace, String indent, java.util.Map namespaceMap)
0450: throws java.io.IOException {
0451: out.write(indent);
0452: out.write("<");
0453: if (namespace != null) {
0454: out.write((String) namespaceMap.get(namespace));
0455: out.write(":");
0456: }
0457: out.write(nodeName);
0458: if (schemaLocation != null) {
0459: namespaceMap.put(
0460: "http://www.w3.org/2001/XMLSchema-instance", "xsi");
0461: out
0462: .write(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='");
0463: out.write(schemaLocation);
0464: out.write("'"); // NOI18N
0465: }
0466: out.write(">\n");
0467: String nextIndent = indent + " ";
0468: for (java.util.Iterator it = _MetaElement.iterator(); it
0469: .hasNext();) {
0470: org.netbeans.modules.schema2beansdev.metadd.MetaElement element = (org.netbeans.modules.schema2beansdev.metadd.MetaElement) it
0471: .next();
0472: if (element != null) {
0473: element.writeNode(out, "meta-element", null,
0474: nextIndent, namespaceMap);
0475: }
0476: }
0477: if (_Implements != null) {
0478: out.write(nextIndent);
0479: out.write("<implements"); // NOI18N
0480: out.write(">"); // NOI18N
0481: org.netbeans.modules.schema2beansdev.metadd.MetaDD
0482: .writeXML(out, _Implements, false);
0483: out.write("</implements>\n"); // NOI18N
0484: }
0485: if (_Extends != null) {
0486: out.write(nextIndent);
0487: out.write("<extends"); // NOI18N
0488: out.write(">"); // NOI18N
0489: org.netbeans.modules.schema2beansdev.metadd.MetaDD
0490: .writeXML(out, _Extends, false);
0491: out.write("</extends>\n"); // NOI18N
0492: }
0493: for (java.util.Iterator it = _Import.iterator(); it.hasNext();) {
0494: String element = (String) it.next();
0495: if (element != null) {
0496: out.write(nextIndent);
0497: out.write("<import"); // NOI18N
0498: out.write(">"); // NOI18N
0499: org.netbeans.modules.schema2beansdev.metadd.MetaDD
0500: .writeXML(out, element, false);
0501: out.write("</import>\n"); // NOI18N
0502: }
0503: }
0504: if (_isSet_Vetoable) {
0505: if (_Vetoable) {
0506: out.write(nextIndent);
0507: out.write("<vetoable"); // NOI18N
0508: out.write("/>\n"); // NOI18N
0509: }
0510: }
0511: if (_isSet_ThrowExceptions) {
0512: if (_ThrowExceptions) {
0513: out.write(nextIndent);
0514: out.write("<throw-exceptions"); // NOI18N
0515: out.write("/>\n"); // NOI18N
0516: }
0517: }
0518: if (_SchemaLocation != null) {
0519: out.write(nextIndent);
0520: out.write("<schemaLocation"); // NOI18N
0521: out.write(">"); // NOI18N
0522: org.netbeans.modules.schema2beansdev.metadd.MetaDD
0523: .writeXML(out, _SchemaLocation, false);
0524: out.write("</schemaLocation>\n"); // NOI18N
0525: }
0526: for (java.util.Iterator it = _Finder.iterator(); it.hasNext();) {
0527: String element = (String) it.next();
0528: if (element != null) {
0529: out.write(nextIndent);
0530: out.write("<finder"); // NOI18N
0531: out.write(">"); // NOI18N
0532: org.netbeans.modules.schema2beansdev.metadd.MetaDD
0533: .writeXML(out, element, false);
0534: out.write("</finder>\n"); // NOI18N
0535: }
0536: }
0537: out.write(indent);
0538: out.write("</");
0539: if (namespace != null) {
0540: out.write((String) namespaceMap.get(namespace));
0541: out.write(":");
0542: }
0543: out.write(nodeName);
0544: out.write(">\n");
0545: }
0546:
0547: public static MetaDD read(java.io.File f)
0548: throws javax.xml.parsers.ParserConfigurationException,
0549: org.xml.sax.SAXException, java.io.IOException {
0550: java.io.InputStream in = new java.io.FileInputStream(f);
0551: try {
0552: return read(in);
0553: } finally {
0554: in.close();
0555: }
0556: }
0557:
0558: public static MetaDD read(java.io.InputStream in)
0559: throws javax.xml.parsers.ParserConfigurationException,
0560: org.xml.sax.SAXException, java.io.IOException {
0561: return read(new org.xml.sax.InputSource(in), false, null, null);
0562: }
0563:
0564: /**
0565: * Warning: in readNoEntityResolver character and entity references will
0566: * not be read from any DTD in the XML source.
0567: * However, this way is faster since no DTDs are looked up
0568: * (possibly skipping network access) or parsed.
0569: */
0570: public static MetaDD readNoEntityResolver(java.io.InputStream in)
0571: throws javax.xml.parsers.ParserConfigurationException,
0572: org.xml.sax.SAXException, java.io.IOException {
0573: return read(new org.xml.sax.InputSource(in), false,
0574: new org.xml.sax.EntityResolver() {
0575: public org.xml.sax.InputSource resolveEntity(
0576: String publicId, String systemId) {
0577: java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream(
0578: new byte[0]);
0579: return new org.xml.sax.InputSource(bin);
0580: }
0581: }, null);
0582: }
0583:
0584: public static MetaDD read(org.xml.sax.InputSource in,
0585: boolean validate, org.xml.sax.EntityResolver er,
0586: org.xml.sax.ErrorHandler eh)
0587: throws javax.xml.parsers.ParserConfigurationException,
0588: org.xml.sax.SAXException, java.io.IOException {
0589: javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory
0590: .newInstance();
0591: dbf.setValidating(validate);
0592: dbf.setNamespaceAware(true);
0593: javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
0594: if (er != null)
0595: db.setEntityResolver(er);
0596: if (eh != null)
0597: db.setErrorHandler(eh);
0598: org.w3c.dom.Document doc = db.parse(in);
0599: return read(doc);
0600: }
0601:
0602: public static MetaDD read(org.w3c.dom.Document document) {
0603: MetaDD aMetaDD = new MetaDD();
0604: aMetaDD.readFromDocument(document);
0605: return aMetaDD;
0606: }
0607:
0608: protected void readFromDocument(org.w3c.dom.Document document) {
0609: readNode(document.getDocumentElement());
0610: }
0611:
0612: public void readNode(org.w3c.dom.Node node) {
0613: readNode(node, new java.util.HashMap());
0614: }
0615:
0616: public void readNode(org.w3c.dom.Node node,
0617: java.util.Map namespacePrefixes) {
0618: if (node.hasAttributes()) {
0619: org.w3c.dom.NamedNodeMap attrs = node.getAttributes();
0620: org.w3c.dom.Attr attr;
0621: java.lang.String attrValue;
0622: boolean firstNamespaceDef = true;
0623: for (int attrNum = 0; attrNum < attrs.getLength(); ++attrNum) {
0624: attr = (org.w3c.dom.Attr) attrs.item(attrNum);
0625: String attrName = attr.getName();
0626: if (attrName.startsWith("xmlns:")) {
0627: if (firstNamespaceDef) {
0628: firstNamespaceDef = false;
0629: // Dup prefix map, so as to not write over previous values, and to make it easy to clear out our entries.
0630: namespacePrefixes = new java.util.HashMap(
0631: namespacePrefixes);
0632: }
0633: String attrNSPrefix = attrName.substring(6,
0634: attrName.length());
0635: namespacePrefixes
0636: .put(attrNSPrefix, attr.getValue());
0637: }
0638: }
0639: String xsiPrefix = "xsi";
0640: for (java.util.Iterator it = namespacePrefixes.keySet()
0641: .iterator(); it.hasNext();) {
0642: String prefix = (String) it.next();
0643: String ns = (String) namespacePrefixes.get(prefix);
0644: if ("http://www.w3.org/2001/XMLSchema-instance"
0645: .equals(ns)) {
0646: xsiPrefix = prefix;
0647: break;
0648: }
0649: }
0650: attr = (org.w3c.dom.Attr) attrs.getNamedItem("" + xsiPrefix
0651: + ":schemaLocation");
0652: if (attr != null) {
0653: attrValue = attr.getValue();
0654: schemaLocation = attrValue;
0655: }
0656: }
0657: org.w3c.dom.NodeList children = node.getChildNodes();
0658: for (int i = 0, size = children.getLength(); i < size; ++i) {
0659: org.w3c.dom.Node childNode = children.item(i);
0660: String childNodeName = (childNode.getLocalName() == null ? childNode
0661: .getNodeName().intern()
0662: : childNode.getLocalName().intern());
0663: String childNodeValue = "";
0664: if (childNode.getFirstChild() != null) {
0665: childNodeValue = childNode.getFirstChild()
0666: .getNodeValue();
0667: }
0668: if (childNodeName == "meta-element") {
0669: MetaElement aMetaElement = newMetaElement();
0670: aMetaElement.readNode(childNode, namespacePrefixes);
0671: _MetaElement.add(aMetaElement);
0672: } else if (childNodeName == "implements") {
0673: _Implements = childNodeValue;
0674: } else if (childNodeName == "extends") {
0675: _Extends = childNodeValue;
0676: } else if (childNodeName == "import") {
0677: String aImport;
0678: aImport = childNodeValue;
0679: _Import.add(aImport);
0680: } else if (childNodeName == "vetoable") {
0681: if (childNode.getFirstChild() == null)
0682: _Vetoable = true;
0683: else
0684: _Vetoable = java.lang.Boolean.valueOf(
0685: childNodeValue).booleanValue();
0686: _isSet_Vetoable = true;
0687: } else if (childNodeName == "throw-exceptions") {
0688: if (childNode.getFirstChild() == null)
0689: _ThrowExceptions = true;
0690: else
0691: _ThrowExceptions = java.lang.Boolean.valueOf(
0692: childNodeValue).booleanValue();
0693: _isSet_ThrowExceptions = true;
0694: } else if (childNodeName == "schemaLocation") {
0695: _SchemaLocation = childNodeValue;
0696: } else if (childNodeName == "finder") {
0697: String aFinder;
0698: aFinder = childNodeValue;
0699: _Finder.add(aFinder);
0700: } else {
0701: // Found extra unrecognized childNode
0702: }
0703: }
0704: }
0705:
0706: /**
0707: * Takes some text to be printed into an XML stream and escapes any
0708: * characters that might make it invalid XML (like '<').
0709: */
0710: public static void writeXML(java.io.Writer out, String msg)
0711: throws java.io.IOException {
0712: writeXML(out, msg, true);
0713: }
0714:
0715: public static void writeXML(java.io.Writer out, String msg,
0716: boolean attribute) throws java.io.IOException {
0717: if (msg == null)
0718: return;
0719: int msgLength = msg.length();
0720: for (int i = 0; i < msgLength; ++i) {
0721: char c = msg.charAt(i);
0722: writeXML(out, c, attribute);
0723: }
0724: }
0725:
0726: public static void writeXML(java.io.Writer out, char msg,
0727: boolean attribute) throws java.io.IOException {
0728: if (msg == '&')
0729: out.write("&");
0730: else if (msg == '<')
0731: out.write("<");
0732: else if (msg == '>')
0733: out.write(">");
0734: else if (attribute) {
0735: if (msg == '"')
0736: out.write(""");
0737: else if (msg == '\'')
0738: out.write("'");
0739: else if (msg == '\n')
0740: out.write("
");
0741: else if (msg == '\t')
0742: out.write("	");
0743: else
0744: out.write(msg);
0745: } else
0746: out.write(msg);
0747: }
0748:
0749: public static class ValidateException extends Exception {
0750: private org.netbeans.modules.schema2beansdev.metadd.CommonBean failedBean;
0751: private String failedPropertyName;
0752: private FailureType failureType;
0753:
0754: public ValidateException(
0755: String msg,
0756: String failedPropertyName,
0757: org.netbeans.modules.schema2beansdev.metadd.CommonBean failedBean) {
0758: super (msg);
0759: this .failedBean = failedBean;
0760: this .failedPropertyName = failedPropertyName;
0761: }
0762:
0763: public ValidateException(
0764: String msg,
0765: FailureType ft,
0766: String failedPropertyName,
0767: org.netbeans.modules.schema2beansdev.metadd.CommonBean failedBean) {
0768: super (msg);
0769: this .failureType = ft;
0770: this .failedBean = failedBean;
0771: this .failedPropertyName = failedPropertyName;
0772: }
0773:
0774: public String getFailedPropertyName() {
0775: return failedPropertyName;
0776: }
0777:
0778: public FailureType getFailureType() {
0779: return failureType;
0780: }
0781:
0782: public org.netbeans.modules.schema2beansdev.metadd.CommonBean getFailedBean() {
0783: return failedBean;
0784: }
0785:
0786: public static class FailureType {
0787: private final String name;
0788:
0789: private FailureType(String name) {
0790: this .name = name;
0791: }
0792:
0793: public String toString() {
0794: return name;
0795: }
0796:
0797: public static final FailureType NULL_VALUE = new FailureType(
0798: "NULL_VALUE");
0799: public static final FailureType DATA_RESTRICTION = new FailureType(
0800: "DATA_RESTRICTION");
0801: public static final FailureType ENUM_RESTRICTION = new FailureType(
0802: "ENUM_RESTRICTION");
0803: public static final FailureType ALL_RESTRICTIONS = new FailureType(
0804: "ALL_RESTRICTIONS");
0805: public static final FailureType MUTUALLY_EXCLUSIVE = new FailureType(
0806: "MUTUALLY_EXCLUSIVE");
0807: }
0808: }
0809:
0810: public void validate()
0811: throws org.netbeans.modules.schema2beansdev.metadd.MetaDD.ValidateException {
0812: boolean restrictionFailure = false;
0813: boolean restrictionPassed = false;
0814: // Validating property metaElement
0815: for (int _index = 0; _index < sizeMetaElement(); ++_index) {
0816: org.netbeans.modules.schema2beansdev.metadd.MetaElement element = getMetaElement(_index);
0817: if (element != null) {
0818: element.validate();
0819: }
0820: }
0821: // Validating property implements
0822: // Validating property extends
0823: // Validating property import
0824: // Validating property vetoable
0825: // Validating property throwExceptions
0826: // Validating property schemaLocation
0827: // Validating property finder
0828: }
0829:
0830: public void changePropertyByName(String name, Object value) {
0831: if (name == null)
0832: return;
0833: name = name.intern();
0834: if (name == "metaElement")
0835: addMetaElement((MetaElement) value);
0836: else if (name == "metaElement[]")
0837: setMetaElement((MetaElement[]) value);
0838: else if (name == "implements")
0839: setImplements((String) value);
0840: else if (name == "extends")
0841: setExtends((String) value);
0842: else if (name == "import")
0843: addImport((String) value);
0844: else if (name == "import[]")
0845: setImport((String[]) value);
0846: else if (name == "vetoable")
0847: setVetoable(((java.lang.Boolean) value).booleanValue());
0848: else if (name == "throwExceptions")
0849: setThrowExceptions(((java.lang.Boolean) value)
0850: .booleanValue());
0851: else if (name == "schemaLocation")
0852: setSchemaLocation((String) value);
0853: else if (name == "finder")
0854: addFinder((String) value);
0855: else if (name == "finder[]")
0856: setFinder((String[]) value);
0857: else
0858: throw new IllegalArgumentException(name
0859: + " is not a valid property name for MetaDD");
0860: }
0861:
0862: public Object fetchPropertyByName(String name) {
0863: if (name == "metaElement[]")
0864: return getMetaElement();
0865: if (name == "implements")
0866: return getImplements();
0867: if (name == "extends")
0868: return getExtends();
0869: if (name == "import[]")
0870: return getImport();
0871: if (name == "vetoable")
0872: return (isVetoable() ? java.lang.Boolean.TRUE
0873: : java.lang.Boolean.FALSE);
0874: if (name == "throwExceptions")
0875: return (isThrowExceptions() ? java.lang.Boolean.TRUE
0876: : java.lang.Boolean.FALSE);
0877: if (name == "schemaLocation")
0878: return getSchemaLocation();
0879: if (name == "finder[]")
0880: return getFinder();
0881: throw new IllegalArgumentException(name
0882: + " is not a valid property name for MetaDD");
0883: }
0884:
0885: public String nameSelf() {
0886: return "/MetaDD";
0887: }
0888:
0889: public String nameChild(Object childObj) {
0890: return nameChild(childObj, false, false);
0891: }
0892:
0893: /**
0894: * @param childObj The child object to search for
0895: * @param returnSchemaName Whether or not the schema name should be returned or the property name
0896: * @return null if not found
0897: */
0898: public String nameChild(Object childObj, boolean returnConstName,
0899: boolean returnSchemaName) {
0900: return nameChild(childObj, returnConstName, returnSchemaName,
0901: false);
0902: }
0903:
0904: /**
0905: * @param childObj The child object to search for
0906: * @param returnSchemaName Whether or not the schema name should be returned or the property name
0907: * @return null if not found
0908: */
0909: public String nameChild(Object childObj, boolean returnConstName,
0910: boolean returnSchemaName, boolean returnXPathName) {
0911: if (childObj instanceof java.lang.String) {
0912: java.lang.String child = (java.lang.String) childObj;
0913: if (child == _Implements) {
0914: if (returnConstName) {
0915: return IMPLEMENTS;
0916: } else if (returnSchemaName) {
0917: return "implements";
0918: } else if (returnXPathName) {
0919: return "implements";
0920: } else {
0921: return "Implements";
0922: }
0923: }
0924: if (child == _Extends) {
0925: if (returnConstName) {
0926: return EXTENDS;
0927: } else if (returnSchemaName) {
0928: return "extends";
0929: } else if (returnXPathName) {
0930: return "extends";
0931: } else {
0932: return "Extends";
0933: }
0934: }
0935: int index = 0;
0936: for (java.util.Iterator it = _Import.iterator(); it
0937: .hasNext();) {
0938: String element = (String) it.next();
0939: if (child == element) {
0940: if (returnConstName) {
0941: return IMPORT;
0942: } else if (returnSchemaName) {
0943: return "import";
0944: } else if (returnXPathName) {
0945: return "import[position()=" + index + "]";
0946: } else {
0947: return "Import." + Integer.toHexString(index);
0948: }
0949: }
0950: ++index;
0951: }
0952: if (child == _SchemaLocation) {
0953: if (returnConstName) {
0954: return SCHEMALOCATION;
0955: } else if (returnSchemaName) {
0956: return "schemaLocation";
0957: } else if (returnXPathName) {
0958: return "schemaLocation";
0959: } else {
0960: return "SchemaLocation";
0961: }
0962: }
0963: index = 0;
0964: for (java.util.Iterator it = _Finder.iterator(); it
0965: .hasNext();) {
0966: String element = (String) it.next();
0967: if (child == element) {
0968: if (returnConstName) {
0969: return FINDER;
0970: } else if (returnSchemaName) {
0971: return "finder";
0972: } else if (returnXPathName) {
0973: return "finder[position()=" + index + "]";
0974: } else {
0975: return "Finder." + Integer.toHexString(index);
0976: }
0977: }
0978: ++index;
0979: }
0980: }
0981: if (childObj instanceof MetaElement) {
0982: MetaElement child = (MetaElement) childObj;
0983: int index = 0;
0984: for (java.util.Iterator it = _MetaElement.iterator(); it
0985: .hasNext();) {
0986: org.netbeans.modules.schema2beansdev.metadd.MetaElement element = (org.netbeans.modules.schema2beansdev.metadd.MetaElement) it
0987: .next();
0988: if (child == element) {
0989: if (returnConstName) {
0990: return META_ELEMENT;
0991: } else if (returnSchemaName) {
0992: return "meta-element";
0993: } else if (returnXPathName) {
0994: return "meta-element[position()=" + index + "]";
0995: } else {
0996: return "MetaElement."
0997: + Integer.toHexString(index);
0998: }
0999: }
1000: ++index;
1001: }
1002: }
1003: if (childObj instanceof java.lang.Boolean) {
1004: java.lang.Boolean child = (java.lang.Boolean) childObj;
1005: if (((java.lang.Boolean) child).booleanValue() == _Vetoable) {
1006: if (returnConstName) {
1007: return VETOABLE;
1008: } else if (returnSchemaName) {
1009: return "vetoable";
1010: } else if (returnXPathName) {
1011: return "vetoable";
1012: } else {
1013: return "Vetoable";
1014: }
1015: }
1016: if (((java.lang.Boolean) child).booleanValue() == _ThrowExceptions) {
1017: if (returnConstName) {
1018: return THROW_EXCEPTIONS;
1019: } else if (returnSchemaName) {
1020: return "throw-exceptions";
1021: } else if (returnXPathName) {
1022: return "throw-exceptions";
1023: } else {
1024: return "ThrowExceptions";
1025: }
1026: }
1027: }
1028: return null;
1029: }
1030:
1031: /**
1032: * Return an array of all of the properties that are beans and are set.
1033: */
1034: public org.netbeans.modules.schema2beansdev.metadd.CommonBean[] childBeans(
1035: boolean recursive) {
1036: java.util.List children = new java.util.LinkedList();
1037: childBeans(recursive, children);
1038: org.netbeans.modules.schema2beansdev.metadd.CommonBean[] result = new org.netbeans.modules.schema2beansdev.metadd.CommonBean[children
1039: .size()];
1040: return (org.netbeans.modules.schema2beansdev.metadd.CommonBean[]) children
1041: .toArray(result);
1042: }
1043:
1044: /**
1045: * Put all child beans into the beans list.
1046: */
1047: public void childBeans(boolean recursive, java.util.List beans) {
1048: for (java.util.Iterator it = _MetaElement.iterator(); it
1049: .hasNext();) {
1050: org.netbeans.modules.schema2beansdev.metadd.MetaElement element = (org.netbeans.modules.schema2beansdev.metadd.MetaElement) it
1051: .next();
1052: if (element != null) {
1053: if (recursive) {
1054: element.childBeans(true, beans);
1055: }
1056: beans.add(element);
1057: }
1058: }
1059: }
1060:
1061: public boolean equals(Object o) {
1062: return o instanceof org.netbeans.modules.schema2beansdev.metadd.MetaDD
1063: && equals((org.netbeans.modules.schema2beansdev.metadd.MetaDD) o);
1064: }
1065:
1066: public boolean equals(
1067: org.netbeans.modules.schema2beansdev.metadd.MetaDD inst) {
1068: if (inst == this ) {
1069: return true;
1070: }
1071: if (inst == null) {
1072: return false;
1073: }
1074: if (sizeMetaElement() != inst.sizeMetaElement())
1075: return false;
1076: // Compare every element.
1077: for (java.util.Iterator it = _MetaElement.iterator(), it2 = inst._MetaElement
1078: .iterator(); it.hasNext() && it2.hasNext();) {
1079: org.netbeans.modules.schema2beansdev.metadd.MetaElement element = (org.netbeans.modules.schema2beansdev.metadd.MetaElement) it
1080: .next();
1081: org.netbeans.modules.schema2beansdev.metadd.MetaElement element2 = (org.netbeans.modules.schema2beansdev.metadd.MetaElement) it2
1082: .next();
1083: if (!(element == null ? element2 == null : element
1084: .equals(element2))) {
1085: return false;
1086: }
1087: }
1088: if (!(_Implements == null ? inst._Implements == null
1089: : _Implements.equals(inst._Implements))) {
1090: return false;
1091: }
1092: if (!(_Extends == null ? inst._Extends == null : _Extends
1093: .equals(inst._Extends))) {
1094: return false;
1095: }
1096: if (sizeImport() != inst.sizeImport())
1097: return false;
1098: // Compare every element.
1099: for (java.util.Iterator it = _Import.iterator(), it2 = inst._Import
1100: .iterator(); it.hasNext() && it2.hasNext();) {
1101: String element = (String) it.next();
1102: String element2 = (String) it2.next();
1103: if (!(element == null ? element2 == null : element
1104: .equals(element2))) {
1105: return false;
1106: }
1107: }
1108: if (_isSet_Vetoable != inst._isSet_Vetoable) {
1109: return false;
1110: }
1111: if (_isSet_Vetoable) {
1112: if (!(_Vetoable == inst._Vetoable)) {
1113: return false;
1114: }
1115: }
1116: if (_isSet_ThrowExceptions != inst._isSet_ThrowExceptions) {
1117: return false;
1118: }
1119: if (_isSet_ThrowExceptions) {
1120: if (!(_ThrowExceptions == inst._ThrowExceptions)) {
1121: return false;
1122: }
1123: }
1124: if (!(_SchemaLocation == null ? inst._SchemaLocation == null
1125: : _SchemaLocation.equals(inst._SchemaLocation))) {
1126: return false;
1127: }
1128: if (sizeFinder() != inst.sizeFinder())
1129: return false;
1130: // Compare every element.
1131: for (java.util.Iterator it = _Finder.iterator(), it2 = inst._Finder
1132: .iterator(); it.hasNext() && it2.hasNext();) {
1133: String element = (String) it.next();
1134: String element2 = (String) it2.next();
1135: if (!(element == null ? element2 == null : element
1136: .equals(element2))) {
1137: return false;
1138: }
1139: }
1140: return true;
1141: }
1142:
1143: public int hashCode() {
1144: int result = 17;
1145: result = 37 * result
1146: + (_MetaElement == null ? 0 : _MetaElement.hashCode());
1147: result = 37 * result
1148: + (_Implements == null ? 0 : _Implements.hashCode());
1149: result = 37 * result
1150: + (_Extends == null ? 0 : _Extends.hashCode());
1151: result = 37 * result
1152: + (_Import == null ? 0 : _Import.hashCode());
1153: result = 37 * result
1154: + (_isSet_Vetoable ? 0 : (_Vetoable ? 0 : 1));
1155: result = 37
1156: * result
1157: + (_isSet_ThrowExceptions ? 0 : (_ThrowExceptions ? 0
1158: : 1));
1159: result = 37
1160: * result
1161: + (_SchemaLocation == null ? 0 : _SchemaLocation
1162: .hashCode());
1163: result = 37 * result
1164: + (_Finder == null ? 0 : _Finder.hashCode());
1165: return result;
1166: }
1167:
1168: public String toString() {
1169: java.io.StringWriter sw = new java.io.StringWriter();
1170: try {
1171: writeNode(sw);
1172: } catch (java.io.IOException e) {
1173: // How can we actually get an IOException on a StringWriter?
1174: throw new RuntimeException(e);
1175: }
1176: return sw.toString();
1177: }
1178:
1179: }
1180:
1181: /*
1182: The following schema file has been used for generation:
1183:
1184: <!-- This holds data about the schema that is not part of DTDs and/or XML Schemas.
1185: -->
1186:
1187: <!--
1188: -->
1189: <!ELEMENT metaDD (meta-element*, implements?, extends?, import*, vetoable?, throw-exceptions?, schemaLocation?, finder*)>
1190:
1191: <!--
1192: -->
1193: <!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?>
1194:
1195: <!--
1196: -->
1197: <!ELEMENT meta-property (bean-name, default-value*, known-value*, key?, vetoable?)>
1198:
1199: <!ELEMENT delegator-name (#PCDATA)>
1200:
1201: <!--
1202: -->
1203: <!ELEMENT implements (#PCDATA)>
1204:
1205: <!--
1206: -->
1207: <!ELEMENT extends (#PCDATA)>
1208:
1209: <!--
1210: -->
1211: <!ELEMENT import (#PCDATA)>
1212:
1213: <!--
1214: -->
1215: <!ELEMENT dtd-name (#PCDATA)>
1216:
1217: <!ELEMENT namespace (#PCDATA)>
1218:
1219: <!--
1220: -->
1221: <!ELEMENT default-value (#PCDATA)>
1222:
1223: <!--
1224: -->
1225: <!ELEMENT skip-generation EMPTY>
1226:
1227: <!--
1228: -->
1229: <!ELEMENT key EMPTY>
1230:
1231: <!--
1232: -->
1233: <!ELEMENT vetoable EMPTY>
1234:
1235: <!--
1236: -->
1237: <!ELEMENT known-value (#PCDATA)>
1238:
1239: <!--
1240: -->
1241: <!ELEMENT bean-name (#PCDATA)>
1242:
1243: <!--
1244: -->
1245: <!ELEMENT bean-class (#PCDATA)>
1246:
1247: <!--
1248: -->
1249: <!ELEMENT wrapper-class (#PCDATA)>
1250:
1251: <!--
1252: -->
1253: <!ELEMENT comparator-class (#PCDATA)>
1254:
1255: <!--
1256: -->
1257: <!ELEMENT user-code (#PCDATA)>
1258:
1259: <!ELEMENT throw-exceptions EMPTY>
1260:
1261: <!-- Automatically set the schemaLocation -->
1262: <!ELEMENT schemaLocation (#PCDATA)>
1263:
1264: <!ELEMENT finder (#PCDATA)>
1265:
1266: <!ELEMENT bean-interface-extends (#PCDATA)>
1267:
1268: <!ELEMENT can-be-empty EMPTY>
1269:
1270: */
|