Source Code Cross Referenced for SchemaRep.java in  » IDE-Netbeans » schema2beans » org » netbeans » modules » schema2beansdev » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » schema2beans » org.netbeans.modules.schema2beansdev 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * Software 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:        package org.netbeans.modules.schema2beansdev;
0043:
0044:        import org.netbeans.modules.schema2beansdev.gen.JavaUtil;
0045:        import org.netbeans.modules.schema2beansdev.gen.XMLWriter;
0046:
0047:        import java.io.*;
0048:        import java.util.*;
0049:
0050:        import org.w3c.dom.*;
0051:        import org.xml.sax.*;
0052:
0053:        import org.netbeans.modules.schema2beans.*;
0054:
0055:        /**
0056:         * This class will represent a schema for XML as a Java object.
0057:         * (This implementation isn't complete, but does enough for my purposes
0058:         * for now.)
0059:         *
0060:         * @author  cliffwd
0061:         */
0062:        public class SchemaRep implements  PrefixGuesser {
0063:            public static boolean debug = false;
0064:
0065:            public static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
0066:
0067:            /*
0068:             * The Schema Representation is internally made up of a tree of
0069:             * Element Expressions (ElementExpr).
0070:             */
0071:            ////////////////////////////////////////////////////////////////
0072:            public abstract class ElementExpr {
0073:                public abstract String getName();
0074:
0075:                public abstract void writeDTD(StringBuffer out);
0076:
0077:                // writeDTDName returns true if there were any named elements
0078:                public abstract boolean writeDTDName(StringBuffer out);
0079:
0080:                public abstract void writeXMLSchema(XMLWriter out)
0081:                        throws IOException;
0082:
0083:                // validate checks to make sure everything is okay
0084:                public abstract void validate();
0085:
0086:                // optimize returns a replacement node.  null means delete.
0087:                public abstract ElementExpr optimize();
0088:
0089:                public abstract void readSchema(org.w3c.dom.Element node);
0090:
0091:                // Return null for getContentName if this expr doesn't have one.
0092:                public abstract String getContentName();
0093:
0094:                protected ElementExpr parentExpr;
0095:
0096:                protected void setParentExpr(ElementExpr ee) {
0097:                    parentExpr = ee;
0098:                    fullContentName = null;
0099:                }
0100:
0101:                public ElementExpr getParentExpr() {
0102:                    return parentExpr;
0103:                }
0104:
0105:                private String fullContentName = null;
0106:
0107:                public String getFullContentName() {
0108:                    if (fullContentName == null) {
0109:                        String contentName = getContentName();
0110:                        if (parentExpr == null) {
0111:                            if (contentName == null)
0112:                                fullContentName = "/";
0113:                            else
0114:                                fullContentName = ("/" + contentName).intern();
0115:                        } else {
0116:                            String parentFullContentName = parentExpr
0117:                                    .getFullContentName();
0118:                            if (contentName == null)
0119:                                fullContentName = parentFullContentName;
0120:                            else if (parentFullContentName == "/")
0121:                                fullContentName = (parentFullContentName + contentName)
0122:                                        .intern();
0123:                            else
0124:                                fullContentName = (parentFullContentName + "/" + contentName)
0125:                                        .intern();
0126:                        }
0127:                    }
0128:                    return fullContentName;
0129:                }
0130:
0131:                protected String uniquifyFullContentName() {
0132:                    fullContentName = (getFullContentName() + "/#").intern();
0133:                    return fullContentName;
0134:                }
0135:            }
0136:
0137:            ////////////////////////////////////////////////////////////////
0138:            // This class represents all elements (or nodes in the metadata)
0139:            // that can have subelements.
0140:            public abstract class ContainsSubElements extends ElementExpr {
0141:                protected List subElements; // List<ElementExpr>
0142:
0143:                public ContainsSubElements() {
0144:                    subElements = new LinkedList();
0145:                }
0146:
0147:                public void addSubElement(ElementExpr subElement) {
0148:                    //System.out.println("Adding:"+subElement);
0149:                    subElement.setParentExpr(this );
0150:                    if (subElement instanceof  Element) {
0151:                        String subElementFullContentName;
0152:                        boolean checkAgain;
0153:                        do {
0154:                            checkAgain = false;
0155:                            subElementFullContentName = subElement
0156:                                    .getFullContentName();
0157:                            Iterator it = subElements.iterator();
0158:                            while (it.hasNext()) {
0159:                                ElementExpr otherElement = (ElementExpr) it
0160:                                        .next();
0161:                                String otherElementFullContentName = otherElement
0162:                                        .getFullContentName();
0163:                                if (subElementFullContentName == otherElementFullContentName) {
0164:                                    if (debug)
0165:                                        System.out
0166:                                                .println("Found duplicate fullContentName for "
0167:                                                        + otherElement
0168:                                                                .getName()
0169:                                                        + " : "
0170:                                                        + subElementFullContentName);
0171:                                    subElement.uniquifyFullContentName();
0172:                                    checkAgain = true;
0173:                                }
0174:                            }
0175:                        } while (checkAgain);
0176:                    }
0177:                    subElements.add(subElement);
0178:                }
0179:
0180:                public void addSubElement(List se) {
0181:                    //System.out.println("Adding: "+se+" to:"+toString());
0182:                    Iterator it = se.iterator();
0183:                    while (it.hasNext()) {
0184:                        addSubElement((ElementExpr) it.next());
0185:                    }
0186:                }
0187:
0188:                public Iterator subElementsIterator() {
0189:                    return subElements.iterator();
0190:                }
0191:
0192:                public ElementExpr findSubElement(String nodeName) {
0193:                    //System.out.println("Looking for subelement "+nodeName);
0194:                    Iterator it = subElements.iterator();
0195:                    while (it.hasNext()) {
0196:                        ElementExpr el = (ElementExpr) it.next();
0197:                        if (el.getName().equals(nodeName))
0198:                            return el;
0199:                    }
0200:                    //System.out.println("Did not find it");
0201:                    return null;
0202:                }
0203:
0204:                public ElementExpr findSubElement(Class type) {
0205:                    Iterator it = subElements.iterator();
0206:                    while (it.hasNext()) {
0207:                        ElementExpr el = (ElementExpr) it.next();
0208:                        if (type.isAssignableFrom(el.getClass()))
0209:                            return el;
0210:                    }
0211:                    return null;
0212:                }
0213:
0214:                /**
0215:                 * This will do an xpath like search.
0216:                 */
0217:                public ElementExpr findSubElement(String[] nodeNames) {
0218:                    ContainsSubElements current = this ;
0219:                    for (int i = 0; i < nodeNames.length; ++i) {
0220:                        ElementExpr ee = current.findSubElement(nodeNames[i]);
0221:                        if (ee == null)
0222:                            return null;
0223:                        if (ee instanceof  ContainsSubElements)
0224:                            current = (ContainsSubElements) ee;
0225:                        else if (i + 1 != nodeNames.length)
0226:                            return null;
0227:                    }
0228:                    return current;
0229:                }
0230:
0231:                /**
0232:                 * Find all matching sub elements and put them into lst.
0233:                 */
0234:                public void findAllSubElements(String name, List lst) {
0235:                    Iterator it = subElements.iterator();
0236:                    while (it.hasNext()) {
0237:                        ElementExpr el = (ElementExpr) it.next();
0238:                        if (el.getName().equals(name))
0239:                            lst.add(el);
0240:                        if (el instanceof  ContainsSubElements)
0241:                            ((ContainsSubElements) el).findAllSubElements(name,
0242:                                    lst);
0243:                    }
0244:                }
0245:
0246:                /**
0247:                 * Find all matching sub elements and put them into lst.
0248:                 */
0249:                public void findAllSubElements(Class type, List lst) {
0250:                    Iterator it = subElements.iterator();
0251:                    while (it.hasNext()) {
0252:                        ElementExpr el = (ElementExpr) it.next();
0253:                        if (type.isAssignableFrom(el.getClass()))
0254:                            lst.add(el);
0255:                        if (el instanceof  ContainsSubElements)
0256:                            ((ContainsSubElements) el).findAllSubElements(type,
0257:                                    lst);
0258:                    }
0259:                }
0260:
0261:                public void validate() {
0262:                    //System.out.println("** validate: "+this);
0263:                    Map possibleSubElements = validSubElementTypeMap();
0264:                    Iterator it = subElements.iterator();
0265:                    while (it.hasNext()) {
0266:                        ElementExpr ee = (ElementExpr) it.next();
0267:                        if (!possibleSubElements.containsKey(ee.getClass())) {
0268:                            throw new IllegalStateException(Common.getMessage(
0269:                                    "MSG_InvalidContents", toString(), ee
0270:                                            .getName(), getFullContentName()));
0271:                        }
0272:                        ee.validate();
0273:                    }
0274:                }
0275:
0276:                public abstract Map validSubElementTypeMap();
0277:
0278:                public void writeDTD(StringBuffer out) {
0279:                    Iterator it = subElements.iterator();
0280:                    while (it.hasNext()) {
0281:                        ElementExpr el = (ElementExpr) it.next();
0282:                        el.writeDTD(out);
0283:                    }
0284:                }
0285:
0286:                /**
0287:                 * Return the attributes as a string for the XML Schema.
0288:                 * null means that we have no attributes to add.
0289:                 */
0290:                public String getAttributeString() {
0291:                    return null;
0292:                }
0293:
0294:                /**
0295:                 * If whitespace is used on the outside of this element.
0296:                 */
0297:                public boolean compressWhiteSpaceOuter() {
0298:                    return false;
0299:                }
0300:
0301:                /**
0302:                 * If whitespace is used on the inside of this element.
0303:                 */
0304:                public boolean compressWhiteSpaceInner() {
0305:                    return false;
0306:                }
0307:
0308:                public void writeXMLSchema(XMLWriter out) throws IOException {
0309:                    writeXMLSchema(out, true);
0310:                }
0311:
0312:                /**
0313:                 * If @printMyElement is false, then we only print subelements.
0314:                 */
0315:                public void writeXMLSchema(XMLWriter out, boolean printMyElement)
0316:                        throws IOException {
0317:                    if (printMyElement) {
0318:                        //if (!compressWhiteSpaceOuter())
0319:                        //    out.indentRight();
0320:                        out.startTag(getXSDNamespace(), getName(), false);
0321:                        String attrs = getAttributeString();
0322:                        if (attrs != null)
0323:                            out.write(attrs);
0324:                        out.finishStartTag(subElements.size() > 0,
0325:                                !compressWhiteSpaceInner());
0326:                        if (subElements.size() == 0)
0327:                            return;
0328:                    }
0329:                    Iterator it = subElements.iterator();
0330:                    while (it.hasNext()) {
0331:                        ElementExpr el = (ElementExpr) it.next();
0332:                        el.writeXMLSchema(out);
0333:                    }
0334:                    if (printMyElement) {
0335:                        //if (!compressWhiteSpaceInner())
0336:                        //    out.indentLeft();
0337:                        out.endTag(!compressWhiteSpaceOuter());
0338:                    }
0339:                }
0340:
0341:                protected boolean writeDTDSubElementNames(StringBuffer out) {
0342:                    return writeDTDSubElementNames(out, true);
0343:                }
0344:
0345:                protected boolean writeDTDSubElementNames(StringBuffer out,
0346:                        boolean writeParens) {
0347:                    if (subElements.size() == 0)
0348:                        return false;
0349:                    boolean first = true;
0350:                    Iterator it = subElements.iterator();
0351:                    boolean hasNamedSubElements = false;
0352:                    // Put all of the DTD names of our subelements into subOut
0353:                    StringBuffer subOut = new StringBuffer();
0354:                    // Let each individual subelement do it's work in freshOut
0355:                    // (it's always empty at the top of the loop).
0356:                    StringBuffer freshOut = new StringBuffer();
0357:                    while (it.hasNext()) {
0358:                        ElementExpr el = (ElementExpr) it.next();
0359:                        boolean anyNamed = el.writeDTDName(freshOut);
0360:                        if (anyNamed) {
0361:                            hasNamedSubElements = true;
0362:                            if (first)
0363:                                first = false;
0364:                            else
0365:                                subOut.append(", "); // NOI18N
0366:                            subOut.append(freshOut.toString());
0367:                            freshOut = new StringBuffer();
0368:                        }
0369:                    }
0370:                    if (!hasNamedSubElements)
0371:                        return false;
0372:                    if (writeParens && subElements.size() >= 2)
0373:                        out.append("("); // NOI18N
0374:                    out.append(subOut);
0375:                    if (writeParens && subElements.size() >= 2)
0376:                        out.append(")"); // NOI18N
0377:                    return hasNamedSubElements;
0378:                }
0379:
0380:                // Inserts String's into @param list.
0381:                public void findSubElementNames(List list) {
0382:                    Iterator it = subElements.iterator();
0383:                    StringBuffer freshOut = new StringBuffer();
0384:                    while (it.hasNext()) {
0385:                        ElementExpr el = (ElementExpr) it.next();
0386:                        boolean anyNamed = el.writeDTDName(freshOut);
0387:                    }
0388:                }
0389:
0390:                public String toString() {
0391:                    String attributeString = getAttributeString();
0392:                    if (attributeString == null)
0393:                        return getName();
0394:                    else
0395:                        return getName() + attributeString;
0396:                }
0397:
0398:                public boolean equals(Object o) {
0399:                    if (!(o instanceof  ContainsSubElements))
0400:                        return false;
0401:                    ContainsSubElements e = (ContainsSubElements) o;
0402:                    //System.out.println("Checking for equals of ContainsSubElements");
0403:                    if (subElements.size() != e.subElements.size())
0404:                        return false;
0405:                    Iterator it = subElements.iterator();
0406:                    Iterator ite = e.subElements.iterator();
0407:                    while (it.hasNext()) {
0408:                        ElementExpr el = (ElementExpr) it.next();
0409:                        ElementExpr ele = (ElementExpr) ite.next();
0410:                        //System.out.println("el="+el);
0411:                        //System.out.println("ele="+ele);
0412:                        if (!el.equals(ele))
0413:                            return false;
0414:                    }
0415:                    return true;
0416:                }
0417:
0418:                public int hashCode() {
0419:                    int result = 17;
0420:                    Iterator it = subElements.iterator();
0421:                    while (it.hasNext()) {
0422:                        ElementExpr el = (ElementExpr) it.next();
0423:                        result = 37 * result + el.hashCode();
0424:                    }
0425:                    return result;
0426:                }
0427:
0428:                public ElementExpr optimize() {
0429:                    ListIterator it = subElements.listIterator();
0430:                    while (it.hasNext()) {
0431:                        ElementExpr el = (ElementExpr) it.next();
0432:                        ElementExpr result = el.optimize();
0433:                        //System.out.println("optimize: result="+result);
0434:                        if (result == null) {
0435:                            el.setParentExpr(null);
0436:                            it.remove();
0437:                        } else if (el != result)
0438:                            it.set(result);
0439:                    }
0440:                    return this ;
0441:                }
0442:
0443:                public String getJavaTypeName() {
0444:                    Iterator it = subElements.iterator();
0445:                    while (it.hasNext()) {
0446:                        Object o = it.next();
0447:                        if (o instanceof  HasJavaTypeName) {
0448:                            //System.out.println("Container: getJavaTypeName: o="+o);
0449:                            return ((HasJavaTypeName) o).getJavaTypeName();
0450:                        }
0451:                    }
0452:                    return null;
0453:                }
0454:            }
0455:
0456:            public interface HasJavaTypeName {
0457:                public String getJavaTypeName();
0458:            }
0459:
0460:            public interface MinMaxOccurs {
0461:                public String getMinOccurs();
0462:
0463:                public String getMaxOccurs();
0464:            }
0465:
0466:            public interface CanRef {
0467:                public boolean hasRef();
0468:
0469:                /**
0470:                 * @return the name of the ref or null if !hasRef()
0471:                 */
0472:                public String getRef();
0473:
0474:                public ElementExpr getRefElementExpr();
0475:            }
0476:
0477:            ////
0478:            public abstract class HasTypeName extends ContainsSubElements {
0479:                private String typeNameLocalPart = null;
0480:                private String typeNameNamespace = null;
0481:
0482:                protected String setTypeName(String typeName) {
0483:                    if (typeName == null) {
0484:                        typeNameLocalPart = null;
0485:                        typeNameNamespace = null;
0486:                        return null;
0487:                    }
0488:                    typeName = normalizeTargetNamespace(typeName).intern();
0489:                    typeNameLocalPart = removePrefix(typeName).intern();
0490:                    String prefix = prefixOf(typeName);
0491:                    typeNameNamespace = getNamespaceURI(prefix);
0492:                    if (typeNameNamespace != null)
0493:                        typeNameNamespace = typeNameNamespace.intern();
0494:                    return typeName;
0495:                }
0496:
0497:                public String getTypeNameLocalPart() {
0498:                    return typeNameLocalPart;
0499:                }
0500:
0501:                public String getTypeNameNamespace() {
0502:                    return typeNameNamespace;
0503:                }
0504:
0505:                /**
0506:                 * Can return null.
0507:                 */
0508:                public String getTypeName() {
0509:                    if (typeNameLocalPart == null)
0510:                        return null;
0511:                    String result = normalizeNamespace(typeNameNamespace,
0512:                            typeNameLocalPart);
0513:                    return result;
0514:                }
0515:
0516:            }
0517:
0518:            ////////////////////////////////////////////////////////////////
0519:            // Top of an XML Schema
0520:            public class SchemaNode extends ContainsSubElements {
0521:                protected String targetNamespace;
0522:                private Boolean elementFormQualifiedDefault = null;
0523:                private Boolean attributeFormQualifiedDefault = null;
0524:
0525:                public SchemaNode() {
0526:                }
0527:
0528:                public String getName() {
0529:                    return "schema";
0530:                }
0531:
0532:                public String getContentName() {
0533:                    return null;
0534:                }
0535:
0536:                public void setTargetNamespace(String tn) {
0537:                    targetNamespace = tn;
0538:                }
0539:
0540:                public String getTargetNamespace() {
0541:                    return targetNamespace;
0542:                }
0543:
0544:                public boolean isElementFormQualified() {
0545:                    if (elementFormQualifiedDefault == null)
0546:                        return false;
0547:                    return elementFormQualifiedDefault.booleanValue();
0548:                }
0549:
0550:                public boolean isAttributeFormQualified() {
0551:                    if (attributeFormQualifiedDefault == null)
0552:                        return false;
0553:                    return attributeFormQualifiedDefault.booleanValue();
0554:                }
0555:
0556:                public void readSchema(org.w3c.dom.Element node) {
0557:                    String tns = node.getAttribute("targetNamespace"); // NOI18N
0558:                    String efd = node.getAttribute("elementFormDefault"); // NOI18N
0559:                    String afd = node.getAttribute("attributeFormDefault"); // NOI18N
0560:                    if (tns != null && !"".equals(tns))
0561:                        targetNamespace = tns;
0562:                    if (efd != null)
0563:                        elementFormQualifiedDefault = Boolean
0564:                                .valueOf("qualified".equals(efd));
0565:                    SchemaRep.this .elementFormQualifiedDefault = isElementFormQualified();
0566:                    if (afd != null)
0567:                        attributeFormQualifiedDefault = Boolean
0568:                                .valueOf("qualified".equals(afd));
0569:                    SchemaRep.this .attributeFormQualifiedDefault = isAttributeFormQualified();
0570:                }
0571:
0572:                void merge(org.w3c.dom.Element node) {
0573:                    //System.out.println("merge: "+node);
0574:                    String tns = node.getAttribute("targetNamespace"); // NOI18N
0575:                    String efd = node.getAttribute("elementFormDefault"); // NOI18N
0576:                    String afd = node.getAttribute("attributeFormDefault"); // NOI18N
0577:                    if (targetNamespace == null)
0578:                        targetNamespace = tns;
0579:
0580:                    boolean value = "qualified".equals(efd);
0581:                    if (efd != null) {
0582:                        if (elementFormQualifiedDefault == null
0583:                                || elementFormQualifiedDefault.booleanValue())
0584:                            elementFormQualifiedDefault = Boolean
0585:                                    .valueOf(value);
0586:                    }
0587:                    SchemaRep.this .elementFormQualifiedDefault = value;
0588:
0589:                    value = "qualified".equals(afd);
0590:                    if (afd != null) {
0591:                        if (attributeFormQualifiedDefault == null
0592:                                || attributeFormQualifiedDefault.booleanValue())
0593:                            attributeFormQualifiedDefault = Boolean
0594:                                    .valueOf(value);
0595:                    }
0596:                    SchemaRep.this .attributeFormQualifiedDefault = value;
0597:                }
0598:
0599:                public void addSubElement(ElementExpr subElement) {
0600:                    if (subElement instanceof  Element) {
0601:                        Element el = (Element) subElement;
0602:                        //System.out.println("SchemaNode.addSubElement: el="+el);
0603:                        if (el.isDefiningNewType()) {
0604:                            if (debug)
0605:                                System.out
0606:                                        .println("SchemaNode new element type: name="
0607:                                                + el.getElementName());
0608:                            definedTypes.put(el.getElementName(), el);
0609:                            definedTypesFull.put(
0610:                                    canonicalQName(el.getElementNamespace(), el
0611:                                            .getElementName()), el);
0612:                        }
0613:                    }
0614:                    if (subElement instanceof  Attribute) {
0615:                        Attribute attr = (Attribute) subElement;
0616:                        //System.out.println("SchemaNode.addSubElement: attr="+attr);
0617:                        if (attr.isDefiningNewType()) {
0618:                            if (debug)
0619:                                System.out
0620:                                        .println("SchemaNode new element type: attr="
0621:                                                + attr);
0622:                            definedAttributes
0623:                                    .put(attr.getAttributeName(), attr);
0624:                        }
0625:                    }
0626:                    super .addSubElement(subElement);
0627:                }
0628:
0629:                public String getAttributeString() {
0630:                    StringBuffer sb = new StringBuffer(" xmlns:"
0631:                            + getXSDNamespace() + "='"
0632:                            + getNamespaceURI(getXSDNamespace()) + "'"); // NOI18N
0633:                    if (targetNamespace != null)
0634:                        sb.append(" targetNamespace='" + getTargetNamespace()
0635:                                + "'"); // NOI18N
0636:                    if (documentNamespace != null) {
0637:                        sb.append(" xmlns='" + documentNamespace + "'"); // NOI18N
0638:                    }
0639:                    if (isElementFormQualified())
0640:                        sb.append(" elementFormDefault='qualified'");
0641:                    if (isAttributeFormQualified())
0642:                        sb.append(" attributeFormDefault='qualified'");
0643:                    return sb.toString();
0644:                }
0645:
0646:                public void writeXMLSchema(XMLWriter out) throws IOException {
0647:                    out.startTag(getXSDNamespace(), getName(),
0648:                            getAttributeString()); // NOI18N
0649:                    out.cr();
0650:                    Iterator it = requiredPredefinedTypes.keySet().iterator();
0651:                    while (it.hasNext()) {
0652:                        String type = (String) it.next();
0653:                        //System.out.println("Required predefined type "+type);
0654:                        ElementExpr el = (ElementExpr) optionallyDefinedTypes
0655:                                .get(type);
0656:                        el.writeXMLSchema(out);
0657:                    }
0658:
0659:                    super .writeXMLSchema(out, false);
0660:                    out.endTag(); // NOI18N
0661:                }
0662:
0663:                public boolean writeDTDName(StringBuffer out) {
0664:                    return writeDTDSubElementNames(out, false);
0665:                }
0666:
0667:                public Map validSubElementTypeMap() {
0668:                    return schemaValidSubElementTypeMap;
0669:                }
0670:
0671:                public boolean equals(Object o) {
0672:                    if (!(o instanceof  SchemaNode))
0673:                        return false;
0674:                    SchemaNode el = (SchemaNode) o;
0675:                    if (targetNamespace == null) {
0676:                        if (el.targetNamespace != null)
0677:                            return false;
0678:                    } else {
0679:                        if (!targetNamespace.equals(el.targetNamespace))
0680:                            return false;
0681:                    }
0682:                    if (elementFormQualifiedDefault != el.elementFormQualifiedDefault)
0683:                        return false;
0684:                    if (attributeFormQualifiedDefault != el.attributeFormQualifiedDefault)
0685:                        return false;
0686:
0687:                    return super .equals(el);
0688:                }
0689:
0690:                public int hashCode() {
0691:                    int result = 17;
0692:                    result = 37
0693:                            * result
0694:                            + ((targetNamespace == null) ? 0 : targetNamespace
0695:                                    .hashCode());
0696:                    result = 37
0697:                            * result
0698:                            + (elementFormQualifiedDefault.booleanValue() ? 1
0699:                                    : 0);
0700:                    result = 37
0701:                            * result
0702:                            + (attributeFormQualifiedDefault.booleanValue() ? 1
0703:                                    : 0);
0704:                    result = 37 * result + super .hashCode();
0705:                    return result;
0706:                }
0707:            }
0708:
0709:            static private Map schemaValidSubElementTypeMap = null;
0710:            static {
0711:                schemaValidSubElementTypeMap = new HashMap();
0712:                schemaValidSubElementTypeMap.put(Annotation.class, null);
0713:                schemaValidSubElementTypeMap.put(SimpleType.class, null);
0714:                schemaValidSubElementTypeMap.put(ComplexType.class, null);
0715:                schemaValidSubElementTypeMap.put(Element.class, null);
0716:                schemaValidSubElementTypeMap.put(Attribute.class, null);
0717:                schemaValidSubElementTypeMap.put(AttributeGroup.class, null);
0718:                schemaValidSubElementTypeMap.put(Include.class, null);
0719:                schemaValidSubElementTypeMap.put(Import.class, null);
0720:                schemaValidSubElementTypeMap.put(Group.class, null);
0721:            }
0722:
0723:            ////////////////////////////////////////////////////////////////
0724:            // See XML Schema complexType
0725:            public class ComplexType extends HasTypeName implements 
0726:                    HasJavaTypeName {
0727:                //protected String typeName;
0728:                private boolean mixed = false;
0729:                private boolean abstractType = false;
0730:
0731:                public ComplexType() {
0732:                }
0733:
0734:                public ComplexType(String typeName) {
0735:                    if (typeName != null && !typeName.equals("")) {
0736:                        typeName = setTypeName(typeName);
0737:                        putSchemaTypeDef(typeName, this );
0738:                    }
0739:                }
0740:
0741:                public String getName() {
0742:                    return "complexType";
0743:                }
0744:
0745:                public String getContentName() {
0746:                    return getTypeName();
0747:                }
0748:
0749:                public boolean isMixed() {
0750:                    return mixed;
0751:                }
0752:
0753:                public boolean isAbstract() {
0754:                    return abstractType;
0755:                }
0756:
0757:                public boolean writeDTDName(StringBuffer out) {
0758:                    return writeDTDSubElementNames(out, false);
0759:                }
0760:
0761:                public String getAttributeString() {
0762:                    String result = "";
0763:                    if (getTypeName() != null)
0764:                        result += " name='" + getTypeName() + "'";
0765:                    if (mixed)
0766:                        result += " mixed='true'";
0767:                    if (abstractType)
0768:                        result += " abstract='true'";
0769:                    return result;
0770:                }
0771:
0772:                public Map validSubElementTypeMap() {
0773:                    return complexTypeValidSubElementTypeMap;
0774:                }
0775:
0776:                public void readSchema(org.w3c.dom.Element node) {
0777:                    String elementType = node.getAttribute("name"); // NOI18N
0778:                    String myMixed = node.getAttribute("mixed"); // NOI18N
0779:                    String myAbstract = node.getAttribute("abstract"); // NOI18N
0780:                    ComplexType el = new ComplexType(elementType);
0781:                    if (myMixed != null
0782:                            && (myMixed.equals("true") || myMixed.equals("yes") || myMixed
0783:                                    .equals("on")))
0784:                        el.mixed = true;
0785:                    if (myAbstract != null
0786:                            && (myAbstract.equals("true")
0787:                                    || myAbstract.equals("yes") || myAbstract
0788:                                    .equals("on")))
0789:                        el.abstractType = true;
0790:                    if (debug)
0791:                        System.out
0792:                                .println("Created complexType " + elementType);
0793:                    pushCurrent(el);
0794:                    read(node);
0795:                    popCurrent();
0796:                }
0797:
0798:                public boolean equals(Object o) {
0799:                    if (!(o instanceof  ComplexType))
0800:                        return false;
0801:                    ComplexType el = (ComplexType) o;
0802:                    if ((getTypeName() == null) ? (el.getTypeName() == null)
0803:                            : getTypeName().equals(el.getTypeName()))
0804:                        return false;
0805:                    if (mixed != el.mixed)
0806:                        return false;
0807:                    if (abstractType != el.abstractType)
0808:                        return false;
0809:
0810:                    return super .equals(el);
0811:                }
0812:
0813:                public int hashCode() {
0814:                    int result = 17;
0815:                    result = 37
0816:                            * result
0817:                            + ((getTypeName() == null) ? 0 : getTypeName()
0818:                                    .hashCode());
0819:                    result = 37 * result + (mixed ? 1 : 0);
0820:                    result = 37 * result + (abstractType ? 1 : 0);
0821:                    result = 37 * result + super .hashCode();
0822:                    return result;
0823:                }
0824:            }
0825:
0826:            static private Map complexTypeValidSubElementTypeMap = null;
0827:            static {
0828:                complexTypeValidSubElementTypeMap = new HashMap();
0829:                complexTypeValidSubElementTypeMap.put(Annotation.class, null);
0830:                complexTypeValidSubElementTypeMap.put(Choice.class, null);
0831:                complexTypeValidSubElementTypeMap.put(Group.class, null);
0832:                complexTypeValidSubElementTypeMap.put(Sequence.class, null);
0833:                complexTypeValidSubElementTypeMap.put(All.class, null);
0834:                complexTypeValidSubElementTypeMap.put(Attribute.class, null);
0835:                complexTypeValidSubElementTypeMap.put(AttributeGroup.class,
0836:                        null);
0837:                complexTypeValidSubElementTypeMap.put(AnyAttribute.class, null);
0838:                complexTypeValidSubElementTypeMap
0839:                        .put(SimpleContent.class, null);
0840:                complexTypeValidSubElementTypeMap.put(ComplexContent.class,
0841:                        null);
0842:            }
0843:
0844:            ////////////////////////////////////////////////////////////////
0845:            public class SimpleContent extends ContainsSubElements implements 
0846:                    HasJavaTypeName {
0847:                public SimpleContent() {
0848:                }
0849:
0850:                public String getName() {
0851:                    return "simpleContent";
0852:                }
0853:
0854:                public String getContentName() {
0855:                    return null;
0856:                }
0857:
0858:                public void validate() {
0859:                }
0860:
0861:                public ElementExpr optimize() {
0862:                    return this ;
0863:                }
0864:
0865:                public void readSchema(org.w3c.dom.Element node) {
0866:                    SimpleContent el = new SimpleContent();
0867:                    pushCurrent(el);
0868:                    read(node);
0869:                    popCurrent();
0870:                }
0871:
0872:                public boolean writeDTDName(StringBuffer out) {
0873:                    return writeDTDSubElementNames(out, false);
0874:                }
0875:
0876:                public Map validSubElementTypeMap() {
0877:                    return simpleContentValidSubElementTypeMap;
0878:                }
0879:            }
0880:
0881:            static private Map simpleContentValidSubElementTypeMap = null;
0882:            static {
0883:                simpleContentValidSubElementTypeMap = new HashMap();
0884:                simpleContentValidSubElementTypeMap.put(Annotation.class, null);
0885:                simpleContentValidSubElementTypeMap
0886:                        .put(Restriction.class, null);
0887:                simpleContentValidSubElementTypeMap.put(Extension.class, null);
0888:            }
0889:
0890:            ////////////////////////////////////////////////////////////////
0891:            public class ComplexContent extends ContainsSubElements implements 
0892:                    HasJavaTypeName {
0893:                private boolean mixed;
0894:
0895:                public ComplexContent() {
0896:                }
0897:
0898:                public String getName() {
0899:                    return "complexContent";
0900:                }
0901:
0902:                public String getContentName() {
0903:                    return null;
0904:                }
0905:
0906:                public void validate() {
0907:                }
0908:
0909:                public ElementExpr optimize() {
0910:                    return this ;
0911:                }
0912:
0913:                public boolean isMixed() {
0914:                    return mixed;
0915:                }
0916:
0917:                public void readSchema(org.w3c.dom.Element node) {
0918:                    ComplexContent el = new ComplexContent();
0919:                    String myMixed = node.getAttribute("mixed"); // NOI18N
0920:                    if (myMixed != null
0921:                            && (myMixed.equals("true") || myMixed.equals("yes") || myMixed
0922:                                    .equals("on")))
0923:                        el.mixed = true;
0924:                    pushCurrent(el);
0925:                    read(node);
0926:                    popCurrent();
0927:                }
0928:
0929:                public boolean writeDTDName(StringBuffer out) {
0930:                    return writeDTDSubElementNames(out, false);
0931:                }
0932:
0933:                public Map validSubElementTypeMap() {
0934:                    return complexContentValidSubElementTypeMap;
0935:                }
0936:
0937:                public boolean equals(Object o) {
0938:                    if (!(o instanceof  ComplexContent))
0939:                        return false;
0940:                    ComplexContent el = (ComplexContent) o;
0941:                    if (mixed != el.mixed)
0942:                        return false;
0943:                    return super .equals(el);
0944:                }
0945:
0946:                public int hashCode() {
0947:                    int result = 17;
0948:                    result = 37 * result + (mixed ? 0 : 1);
0949:                    result = 37 * result + super .hashCode();
0950:                    return result;
0951:                }
0952:            }
0953:
0954:            static private Map complexContentValidSubElementTypeMap = null;
0955:            static {
0956:                complexContentValidSubElementTypeMap = new HashMap();
0957:                complexContentValidSubElementTypeMap
0958:                        .put(Annotation.class, null);
0959:                complexContentValidSubElementTypeMap.put(Restriction.class,
0960:                        null);
0961:                complexContentValidSubElementTypeMap.put(Extension.class, null);
0962:            }
0963:
0964:            ////////////////////////////////////////////////////////////////
0965:            // See XML Schema simpleType
0966:            public class SimpleType extends HasTypeName implements 
0967:                    HasJavaTypeName {
0968:                //private String typeName = null;
0969:                private String javaTypeName = null;
0970:
0971:                public SimpleType(String tn) {
0972:                    //System.out.println("SimpleType1: tn="+tn);
0973:                    if (tn != null && !tn.equals("")) {
0974:                        String typeName = normalizeTargetNamespace(tn).intern();
0975:                        ElementExpr previousDef = getSchemaTypeDef(typeName);
0976:                        if (previousDef instanceof  SimpleType
0977:                                && (((SimpleType) previousDef).javaTypeName != null || ((SimpleType) previousDef).subElements
0978:                                        .size() > 0)) {
0979:                            // The previous definition has more information.  Keep it.
0980:                            System.out.println("Keeping schemaTypeDefs1 for "
0981:                                    + previousDef);
0982:                        } else {
0983:                            if (previousDef != null)
0984:                                System.out
0985:                                        .println("!!! Overwriting schemaTypeDefs1 ("
0986:                                                + previousDef + ") for " + this );
0987:                            typeName = setTypeName(typeName);
0988:                            putSchemaTypeDef(typeName, this );
0989:                        }
0990:                    }
0991:                }
0992:
0993:                /**
0994:                 * @param tn is the type
0995:                 * @param javaTypeName is a java type to associate with @param tn
0996:                 *    and should be linearly dependent.
0997:                 */
0998:                public SimpleType(String tn, String javaTypeName) {
0999:                    super ();
1000:                    //System.out.println("SimpleType2: tn="+tn+" javaTypeName="+javaTypeName);
1001:                    String typeName = setTypeName(tn);
1002:                    this .javaTypeName = (javaTypeName == null) ? null
1003:                            : javaTypeName.intern();
1004:                    /*
1005:                    if (schemaTypeDefs.get(typeName) != null)
1006:                        System.out.println("!!! Overwriting schemaTypeDefs2 for "+this);
1007:                     */
1008:                    putSchemaTypeDef(typeName, this );
1009:                }
1010:
1011:                public SimpleType(String tn, Restriction restrict) {
1012:                    super ();
1013:                    //System.out.println("SimpleType3: tn="+tn+" restrict="+restrict);
1014:                    String typeName = setTypeName(tn);
1015:                    this .addSubElement(restrict);
1016:                    /*
1017:                    if (schemaTypeDefs.get(typeName) != null)
1018:                        System.out.println("!!! Overwriting schemaTypeDefs3 for "+this);
1019:                     */
1020:                    putSchemaTypeDef(typeName, this );
1021:                }
1022:
1023:                public String getName() {
1024:                    return "simpleType";
1025:                }
1026:
1027:                public String getContentName() {
1028:                    return getTypeName();
1029:                }
1030:
1031:                // This may return null
1032:                public String getJavaTypeName() {
1033:                    if (javaTypeName != null)
1034:                        return javaTypeName;
1035:                    return super .getJavaTypeName();
1036:                }
1037:
1038:                public String getAttributeString() {
1039:                    if (getTypeName() == null)
1040:                        return null;
1041:                    return (" name='" + getTypeName() + "'");
1042:                }
1043:
1044:                public boolean compressWhiteSpaceInner() {
1045:                    if (subElements.size() == 0)
1046:                        return true;
1047:                    ElementExpr subElement = (ElementExpr) subElementsIterator()
1048:                            .next();
1049:                    if (subElement instanceof  ContainsSubElements)
1050:                        return ((ContainsSubElements) subElement)
1051:                                .compressWhiteSpaceOuter();
1052:                    return true;
1053:                }
1054:
1055:                public boolean writeDTDName(StringBuffer out) {
1056:                    return writeDTDSubElementNames(out, false);
1057:                }
1058:
1059:                public void readSchema(org.w3c.dom.Element node) {
1060:                    String elementType = node.getAttribute("name"); // NOI18N
1061:                    SimpleType el = new SimpleType(elementType);
1062:                    pushCurrent(el);
1063:                    read(node);
1064:                    popCurrent();
1065:                }
1066:
1067:                public Map validSubElementTypeMap() {
1068:                    return simpleTypeValidSubElementTypeMap;
1069:                }
1070:
1071:                public String toString() {
1072:                    if (javaTypeName == null) {
1073:                        if (getTypeName() == null)
1074:                            return "simpleType (not named)"; // NOI18N
1075:                        else
1076:                            return "simpleType " + getTypeName(); // NOI18N
1077:                    } else
1078:                        return "simpleType " + getTypeName() + " "
1079:                                + javaTypeName; // NOI18N
1080:                }
1081:
1082:                public boolean equals(Object o) {
1083:                    if (!(o instanceof  SimpleType))
1084:                        return false;
1085:                    SimpleType el = (SimpleType) o;
1086:                    if ((getTypeName() == null) ? (el.getTypeName() == null)
1087:                            : getTypeName().equals(el.getTypeName()))
1088:                        return false;
1089:                    // javaTypeName ought to be redundant to typeName
1090:                    return super .equals(el);
1091:                }
1092:
1093:                public int hashCode() {
1094:                    int result = 17;
1095:                    if (getTypeName() != null)
1096:                        result = 37 * result + getTypeName().hashCode();
1097:                    result = 37 * result + super .hashCode();
1098:                    return result;
1099:                }
1100:            }
1101:
1102:            static private Map simpleTypeValidSubElementTypeMap = null;
1103:            static {
1104:                simpleTypeValidSubElementTypeMap = new HashMap();
1105:                simpleTypeValidSubElementTypeMap.put(Annotation.class, null);
1106:                simpleTypeValidSubElementTypeMap.put(Restriction.class, null);
1107:                simpleTypeValidSubElementTypeMap.put(ListElement.class, null);
1108:                simpleTypeValidSubElementTypeMap.put(UnionType.class, null);
1109:            }
1110:
1111:            ////////////////////////////////////////////////////////////////
1112:            // See XML Schema simpleType
1113:            public class UnionType extends ContainsSubElements {
1114:                private String typeName = null;
1115:                private String memberTypes = null;
1116:
1117:                public UnionType(String tn, String memberTypes) {
1118:                    //System.out.println("UnionType1: tn="+tn);
1119:                    if (tn != null && !tn.equals("")) {
1120:                        typeName = normalizeTargetNamespace(tn).intern();
1121:                    }
1122:                    this .memberTypes = memberTypes;
1123:                }
1124:
1125:                public String getMemberTypes() {
1126:                    return memberTypes;
1127:                }
1128:
1129:                public ElementExpr[] getMemberTypeElements() {
1130:                    if (memberTypes == null || memberTypes.trim().length() == 0)
1131:                        return null;
1132:                    ArrayList mlist = new ArrayList();
1133:                    String[] members = memberTypes.trim().split(" ");
1134:                    for (int i = 0; i < members.length; i++) {
1135:                        if (members[i].length() == 0)
1136:                            continue;
1137:                        SchemaRep.ElementExpr ee = getSchemaTypeDef(members[i]);
1138:                        if (ee != null)
1139:                            mlist.add(ee);
1140:                    }
1141:
1142:                    ElementExpr[] memberList = new ElementExpr[mlist.size()];
1143:                    memberList = (ElementExpr[]) mlist.toArray(memberList);
1144:                    return memberList;
1145:                }
1146:
1147:                public String getName() {
1148:                    return "union";
1149:                }
1150:
1151:                public String getContentName() {
1152:                    return typeName;
1153:                }
1154:
1155:                public String getTypeName() {
1156:                    return typeName;
1157:                }
1158:
1159:                public String getAttributeString() {
1160:                    if (memberTypes == null)
1161:                        return null;
1162:                    return (" memberTypes='" + memberTypes + "'");
1163:                }
1164:
1165:                public boolean compressWhiteSpaceInner() {
1166:                    if (subElements.size() == 0)
1167:                        return true;
1168:                    ElementExpr subElement = (ElementExpr) subElementsIterator()
1169:                            .next();
1170:                    if (subElement instanceof  ContainsSubElements)
1171:                        return ((ContainsSubElements) subElement)
1172:                                .compressWhiteSpaceOuter();
1173:                    return true;
1174:                }
1175:
1176:                public boolean writeDTDName(StringBuffer out) {
1177:                    return writeDTDSubElementNames(out, false);
1178:                }
1179:
1180:                public void readSchema(org.w3c.dom.Element node) {
1181:                    String memberTypes = node.getAttribute("memberTypes"); // NOI18N
1182:                    String typeName = "_union";
1183:                    org.w3c.dom.Node parent = node.getParentNode();
1184:                    if (parent instanceof  org.w3c.dom.Element) {
1185:                        do {
1186:                            org.w3c.dom.Element parentEl = (org.w3c.dom.Element) parent;
1187:                            if (parent != null) {
1188:                                String name = parentEl.getAttribute("name");
1189:                                if (name != null) {
1190:                                    typeName = name + typeName;
1191:                                    break;
1192:                                } else {
1193:                                    // Only simpletypes have unions..So
1194:                                    typeName = "_simpleType" + typeName;
1195:                                }
1196:                                parent = parent.getParentNode();
1197:                            } else
1198:                                break;
1199:                        } while (parent != null);
1200:                    }
1201:                    UnionType el = new UnionType(typeName, memberTypes);
1202:                    pushCurrent(el);
1203:                    read(node);
1204:                    popCurrent();
1205:                }
1206:
1207:                public Map validSubElementTypeMap() {
1208:                    return unionTypeValidSubElementTypeMap;
1209:                }
1210:
1211:                public String toString() {
1212:                    if (typeName == null)
1213:                        return "unionType (not named)"; // NOI18N
1214:                    else
1215:                        return "unionType " + typeName; // NOI18N
1216:                }
1217:
1218:                public boolean equals(Object o) {
1219:                    if (!(o instanceof  UnionType))
1220:                        return false;
1221:                    UnionType el = (UnionType) o;
1222:                    if (typeName != el.typeName)
1223:                        return false;
1224:                    if (memberTypes != el.memberTypes)
1225:                        return false;
1226:                    // javaTypeName ought to be redundant to typeName
1227:                    return super .equals(el);
1228:                }
1229:
1230:                public int hashCode() {
1231:                    int result = 17;
1232:                    result = 37 * result + memberTypes.hashCode();
1233:                    result = 37 * result + typeName.hashCode();
1234:                    result = 37 * result + super .hashCode();
1235:                    return result;
1236:                }
1237:            }
1238:
1239:            static private Map unionTypeValidSubElementTypeMap = null;
1240:            static {
1241:                unionTypeValidSubElementTypeMap = new HashMap();
1242:                unionTypeValidSubElementTypeMap.put(Annotation.class, null);
1243:                unionTypeValidSubElementTypeMap.put(SimpleType.class, null);
1244:            }
1245:
1246:            public interface EncodingStyle {
1247:            }
1248:
1249:            public class HexBinary extends SimpleType implements  EncodingStyle {
1250:                public HexBinary() {
1251:                    super (getXSDNamespace() + ":hexBinary", "byte[]");
1252:                }
1253:
1254:                public String toString() {
1255:                    return "hexBinary";
1256:                }
1257:            }
1258:
1259:            public class Base64Binary extends SimpleType implements 
1260:                    EncodingStyle {
1261:                public Base64Binary() {
1262:                    super (getXSDNamespace() + ":base64Binary", "byte[]");
1263:                }
1264:
1265:                public String toString() {
1266:                    return "base64Binary";
1267:                }
1268:            }
1269:
1270:            ////////////////////////////////////////////////////////////////
1271:            // See XML Schema restriction (usually underneath simpleType)
1272:            public class Restriction extends ContainsSubElements implements 
1273:                    HasJavaTypeName {
1274:                protected String base;
1275:
1276:                public Restriction() {
1277:                }
1278:
1279:                public Restriction(String base) {
1280:                    setBase(base);
1281:                }
1282:
1283:                public String getName() {
1284:                    return "restriction";
1285:                }
1286:
1287:                public String getContentName() {
1288:                    return null;
1289:                }
1290:
1291:                public void setBase(String b) {
1292:                    if (b == null) {
1293:                        base = null;
1294:                        return;
1295:                    }
1296:                    base = normalizeDocumentNamespace(b).intern();
1297:                }
1298:
1299:                public String getBase() {
1300:                    return base;
1301:                }
1302:
1303:                public String getJavaTypeName() {
1304:                    return schemaTypeToJavaType(base);
1305:                }
1306:
1307:                public boolean compressWhiteSpaceOuter() {
1308:                    return subElements.size() == 0;
1309:                }
1310:
1311:                public boolean compressWhiteSpaceInner() {
1312:                    return subElements.size() == 0;
1313:                }
1314:
1315:                public boolean writeDTDName(StringBuffer out) {
1316:                    return writeDTDSubElementNames(out, false);
1317:                }
1318:
1319:                public String getAttributeString() {
1320:                    if (base == null)
1321:                        return null;
1322:                    return (" base='" + getBase() + "'");
1323:                }
1324:
1325:                public void readSchema(org.w3c.dom.Element node) {
1326:                    String base = node.getAttribute("base"); // NOI18N
1327:                    Restriction el = new Restriction(base);
1328:                    pushCurrent(el);
1329:                    read(node);
1330:                    popCurrent();
1331:                }
1332:
1333:                public Map validSubElementTypeMap() {
1334:                    return restrictionValidSubElementTypeMap;
1335:                }
1336:
1337:                public boolean equals(Object o) {
1338:                    if (!(o instanceof  Restriction))
1339:                        return false;
1340:                    Restriction el = (Restriction) o;
1341:                    if (base == null) {
1342:                        if (el.base != null)
1343:                            return false;
1344:                    } else {
1345:                        if (!base.equals(el.base))
1346:                            return false;
1347:                    }
1348:
1349:                    return super .equals(el);
1350:                }
1351:
1352:                public String toString() {
1353:                    Iterator subElements = subElementsIterator();
1354:                    StringBuffer sb = null;
1355:                    while (subElements.hasNext()) {
1356:                        ElementExpr ee = (ElementExpr) subElements.next();
1357:                        if (ee instanceof  RestrictionType) {
1358:                            if (sb == null)
1359:                                sb = new StringBuffer();
1360:                            else
1361:                                sb.append(", ");
1362:                            RestrictionType restrictionType = (RestrictionType) ee;
1363:                            sb.append(restrictionType.toString());
1364:                        }
1365:                    }
1366:                    /*
1367:                     if (sb == null)
1368:                     return super.toString();
1369:                     else
1370:                     */
1371:                    if (sb != null)
1372:                        return sb.toString();
1373:                    else
1374:                        return "";
1375:                }
1376:
1377:                public int hashCode() {
1378:                    int result = 17;
1379:                    result = 37 * result
1380:                            + ((base == null) ? 0 : base.hashCode());
1381:                    result = 37 * result + super .hashCode();
1382:                    return result;
1383:                }
1384:            }
1385:
1386:            static private Map restrictionValidSubElementTypeMap = null;
1387:            static {
1388:                restrictionValidSubElementTypeMap = new HashMap();
1389:                restrictionValidSubElementTypeMap.put(Annotation.class, null);
1390:                restrictionValidSubElementTypeMap.put(SimpleType.class, null);
1391:                restrictionValidSubElementTypeMap.put(All.class, null);
1392:                restrictionValidSubElementTypeMap.put(Choice.class, null);
1393:                restrictionValidSubElementTypeMap.put(Sequence.class, null);
1394:                restrictionValidSubElementTypeMap.put(Group.class, null);
1395:                restrictionValidSubElementTypeMap.put(Attribute.class, null);
1396:                restrictionValidSubElementTypeMap.put(AttributeGroup.class,
1397:                        null);
1398:                restrictionValidSubElementTypeMap.put(AnyAttribute.class, null);
1399:                restrictionValidSubElementTypeMap.put(MinExclusive.class, null);
1400:                restrictionValidSubElementTypeMap.put(MaxExclusive.class, null);
1401:                restrictionValidSubElementTypeMap.put(Enumeration.class, null);
1402:                restrictionValidSubElementTypeMap.put(Pattern.class, null);
1403:                restrictionValidSubElementTypeMap.put(MinLength.class, null);
1404:                restrictionValidSubElementTypeMap.put(MaxLength.class, null);
1405:                restrictionValidSubElementTypeMap.put(TotalDigits.class, null);
1406:                restrictionValidSubElementTypeMap.put(MinInclusive.class, null);
1407:                restrictionValidSubElementTypeMap.put(MaxInclusive.class, null);
1408:                restrictionValidSubElementTypeMap.put(FractionDigits.class,
1409:                        null);
1410:                restrictionValidSubElementTypeMap.put(Length.class, null);
1411:                restrictionValidSubElementTypeMap.put(WhiteSpace.class, null);
1412:            }
1413:
1414:            ////////////////////////////////////////////////////////////////
1415:            public class Extension extends ContainsSubElements implements 
1416:                    HasJavaTypeName {
1417:                protected String base;
1418:
1419:                public Extension() {
1420:                }
1421:
1422:                public Extension(String base) {
1423:                    setBase(base);
1424:                }
1425:
1426:                public String getContentName() {
1427:                    return null;
1428:                }
1429:
1430:                public String getName() {
1431:                    return "extension";
1432:                }
1433:
1434:                public void setBase(String b) {
1435:                    base = normalizeDocumentNamespace(b);
1436:                }
1437:
1438:                public String getBase() {
1439:                    return base;
1440:                }
1441:
1442:                public String getJavaTypeName() {
1443:                    return schemaTypeToJavaType(base);
1444:                }
1445:
1446:                public boolean writeDTDName(StringBuffer out) {
1447:                    return writeDTDSubElementNames(out, false);
1448:                }
1449:
1450:                public String getAttributeString() {
1451:                    if (base == null)
1452:                        return null;
1453:                    return (" base='" + getBase() + "'");
1454:                }
1455:
1456:                public void readSchema(org.w3c.dom.Element node) {
1457:                    String base = node.getAttribute("base"); // NOI18N
1458:                    Extension el = new Extension(base);
1459:                    pushCurrent(el);
1460:                    read(node);
1461:                    popCurrent();
1462:                }
1463:
1464:                public Map validSubElementTypeMap() {
1465:                    return extensionValidSubElementTypeMap;
1466:                }
1467:
1468:                public boolean equals(Object o) {
1469:                    if (!(o instanceof  Extension))
1470:                        return false;
1471:                    Extension el = (Extension) o;
1472:                    if (base == null) {
1473:                        if (el.base != null)
1474:                            return false;
1475:                    } else {
1476:                        if (!base.equals(el.base))
1477:                            return false;
1478:                    }
1479:
1480:                    return super .equals(el);
1481:                }
1482:
1483:                public int hashCode() {
1484:                    int result = 17;
1485:                    result = 37 * result
1486:                            + ((base == null) ? 0 : base.hashCode());
1487:                    result = 37 * result + super .hashCode();
1488:                    return result;
1489:                }
1490:            }
1491:
1492:            static private Map extensionValidSubElementTypeMap = null;
1493:            static {
1494:                extensionValidSubElementTypeMap = new HashMap();
1495:                extensionValidSubElementTypeMap.put(Annotation.class, null);
1496:                extensionValidSubElementTypeMap.put(Attribute.class, null);
1497:                extensionValidSubElementTypeMap.put(AttributeGroup.class, null);
1498:                extensionValidSubElementTypeMap.put(AnyAttribute.class, null);
1499:                extensionValidSubElementTypeMap.put(Choice.class, null);
1500:                extensionValidSubElementTypeMap.put(Group.class, null);
1501:                extensionValidSubElementTypeMap.put(Sequence.class, null);
1502:                extensionValidSubElementTypeMap.put(All.class, null);
1503:            }
1504:
1505:            ////////////////////////////////////////////////////////////////
1506:            public class ListElement extends ContainsSubElements {
1507:                protected String itemType;
1508:
1509:                public ListElement() {
1510:                }
1511:
1512:                public ListElement(String itemType) {
1513:                    this .itemType = itemType;
1514:                }
1515:
1516:                public String getContentName() {
1517:                    return null;
1518:                }
1519:
1520:                public String getName() {
1521:                    return "list";
1522:                }
1523:
1524:                public void setItemType(String b) {
1525:                    itemType = b;
1526:                }
1527:
1528:                public String getItemType() {
1529:                    return itemType;
1530:                }
1531:
1532:                public String getJavaTypeName() {
1533:                    return schemaTypeToJavaType(itemType);
1534:                }
1535:
1536:                public boolean writeDTDName(StringBuffer out) {
1537:                    return writeDTDSubElementNames(out, false);
1538:                }
1539:
1540:                public String getAttributeString() {
1541:                    if (itemType == null)
1542:                        return null;
1543:                    return (" itemType='" + getItemType() + "'");
1544:                }
1545:
1546:                public void readSchema(org.w3c.dom.Element node) {
1547:                    String itemType = node.getAttribute("itemType"); // NOI18N
1548:                    ListElement el = new ListElement(itemType);
1549:                    pushCurrent(el);
1550:                    read(node);
1551:                    popCurrent();
1552:                }
1553:
1554:                public Map validSubElementTypeMap() {
1555:                    return listValidSubElementTypeMap;
1556:                }
1557:
1558:                public boolean equals(Object o) {
1559:                    if (!(o instanceof  ListElement))
1560:                        return false;
1561:                    ListElement el = (ListElement) o;
1562:                    if (itemType == null) {
1563:                        if (el.itemType != null)
1564:                            return false;
1565:                    } else {
1566:                        if (!itemType.equals(el.itemType))
1567:                            return false;
1568:                    }
1569:
1570:                    return super .equals(el);
1571:                }
1572:
1573:                public int hashCode() {
1574:                    int result = 17;
1575:                    result = 37 * result
1576:                            + ((itemType == null) ? 0 : itemType.hashCode());
1577:                    result = 37 * result + super .hashCode();
1578:                    return result;
1579:                }
1580:            }
1581:
1582:            static private Map listValidSubElementTypeMap = null;
1583:            static {
1584:                listValidSubElementTypeMap = new HashMap();
1585:                listValidSubElementTypeMap.put(Annotation.class, null);
1586:            }
1587:
1588:            ////////////////////////////////////////////////////////////////
1589:            public abstract class RestrictionType extends ContainsSubElements {
1590:                protected String value;
1591:
1592:                public RestrictionType(String value) {
1593:                    super ();
1594:                    this .value = (value == null) ? null : value.intern();
1595:                }
1596:
1597:                public String getContentName() {
1598:                    return null;
1599:                }
1600:
1601:                public String getValue() {
1602:                    return value;
1603:                }
1604:
1605:                public void writeDTD(StringBuffer out) {
1606:                    // Has no bearing on a DTD
1607:                }
1608:
1609:                public boolean writeDTDName(StringBuffer out) {
1610:                    // Has no bearing on a DTD
1611:                    return false;
1612:                }
1613:
1614:                public void validate() {
1615:                }
1616:
1617:                public ElementExpr optimize() {
1618:                    return this ;
1619:                }
1620:
1621:                public Map validSubElementTypeMap() {
1622:                    return restrictionTypeValidSubElementTypeMap;
1623:                }
1624:
1625:                public void writeXMLSchema(XMLWriter out) throws IOException {
1626:                    out.startTag(getXSDNamespace(), getName(), false);
1627:                    out.write(" value='");
1628:                    XMLUtil.printXML(out, value);
1629:                    out.write("'");
1630:                    out.finishStartTag(false, true);
1631:                }
1632:
1633:                public void readSchema(org.w3c.dom.Element node) {
1634:                    String myValue = node.getAttribute("value"); // NOI18N
1635:                    RestrictionType el = newInstance(myValue);
1636:                    pushCurrent(el);
1637:                    read(node);
1638:                    popCurrent();
1639:                }
1640:
1641:                protected abstract RestrictionType newInstance(String value);
1642:
1643:                /*
1644:                public void genRestriction(Writer out, String var, String type, String failVar) throws IOException {
1645:                    out.write("// FIXME "+getClass()+"\n");
1646:                }
1647:                 */
1648:
1649:                public String toString() {
1650:                    return getName() + " (" + value + ")";
1651:                }
1652:            }
1653:
1654:            static private Map restrictionTypeValidSubElementTypeMap = null;
1655:            static {
1656:                restrictionTypeValidSubElementTypeMap = new HashMap();
1657:                restrictionTypeValidSubElementTypeMap.put(Annotation.class,
1658:                        null);
1659:            }
1660:
1661:            ////////////////////////////////////////////////////////////////
1662:            public class MaxExclusive extends RestrictionType implements 
1663:                    DataTypeRestriction {
1664:                public MaxExclusive(String value) {
1665:                    super (value);
1666:                }
1667:
1668:                public String getName() {
1669:                    return "maxExclusive";
1670:                }
1671:
1672:                protected RestrictionType newInstance(String value) {
1673:                    return new MaxExclusive(value);
1674:                }
1675:
1676:                public void genRestriction(Writer out, String var, String type,
1677:                        String failVar, boolean passCheck) throws IOException {
1678:                    if (!passCheck) {
1679:                        out.write("if ("
1680:                                + JavaUtil.compareToText(var, type, value)
1681:                                + " >= 0) {\n");
1682:                        out.write(failVar + " = true;\n");
1683:                        out.write("}\n");
1684:                    } else {
1685:                        out.write("if ("
1686:                                + JavaUtil.compareToText(var, type, value)
1687:                                + " < 0) {\n");
1688:                        out.write(failVar + " = true;\n");
1689:                        out.write("}\n");
1690:                    }
1691:                }
1692:            }
1693:
1694:            ////////////////////////////////////////////////////////////////
1695:            public class MinExclusive extends RestrictionType implements 
1696:                    DataTypeRestriction {
1697:                public MinExclusive(String value) {
1698:                    super (value);
1699:                }
1700:
1701:                public String getName() {
1702:                    return "minExclusive";
1703:                }
1704:
1705:                protected RestrictionType newInstance(String value) {
1706:                    return new MinExclusive(value);
1707:                }
1708:
1709:                public void genRestriction(Writer out, String var, String type,
1710:                        String failVar, boolean passCheck) throws IOException {
1711:                    if (!passCheck) {
1712:                        out.write("if ("
1713:                                + JavaUtil.compareToText(var, type, value)
1714:                                + " <= 0) {\n");
1715:                        out.write(failVar + " = true;\n");
1716:                        out.write("}\n");
1717:                    } else {
1718:                        out.write("if ("
1719:                                + JavaUtil.compareToText(var, type, value)
1720:                                + " > 0) {\n");
1721:                        out.write(failVar + " = true;\n");
1722:                        out.write("}\n");
1723:                    }
1724:                }
1725:            }
1726:
1727:            ////////////////////////////////////////////////////////////////
1728:            public class Enumeration extends RestrictionType implements 
1729:                    DataEnumRestriction {
1730:                public Enumeration(String value) {
1731:                    super (value);
1732:                }
1733:
1734:                public String getName() {
1735:                    return "enumeration";
1736:                }
1737:
1738:                protected RestrictionType newInstance(String value) {
1739:                    return new Enumeration(value);
1740:                }
1741:
1742:                public void genRestriction(Writer out, String type)
1743:                        throws IOException {
1744:                    out.write(JavaUtil.instanceFrom(type, value));
1745:                }
1746:            }
1747:
1748:            ////////////////////////////////////////////////////////////////
1749:            public class Pattern extends RestrictionType implements 
1750:                    DataTypeRestriction {
1751:                public Pattern(String value) {
1752:                    super (value);
1753:                }
1754:
1755:                public String getName() {
1756:                    return "pattern";
1757:                }
1758:
1759:                protected RestrictionType newInstance(String value) {
1760:                    return new Pattern(value);
1761:                }
1762:
1763:                public void genRestriction(Writer out, String var, String type,
1764:                        String failVar, boolean passCheck) throws IOException {
1765:                    if (!passCheck) {
1766:                        out.write("if (!("
1767:                                + JavaUtil.typeToString(type, var)
1768:                                + ").matches("
1769:                                + JavaUtil.instanceFrom("java.lang.String",
1770:                                        value) + ")) {\n");
1771:                        out.write(failVar + " = true;\n");
1772:                        out.write("}\n");
1773:                    } else {
1774:                        out.write("if (("
1775:                                + JavaUtil.typeToString(type, var)
1776:                                + ").matches("
1777:                                + JavaUtil.instanceFrom("java.lang.String",
1778:                                        value) + ")) {\n");
1779:                        out.write(failVar + " = true;\n");
1780:                        out.write("}\n");
1781:                    }
1782:                }
1783:            }
1784:
1785:            ////////////////////////////////////////////////////////////////
1786:            public class MinLength extends RestrictionType implements 
1787:                    DataTypeRestriction {
1788:                public MinLength(String value) {
1789:                    super (value);
1790:                }
1791:
1792:                public String getName() {
1793:                    return "minLength";
1794:                }
1795:
1796:                protected RestrictionType newInstance(String value) {
1797:                    return new MinLength(value);
1798:                }
1799:
1800:                public void genRestriction(Writer out, String var, String type,
1801:                        String failVar, boolean passCheck) throws IOException {
1802:                    if (!passCheck) {
1803:                        out.write("if ((" + JavaUtil.typeToString(type, var)
1804:                                + ").length() < " + value + ") {\n");
1805:                        out.write(failVar + " = true;\n");
1806:                        out.write("}\n");
1807:                    } else {
1808:                        out.write("if ((" + JavaUtil.typeToString(type, var)
1809:                                + ").length() >= " + value + ") {\n");
1810:                        out.write(failVar + " = true;\n");
1811:                        out.write("}\n");
1812:                    }
1813:                }
1814:            }
1815:
1816:            ////////////////////////////////////////////////////////////////
1817:            public class MaxLength extends RestrictionType implements 
1818:                    DataTypeRestriction {
1819:                public MaxLength(String value) {
1820:                    super (value);
1821:                }
1822:
1823:                public String getName() {
1824:                    return "maxLength";
1825:                }
1826:
1827:                protected RestrictionType newInstance(String value) {
1828:                    return new MaxLength(value);
1829:                }
1830:
1831:                public void genRestriction(Writer out, String var, String type,
1832:                        String failVar, boolean passCheck) throws IOException {
1833:                    if (!passCheck) {
1834:                        out.write("if ((" + JavaUtil.typeToString(type, var)
1835:                                + ").length() > " + value + ") {\n");
1836:                        out.write(failVar + " = true;\n");
1837:                        out.write("}\n");
1838:                    } else {
1839:                        out.write("if ((" + JavaUtil.typeToString(type, var)
1840:                                + ").length() <= " + value + ") {\n");
1841:                        out.write(failVar + " = true;\n");
1842:                        out.write("}\n");
1843:                    }
1844:                }
1845:            }
1846:
1847:            ////////////////////////////////////////////////////////////////
1848:            public class TotalDigits extends RestrictionType implements 
1849:                    DataTypeRestriction {
1850:                public TotalDigits(String value) {
1851:                    super (value);
1852:                }
1853:
1854:                public String getName() {
1855:                    return "totalDigits";
1856:                }
1857:
1858:                protected RestrictionType newInstance(String value) {
1859:                    return new TotalDigits(value);
1860:                }
1861:
1862:                public void genRestriction(Writer out, String var, String type,
1863:                        String failVar, boolean passCheck) throws IOException {
1864:                    if (!passCheck) {
1865:                        out.write("{\n");
1866:                        out.write("String _tmp = "
1867:                                + JavaUtil.typeToString(type, var) + ";\n");
1868:                        out.write("int digitCount = 0;\n");
1869:                        out
1870:                                .write("for (int _index1 = 0; _index1 < _tmp.length(); ++_index1) {\n");
1871:                        out
1872:                                .write("if (Character.isDigit(_tmp.charAt(_index1))) {\n");
1873:                        out.write("++digitCount;\n");
1874:                        out.write("if (digitCount > " + value + ") {\n");
1875:                        out.write(failVar + " = true;\n");
1876:                        out.write("break;\n");
1877:                        out.write("}\n");
1878:                        out.write("}\n");
1879:                        out.write("}\n");
1880:                        out.write("}\n");
1881:                    } else {
1882:                        out.write("{\n");
1883:                        out.write("String _tmp = "
1884:                                + JavaUtil.typeToString(type, var) + ";\n");
1885:                        out.write("int digitCount = 0;\n");
1886:                        out
1887:                                .write("for (int _index1 = 0; _index1 < _tmp.length(); ++_index1) {\n");
1888:                        out
1889:                                .write("if (Character.isDigit(_tmp.charAt(_index1))) {\n");
1890:                        out.write("++digitCount;\n");
1891:                        out.write("}\n");
1892:                        out.write("}\n");
1893:                        out.write("if (digitCount <= " + value + ") {\n");
1894:                        out.write(failVar + " = true;\n");
1895:                        out.write("}\n");
1896:                        out.write("}\n");
1897:                    }
1898:                }
1899:            }
1900:
1901:            ////////////////////////////////////////////////////////////////
1902:            public class MinInclusive extends RestrictionType implements 
1903:                    DataTypeRestriction {
1904:                public MinInclusive(String value) {
1905:                    super (value);
1906:                }
1907:
1908:                public String getName() {
1909:                    return "minInclusive";
1910:                }
1911:
1912:                protected RestrictionType newInstance(String value) {
1913:                    return new MinInclusive(value);
1914:                }
1915:
1916:                public void genRestriction(Writer out, String var, String type,
1917:                        String failVar, boolean passCheck) throws IOException {
1918:                    if (!passCheck) {
1919:                        out.write("if ("
1920:                                + JavaUtil.compareToText(var, type, value)
1921:                                + " < 0) {\n");
1922:                        out.write(failVar + " = true;\n");
1923:                        out.write("}\n");
1924:                    } else {
1925:                        out.write("if ("
1926:                                + JavaUtil.compareToText(var, type, value)
1927:                                + " >= 0) {\n");
1928:                        out.write(failVar + " = true;\n");
1929:                        out.write("}\n");
1930:                    }
1931:                }
1932:            }
1933:
1934:            ////////////////////////////////////////////////////////////////
1935:            public class MaxInclusive extends RestrictionType implements 
1936:                    DataTypeRestriction {
1937:                public MaxInclusive(String value) {
1938:                    super (value);
1939:                }
1940:
1941:                public String getName() {
1942:                    return "maxInclusive";
1943:                }
1944:
1945:                protected RestrictionType newInstance(String value) {
1946:                    return new MaxInclusive(value);
1947:                }
1948:
1949:                public void genRestriction(Writer out, String var, String type,
1950:                        String failVar, boolean passCheck) throws IOException {
1951:                    if (!passCheck) {
1952:                        out.write("if ("
1953:                                + JavaUtil.compareToText(var, type, value)
1954:                                + " > 0) {\n");
1955:                        out.write(failVar + " = true;\n");
1956:                        out.write("}\n");
1957:                    } else {
1958:                        out.write("if ("
1959:                                + JavaUtil.compareToText(var, type, value)
1960:                                + " <= 0) {\n");
1961:                        out.write(failVar + " = true;\n");
1962:                        out.write("}\n");
1963:                    }
1964:                }
1965:            }
1966:
1967:            ////////////////////////////////////////////////////////////////
1968:            public class FractionDigits extends RestrictionType implements 
1969:                    DataTypeRestriction {
1970:                public FractionDigits(String value) {
1971:                    super (value);
1972:                }
1973:
1974:                public String getName() {
1975:                    return "fractionDigits";
1976:                }
1977:
1978:                protected RestrictionType newInstance(String value) {
1979:                    return new FractionDigits(value);
1980:                }
1981:
1982:                public void genRestriction(Writer out, String var, String type,
1983:                        String failVar, boolean passCheck) throws IOException {
1984:                    if (!passCheck) {
1985:                        out.write("{\n");
1986:                        out.write("String _tmp = "
1987:                                + JavaUtil.typeToString(type, var) + ";\n");
1988:                        out.write("int dotPos = _tmp.indexOf('.');\n");
1989:                        out.write("if (dotPos >= 0) {\n");
1990:                        out
1991:                                .write("_tmp = _tmp.substring(dotPos+1, _tmp.length());\n");
1992:                        out.write("int digitCount = 0;\n");
1993:                        out
1994:                                .write("for (int _index1 = 0; _index1 < _tmp.length(); ++_index1) {\n");
1995:                        out
1996:                                .write("if (Character.isDigit(_tmp.charAt(_index1))) {\n");
1997:                        out.write("++digitCount;\n");
1998:                        out.write("if (digitCount > " + value + ") {\n");
1999:                        out.write(failVar + " = true;\n");
2000:                        out.write("break;\n");
2001:                        out.write("}\n");
2002:                        out.write("}\n");
2003:                        out.write("}\n");
2004:                        out.write("}\n");
2005:                        out.write("}\n");
2006:                    } else {
2007:                        out.write("{\n");
2008:                        out.write("String _tmp = "
2009:                                + JavaUtil.typeToString(type, var) + ";\n");
2010:                        out.write("int dotPos = _tmp.indexOf('.');\n");
2011:                        out.write("if (dotPos >= 0) {\n");
2012:                        out
2013:                                .write("_tmp = _tmp.substring(dotPos+1, _tmp.length());\n");
2014:                        out.write("int digitCount = 0;\n");
2015:                        out
2016:                                .write("for (int _index1 = 0; _index1 < _tmp.length(); ++_index1) {\n");
2017:                        out
2018:                                .write("if (Character.isDigit(_tmp.charAt(_index1))) {\n");
2019:                        out.write("++digitCount;\n");
2020:                        out.write("}\n");
2021:                        out.write("}\n");
2022:                        out.write("if (digitCount <= " + value + ") {\n");
2023:                        out.write(failVar + " = true;\n");
2024:                        out.write("}\n");
2025:                        out.write("}\n");
2026:                        out.write("else\n");
2027:                        out.write(failVar + " = true;\n");
2028:                        out.write("}\n");
2029:                    }
2030:                }
2031:            }
2032:
2033:            ////////////////////////////////////////////////////////////////
2034:            public class Length extends RestrictionType implements 
2035:                    DataTypeRestriction {
2036:                public Length(String value) {
2037:                    super (value);
2038:                }
2039:
2040:                public String getName() {
2041:                    return "length";
2042:                }
2043:
2044:                protected RestrictionType newInstance(String value) {
2045:                    return new Length(value);
2046:                }
2047:
2048:                public void genRestriction(Writer out, String var, String type,
2049:                        String failVar, boolean passCheck) throws IOException {
2050:                    if (!passCheck) {
2051:                        out.write("if (" + JavaUtil.typeToString(type, var)
2052:                                + ".length() != " + value + ") {\n");
2053:                        out.write(failVar + " = true;\n");
2054:                        out.write("}\n");
2055:                    } else {
2056:                        out.write("if (" + JavaUtil.typeToString(type, var)
2057:                                + ".length() == " + value + ") {\n");
2058:                        out.write(failVar + " = true;\n");
2059:                        out.write("}\n");
2060:                    }
2061:                }
2062:            }
2063:
2064:            ////////////////////////////////////////////////////////////////
2065:            public class WhiteSpace extends RestrictionType implements 
2066:                    DataTypeRestriction {
2067:                public WhiteSpace(String value) {
2068:                    super (value);
2069:                }
2070:
2071:                public String getName() {
2072:                    return "whiteSpace";
2073:                }
2074:
2075:                public boolean isPreserve() {
2076:                    return "preserve" == value;
2077:                }
2078:
2079:                public boolean isReplace() {
2080:                    return "replace" == value;
2081:                }
2082:
2083:                public boolean isCollapse() {
2084:                    return "collapse" == value;
2085:                }
2086:
2087:                public void validate() {
2088:                    super .validate();
2089:                    if (value == null || value.equals(""))
2090:                        throw new IllegalStateException(Common.getMessage(
2091:                                "MSG_InvalidWhiteSpaceValue", value));
2092:                    if (!(value == "preserve" || value == "replace" || value == "collapse"))
2093:                        throw new IllegalStateException(Common.getMessage(
2094:                                "MSG_InvalidWhiteSpaceValue", value));
2095:                }
2096:
2097:                protected RestrictionType newInstance(String value) {
2098:                    return new WhiteSpace(value);
2099:                }
2100:
2101:                public void genRestriction(Writer out, String var, String type,
2102:                        String failVar, boolean passCheck) throws IOException {
2103:                    // Does not cause verify changes
2104:                    out.write("// has whitespace restriction\n");
2105:                }
2106:            }
2107:
2108:            ////////////////////////////////////////////////////////////////
2109:            // the parent class for some others
2110:            public abstract class ElementInformationItem extends
2111:                    ContainsSubElements {
2112:                private String id;
2113:                private String name;
2114:
2115:                public ElementInformationItem() {
2116:                }
2117:
2118:                public ElementInformationItem(String id, String name) {
2119:                    this .id = id;
2120:                    this .name = name;
2121:                }
2122:
2123:                public String getContentName() {
2124:                    return name;
2125:                }
2126:
2127:                public String getId() {
2128:                    return id;
2129:                }
2130:
2131:                public void setId(String id) {
2132:                    this .id = id;
2133:                }
2134:
2135:                public String getElementName() {
2136:                    return name;
2137:                }
2138:
2139:                public void setElementName(String name) {
2140:                    this .name = name;
2141:                }
2142:
2143:                public boolean writeDTDName(StringBuffer out) {
2144:                    boolean hasNamedSubElements = writeDTDSubElementNames(out,
2145:                            true);
2146:                    return hasNamedSubElements;
2147:                }
2148:
2149:                public String getAttributeString() {
2150:                    StringBuffer sb = new StringBuffer();
2151:                    if (name != null)
2152:                        sb.append(" name='" + name + "'");
2153:                    if (id != null)
2154:                        sb.append(" id='" + id + "'");
2155:                    return sb.toString();
2156:                }
2157:
2158:                public void readSchema(org.w3c.dom.Element node) {
2159:                    String id = node.getAttribute("id"); // NOI18N
2160:                    String name = node.getAttribute("name"); // NOI18N
2161:                    ElementInformationItem el = newInstance();
2162:                    pushCurrent(el);
2163:                    if (id != null && !id.equals(""))
2164:                        el.setId(id);
2165:                    if (name != null && !name.equals(""))
2166:                        el.setElementName(name);
2167:                    read(node);
2168:                    popCurrent();
2169:                }
2170:
2171:                protected abstract ElementInformationItem newInstance();
2172:
2173:                public boolean equals(Object o) {
2174:                    if (!(o instanceof  ElementInformationItem))
2175:                        return false;
2176:                    ElementInformationItem el = (ElementInformationItem) o;
2177:                    if (id != el.id)
2178:                        return false;
2179:                    if (name != el.name)
2180:                        return false;
2181:
2182:                    return super .equals(el);
2183:                }
2184:
2185:                public int hashCode() {
2186:                    int result = 17;
2187:                    result = 37 * result + ((id == null) ? 0 : id.hashCode());
2188:                    result = 37 * result
2189:                            + ((name == null) ? 0 : name.hashCode());
2190:                    result = 37 * result + super .hashCode();
2191:                    return result;
2192:                }
2193:            }
2194:
2195:            ////////////////////////////////////////////////////////////////
2196:            public class Key extends ElementInformationItem {
2197:                public Key() {
2198:                }
2199:
2200:                public String getName() {
2201:                    return "key";
2202:                }
2203:
2204:                public Map validSubElementTypeMap() {
2205:                    return keyValidSubElementTypeMap;
2206:                }
2207:
2208:                protected ElementInformationItem newInstance() {
2209:                    return new Key();
2210:                }
2211:            }
2212:
2213:            static private Map keyValidSubElementTypeMap = null;
2214:            static {
2215:                keyValidSubElementTypeMap = new HashMap();
2216:                keyValidSubElementTypeMap.put(Annotation.class, null);
2217:                keyValidSubElementTypeMap.put(Selector.class, null);
2218:                keyValidSubElementTypeMap.put(Field.class, null);
2219:            }
2220:
2221:            ////////////////////////////////////////////////////////////////
2222:            public class Unique extends ElementInformationItem {
2223:                public Unique() {
2224:                }
2225:
2226:                public String getName() {
2227:                    return "unique";
2228:                }
2229:
2230:                public Map validSubElementTypeMap() {
2231:                    return uniqueValidSubElementTypeMap;
2232:                }
2233:
2234:                protected ElementInformationItem newInstance() {
2235:                    return new Unique();
2236:                }
2237:            }
2238:
2239:            static private Map uniqueValidSubElementTypeMap = null;
2240:            static {
2241:                uniqueValidSubElementTypeMap = new HashMap();
2242:                uniqueValidSubElementTypeMap.put(Annotation.class, null);
2243:                uniqueValidSubElementTypeMap.put(Selector.class, null);
2244:                uniqueValidSubElementTypeMap.put(Field.class, null);
2245:            }
2246:
2247:            ////////////////////////////////////////////////////////////////
2248:            public class KeyRef extends ElementInformationItem {
2249:                private String refer;
2250:
2251:                public KeyRef() {
2252:                }
2253:
2254:                public String getName() {
2255:                    return "keyref";
2256:                }
2257:
2258:                public void setRefer(String refer) {
2259:                    this .refer = refer;
2260:                }
2261:
2262:                public String getRefer() {
2263:                    return refer;
2264:                }
2265:
2266:                public String getAttributeString() {
2267:                    StringBuffer sb = new StringBuffer(super 
2268:                            .getAttributeString());
2269:                    if (refer != null)
2270:                        sb.append(" refer='" + refer + "'");
2271:                    return sb.toString();
2272:                }
2273:
2274:                public void readSchema(org.w3c.dom.Element node) {
2275:                    String id = node.getAttribute("id"); // NOI18N
2276:                    String name = node.getAttribute("name"); // NOI18N
2277:                    String refer = node.getAttribute("refer"); // NOI18N
2278:                    KeyRef el = new KeyRef();
2279:                    pushCurrent(el);
2280:                    if (id != null && !id.equals(""))
2281:                        el.setId(id);
2282:                    if (name != null && !name.equals(""))
2283:                        el.setElementName(name);
2284:                    if (refer != null && !refer.equals(""))
2285:                        el.setRefer(refer);
2286:                    read(node);
2287:                    popCurrent();
2288:                }
2289:
2290:                public Map validSubElementTypeMap() {
2291:                    return keyrefValidSubElementTypeMap;
2292:                }
2293:
2294:                protected ElementInformationItem newInstance() {
2295:                    return new KeyRef();
2296:                }
2297:            }
2298:
2299:            static private Map keyrefValidSubElementTypeMap = null;
2300:            static {
2301:                keyrefValidSubElementTypeMap = new HashMap();
2302:                keyrefValidSubElementTypeMap.put(Annotation.class, null);
2303:                keyrefValidSubElementTypeMap.put(Selector.class, null);
2304:                keyrefValidSubElementTypeMap.put(Field.class, null);
2305:            }
2306:
2307:            ////////////////////////////////////////////////////////////////
2308:            public abstract class SelectorOrField extends ContainsSubElements {
2309:                private String id;
2310:                private String xpath;
2311:
2312:                public SelectorOrField() {
2313:                }
2314:
2315:                public String getContentName() {
2316:                    return null;
2317:                }
2318:
2319:                public String getId() {
2320:                    return id;
2321:                }
2322:
2323:                public void setId(String id) {
2324:                    this .id = id;
2325:                }
2326:
2327:                public String getXPath() {
2328:                    return xpath;
2329:                }
2330:
2331:                public void setXPath(String xpath) {
2332:                    this .xpath = xpath;
2333:                }
2334:
2335:                public String getAttributeString() {
2336:                    StringBuffer sb = new StringBuffer();
2337:                    if (xpath != null)
2338:                        sb.append(" xpath='" + xpath + "'");
2339:                    if (id != null)
2340:                        sb.append(" id='" + id + "'");
2341:                    return sb.toString();
2342:                }
2343:
2344:                public void readSchema(org.w3c.dom.Element node) {
2345:                    String id = node.getAttribute("id"); // NOI18N
2346:                    String xpath = node.getAttribute("xpath"); // NOI18N
2347:                    SelectorOrField el = newInstance();
2348:                    pushCurrent(el);
2349:                    if (id != null && !id.equals(""))
2350:                        el.setId(id);
2351:                    if (xpath != null && !xpath.equals(""))
2352:                        el.setXPath(xpath);
2353:                    read(node);
2354:                    popCurrent();
2355:                }
2356:
2357:                protected abstract SelectorOrField newInstance();
2358:
2359:                public void writeDTD(StringBuffer out) {
2360:                    // ?
2361:                }
2362:
2363:                public boolean writeDTDName(StringBuffer out) {
2364:                    // ?
2365:                    return false;
2366:                }
2367:
2368:                public boolean equals(Object o) {
2369:                    if (!(o instanceof  SelectorOrField))
2370:                        return false;
2371:                    SelectorOrField el = (SelectorOrField) o;
2372:                    if (id == null) {
2373:                        if (el.id != null)
2374:                            return false;
2375:                    } else if (id != el.id)
2376:                        return false;
2377:                    if (xpath == null) {
2378:                        if (el.xpath != null)
2379:                            return false;
2380:                    } else if (xpath != el.xpath)
2381:                        return false;
2382:
2383:                    return super .equals(el);
2384:                }
2385:
2386:                public int hashCode() {
2387:                    int result = 17;
2388:                    result = 37 * result + ((id == null) ? 0 : id.hashCode());
2389:                    result = 37 * result
2390:                            + ((xpath == null) ? 0 : xpath.hashCode());
2391:                    result = 37 * result + super .hashCode();
2392:                    return result;
2393:                }
2394:            }
2395:
2396:            ////////////////////////////////////////////////////////////////
2397:            public class Selector extends SelectorOrField {
2398:                public Selector() {
2399:                }
2400:
2401:                public String getName() {
2402:                    return "selector";
2403:                }
2404:
2405:                public Map validSubElementTypeMap() {
2406:                    return selectorValidSubElementTypeMap;
2407:                }
2408:
2409:                protected SelectorOrField newInstance() {
2410:                    return new Selector();
2411:                }
2412:            }
2413:
2414:            static private Map selectorValidSubElementTypeMap = null;
2415:            static {
2416:                selectorValidSubElementTypeMap = new HashMap();
2417:                selectorValidSubElementTypeMap.put(Annotation.class, null);
2418:            }
2419:
2420:            public class Field extends SelectorOrField {
2421:                public Field() {
2422:                }
2423:
2424:                public String getName() {
2425:                    return "field";
2426:                }
2427:
2428:                public Map validSubElementTypeMap() {
2429:                    return fieldValidSubElementTypeMap;
2430:                }
2431:
2432:                protected SelectorOrField newInstance() {
2433:                    return new Field();
2434:                }
2435:            }
2436:
2437:            static private Map fieldValidSubElementTypeMap = null;
2438:            static {
2439:                fieldValidSubElementTypeMap = new HashMap();
2440:                fieldValidSubElementTypeMap.put(Annotation.class, null);
2441:            }
2442:
2443:            ////////////////////////////////////////////////////////////////
2444:            public class Include extends ElementExpr {
2445:                private String schemaLocation;
2446:
2447:                public Include(String schemaLocation) {
2448:                    this .schemaLocation = schemaLocation;
2449:                }
2450:
2451:                public String getContentName() {
2452:                    return null;
2453:                }
2454:
2455:                public void readSchema(org.w3c.dom.Element node) {
2456:                    String schemaLocation = node.getAttribute("schemaLocation"); // NOI18N
2457:                    if (includedAlready.containsKey(schemaLocation))
2458:                        return;
2459:                    includedAlready.put(schemaLocation, null);
2460:
2461:                    //System.out.println("Attempting to include "+schemaLocation);
2462:                    ParserSchemaState oldState = new ParserSchemaState();
2463:                    try {
2464:                        readSchemaFromLocation(schemaLocation);
2465:                    } catch (org.xml.sax.SAXException e) {
2466:                        throw new Schema2BeansRuntimeException(
2467:                                Common.getMessage("MSG_FailedToParse",
2468:                                        schemaLocation), e);
2469:                    } catch (java.io.IOException e) {
2470:                        throw new Schema2BeansRuntimeException(
2471:                                Common.getMessage("MSG_FailedToParse",
2472:                                        schemaLocation), e);
2473:                    } finally {
2474:                        oldState.reload();
2475:                    }
2476:                    //System.out.println("Finished reading include\n");
2477:                    /*
2478:                      if (oldNamespaceTable != null)
2479:                      namespaceTable = oldNamespaceTable;
2480:                     */
2481:                }
2482:
2483:                public ElementExpr optimize() {
2484:                    return this ;
2485:                }
2486:
2487:                public void validate() {
2488:                }
2489:
2490:                public String getName() {
2491:                    return "include";
2492:                }
2493:
2494:                public void writeDTD(StringBuffer out) {
2495:                    // ?
2496:                }
2497:
2498:                public boolean writeDTDName(StringBuffer out) {
2499:                    // ?
2500:                    return false;
2501:                }
2502:
2503:                public void writeXMLSchema(XMLWriter out) throws IOException {
2504:                    out.startTag(getXSDNamespace(), getName(), false);
2505:                    if (schemaLocation != null) {
2506:                        out.write(" schemaLocation='");
2507:                        out.write(schemaLocation);
2508:                        out.write("'");
2509:                    }
2510:                    out.finishStartTag(false, true);
2511:                }
2512:
2513:                public String toString() {
2514:                    if (schemaLocation == null)
2515:                        return getName();
2516:                    else
2517:                        return getName() + " schemaLocation=" + schemaLocation;
2518:                }
2519:
2520:                public boolean equals(Object o) {
2521:                    if (!(o instanceof  Include))
2522:                        return false;
2523:                    Include el = (Include) o;
2524:                    if (schemaLocation == null) {
2525:                        if (el.schemaLocation != null)
2526:                            return false;
2527:                    } else if (!schemaLocation.equals(el.schemaLocation))
2528:                        return false;
2529:
2530:                    return super .equals(el);
2531:                }
2532:
2533:                public int hashCode() {
2534:                    int result = 17;
2535:                    result = 37
2536:                            * result
2537:                            + ((schemaLocation == null) ? 0 : schemaLocation
2538:                                    .hashCode());
2539:                    result = 37 * result + super .hashCode();
2540:                    return result;
2541:                }
2542:            }
2543:
2544:            ////////////////////////////////////////////////////////////////
2545:            public class Import extends ElementExpr {
2546:                private String theNamespace;
2547:                private String schemaLocation;
2548:
2549:                public Import() {
2550:                }
2551:
2552:                public String getContentName() {
2553:                    return null;
2554:                }
2555:
2556:                public String getNamespace() {
2557:                    return theNamespace;
2558:                }
2559:
2560:                public void setNamespace(String namespace) {
2561:                    theNamespace = namespace;
2562:                }
2563:
2564:                public String getSchemaLocation() {
2565:                    return schemaLocation;
2566:                }
2567:
2568:                public void setSchemaLocation(String schemaLocation) {
2569:                    this .schemaLocation = schemaLocation;
2570:                }
2571:
2572:                public void readSchema(org.w3c.dom.Element node) {
2573:                    String namespace = node.getAttribute("namespace"); // NOI18N
2574:                    String schemaLocation = node.getAttribute("schemaLocation"); // NOI18N
2575:                    //System.out.println("Attempting to import "+schemaLocation);
2576:                    ParserSchemaState oldState = new ParserSchemaState();
2577:                    if (namespace != null && !namespace.equals(""))
2578:                        targetNamespace = namespace;
2579:                    try {
2580:                        readSchemaFromLocation(schemaLocation);
2581:                    } catch (org.xml.sax.SAXException e) {
2582:                        throw new Schema2BeansRuntimeException(
2583:                                Common.getMessage("MSG_FailedToParse",
2584:                                        schemaLocation), e);
2585:                    } catch (java.io.IOException e) {
2586:                        throw new Schema2BeansRuntimeException(
2587:                                Common.getMessage("MSG_FailedToParse",
2588:                                        schemaLocation), e);
2589:                    } finally {
2590:                        oldState.reload();
2591:                    }
2592:                    //System.out.println("Finished reading import\n");
2593:                }
2594:
2595:                public ElementExpr optimize() {
2596:                    return this ;
2597:                }
2598:
2599:                public void validate() {
2600:                }
2601:
2602:                public String getName() {
2603:                    return "import";
2604:                }
2605:
2606:                public void writeDTD(StringBuffer out) {
2607:                    // ?
2608:                }
2609:
2610:                public boolean writeDTDName(StringBuffer out) {
2611:                    // ?
2612:                    return false;
2613:                }
2614:
2615:                public void writeXMLSchema(XMLWriter out) throws IOException {
2616:                    out.startTag(getXSDNamespace(), getName(), false);
2617:                    if (theNamespace != null) {
2618:                        out.write(" theNamespace='");
2619:                        out.write(theNamespace);
2620:                        out.write("'");
2621:                    }
2622:                    if (schemaLocation != null) {
2623:                        out.write(" schemaLocation='");
2624:                        out.write(schemaLocation);
2625:                        out.write("'");
2626:                    }
2627:                    out.finishStartTag(false, true);
2628:                }
2629:
2630:                public boolean equals(Object o) {
2631:                    if (!(o instanceof  Import))
2632:                        return false;
2633:                    Import el = (Import) o;
2634:                    if (theNamespace == null) {
2635:                        if (el.theNamespace != null)
2636:                            return false;
2637:                    } else if (!theNamespace.equals(el.theNamespace))
2638:                        return false;
2639:                    if (schemaLocation == null) {
2640:                        if (el.schemaLocation != null)
2641:                            return false;
2642:                    } else if (!schemaLocation.equals(el.schemaLocation))
2643:                        return false;
2644:
2645:                    return super .equals(el);
2646:                }
2647:
2648:                public int hashCode() {
2649:                    int result = 17;
2650:                    result = 37
2651:                            * result
2652:                            + ((theNamespace == null) ? 0 : theNamespace
2653:                                    .hashCode());
2654:                    result = 37
2655:                            * result
2656:                            + ((schemaLocation == null) ? 0 : schemaLocation
2657:                                    .hashCode());
2658:                    result = 37 * result + super .hashCode();
2659:                    return result;
2660:                }
2661:            }
2662:
2663:            ////////////////////////////////////////////////////////////////
2664:            // See XML Schema sequence.
2665:            public abstract class ModelGroup extends ContainsSubElements
2666:                    implements  MinMaxOccurs {
2667:                private String minOccurs;
2668:                private String maxOccurs;
2669:
2670:                public ModelGroup() {
2671:                    super ();
2672:                    minOccurs = "1";
2673:                    maxOccurs = "1";
2674:                }
2675:
2676:                public String getContentName() {
2677:                    return null;
2678:                }
2679:
2680:                public void setMinOccurs(String mino) {
2681:                    if (mino == null)
2682:                        mino = "1";
2683:                    minOccurs = mino.intern();
2684:                }
2685:
2686:                public void setMaxOccurs(String maxo) {
2687:                    if (maxo == null)
2688:                        maxo = "1";
2689:                    maxOccurs = maxo.intern();
2690:                }
2691:
2692:                public String getMinOccurs() {
2693:                    return minOccurs;
2694:                }
2695:
2696:                public String getMaxOccurs() {
2697:                    return maxOccurs;
2698:                }
2699:
2700:                /**
2701:                 * If we have no subelements, we ask to be deleted.
2702:                 * If we have only 1 element and attributes haven't been set, then
2703:                 * we replace ourselves with that element.
2704:                 */
2705:                public ElementExpr optimize() {
2706:                    super .optimize();
2707:                    if (subElements.size() == 0)
2708:                        return null;
2709:                    /*
2710:                    if (subElements.size() == 1 && minOccurs == "1" && maxOccurs == "1")
2711:                        return (ElementExpr) subElements.iterator().next();
2712:                     */
2713:                    return this ;
2714:                }
2715:
2716:                public boolean writeDTDName(StringBuffer out) {
2717:                    boolean many = ("unbounded" == maxOccurs);
2718:                    boolean hasNamedSubElements = writeDTDSubElementNames(out,
2719:                            true);
2720:                    if (many)
2721:                        out.append("*");
2722:                    return hasNamedSubElements;
2723:                }
2724:
2725:                public String getAttributeString() {
2726:                    StringBuffer sb = new StringBuffer();
2727:                    if (minOccurs != "1")
2728:                        sb.append(" minOccurs='" + minOccurs + "'");
2729:                    if (maxOccurs != "1")
2730:                        sb.append(" maxOccurs='" + maxOccurs + "'");
2731:                    return sb.toString();
2732:                }
2733:
2734:                public void readSchema(org.w3c.dom.Element node) {
2735:                    String minOccurs = node.getAttribute("minOccurs"); // NOI18N
2736:                    String maxOccurs = node.getAttribute("maxOccurs"); // NOI18N
2737:                    ModelGroup el = newInstance();
2738:                    pushCurrent(el);
2739:                    if (minOccurs != null && !minOccurs.equals(""))
2740:                        el.setMinOccurs(minOccurs);
2741:                    if (maxOccurs != null && !maxOccurs.equals(""))
2742:                        el.setMaxOccurs(maxOccurs);
2743:                    read(node);
2744:                    popCurrent();
2745:                }
2746:
2747:                protected abstract ModelGroup newInstance();
2748:
2749:                public boolean equals(Object o) {
2750:                    if (!(o instanceof  ModelGroup))
2751:                        return false;
2752:                    ModelGroup el = (ModelGroup) o;
2753:                    if (minOccurs != el.minOccurs)
2754:                        return false;
2755:                    if (maxOccurs != el.maxOccurs)
2756:                        return false;
2757:
2758:                    return super .equals(el);
2759:                }
2760:
2761:                public int hashCode() {
2762:                    int result = 17;
2763:                    result = 37 * result
2764:                            + ((minOccurs == null) ? 0 : minOccurs.hashCode());
2765:                    result = 37 * result
2766:                            + ((maxOccurs == null) ? 0 : maxOccurs.hashCode());
2767:                    result = 37 * result + super .hashCode();
2768:                    return result;
2769:                }
2770:            }
2771:
2772:            ////////////////////////////////////////////////////////////////
2773:            // See XML Schema sequence.
2774:            public class Sequence extends ModelGroup {
2775:                public Sequence() {
2776:                }
2777:
2778:                public String getName() {
2779:                    return "sequence";
2780:                }
2781:
2782:                public Map validSubElementTypeMap() {
2783:                    return sequenceValidSubElementTypeMap;
2784:                }
2785:
2786:                protected ModelGroup newInstance() {
2787:                    return new Sequence();
2788:                }
2789:            }
2790:
2791:            static private Map sequenceValidSubElementTypeMap = null;
2792:            static {
2793:                sequenceValidSubElementTypeMap = new HashMap();
2794:                sequenceValidSubElementTypeMap.put(Annotation.class, null);
2795:                sequenceValidSubElementTypeMap.put(Element.class, null);
2796:                sequenceValidSubElementTypeMap.put(Any.class, null);
2797:                sequenceValidSubElementTypeMap.put(Choice.class, null);
2798:                sequenceValidSubElementTypeMap.put(Sequence.class, null);
2799:                sequenceValidSubElementTypeMap.put(Group.class, null);
2800:            }
2801:
2802:            ////////////////////////////////////////////////////////////////
2803:            public class Choice extends ModelGroup {
2804:                public Choice() {
2805:                }
2806:
2807:                public String getName() {
2808:                    return "choice";
2809:                }
2810:
2811:                public Map validSubElementTypeMap() {
2812:                    return choiceValidSubElementTypeMap;
2813:                }
2814:
2815:                protected ModelGroup newInstance() {
2816:                    return new Choice();
2817:                }
2818:            }
2819:
2820:            static private Map choiceValidSubElementTypeMap = null;
2821:            static {
2822:                choiceValidSubElementTypeMap = new HashMap();
2823:                choiceValidSubElementTypeMap.put(Annotation.class, null);
2824:                choiceValidSubElementTypeMap.put(Element.class, null);
2825:                choiceValidSubElementTypeMap.put(Any.class, null);
2826:                choiceValidSubElementTypeMap.put(Choice.class, null);
2827:                choiceValidSubElementTypeMap.put(Sequence.class, null);
2828:                choiceValidSubElementTypeMap.put(Group.class, null);
2829:            }
2830:
2831:            ////////////////////////////////////////////////////////////////
2832:            public class All extends ModelGroup {
2833:                public All() {
2834:                }
2835:
2836:                public String getName() {
2837:                    return "all";
2838:                }
2839:
2840:                public Map validSubElementTypeMap() {
2841:                    return allValidSubElementTypeMap;
2842:                }
2843:
2844:                protected ModelGroup newInstance() {
2845:                    return new All();
2846:                }
2847:            }
2848:
2849:            static private Map allValidSubElementTypeMap = null;
2850:            static {
2851:                allValidSubElementTypeMap = new HashMap();
2852:                allValidSubElementTypeMap.put(Annotation.class, null);
2853:                allValidSubElementTypeMap.put(Element.class, null);
2854:                allValidSubElementTypeMap.put(Any.class, null);
2855:            }
2856:
2857:            ////////////////////////////////////////////////////////////////
2858:            public class Group extends ModelGroup implements  CanRef {
2859:                private String name;
2860:                private String ref;
2861:
2862:                public Group() {
2863:                }
2864:
2865:                public Group(String n) {
2866:                    if (n != null && !n.equals("")) {
2867:                        name = normalizeTargetNamespace(n).intern();
2868:                        putSchemaTypeDef(name, this );
2869:                    }
2870:                }
2871:
2872:                public ElementExpr optimize() {
2873:                    if (ref != null)
2874:                        return this ;
2875:                    return super .optimize();
2876:                }
2877:
2878:                public String getName() {
2879:                    return "group";
2880:                }
2881:
2882:                public String getGroupName() {
2883:                    return name;
2884:                }
2885:
2886:                public boolean hasRef() {
2887:                    return getRef() != null;
2888:                }
2889:
2890:                /**
2891:                 * May return null.
2892:                 */
2893:                public String getRef() {
2894:                    return ref;
2895:                }
2896:
2897:                public Group getRefGroup() {
2898:                    if (ref == null)
2899:                        return null;
2900:                    Object o = getSchemaTypeDef(ref);
2901:                    if (o instanceof  Group) {
2902:                        Group referredGroup = (Group) o;
2903:                        return referredGroup;
2904:                    } else {
2905:                        throw new IllegalStateException(Common.getMessage(
2906:                                "MSG_FailedToFindRef", ref, this .toString()));
2907:                    }
2908:                }
2909:
2910:                public ElementExpr getRefElementExpr() {
2911:                    return getRefGroup();
2912:                }
2913:
2914:                public Map validSubElementTypeMap() {
2915:                    return groupValidSubElementTypeMap;
2916:                }
2917:
2918:                public String getAttributeString() {
2919:                    StringBuffer sb = new StringBuffer();
2920:                    if (name != null)
2921:                        sb.append(" name='" + name + "'");
2922:                    if (ref != null)
2923:                        sb.append(" ref='" + ref + "'");
2924:                    return sb.toString();
2925:                }
2926:
2927:                public void readSchema(org.w3c.dom.Element node) {
2928:                    String myName = node.getAttribute("name"); // NOI18N
2929:                    String myRef = node.getAttribute("ref"); // NOI18N
2930:                    Group g = new Group(myName);
2931:                    if (myRef != null && !myRef.equals(""))
2932:                        g.ref = myRef.intern();
2933:                    pushCurrent(g);
2934:                    read(node);
2935:                    popCurrent();
2936:                }
2937:
2938:                protected ModelGroup newInstance() {
2939:                    return new Group();
2940:                }
2941:
2942:                public boolean equals(Object o) {
2943:                    if (!(o instanceof  AttributeGroup))
2944:                        return false;
2945:                    AttributeGroup el = (AttributeGroup) o;
2946:                    if (name != el.name)
2947:                        return false;
2948:                    if (ref != el.ref)
2949:                        return false;
2950:
2951:                    return super .equals(el);
2952:                }
2953:
2954:                public int hashCode() {
2955:                    int result = 17;
2956:                    result = 37 * result
2957:                            + ((name == null) ? 0 : name.hashCode());
2958:                    result = 37 * result + ((ref == null) ? 0 : ref.hashCode());
2959:                    result = 37 * result + super .hashCode();
2960:                    return result;
2961:                }
2962:            }
2963:
2964:            static private Map groupValidSubElementTypeMap = null;
2965:            static {
2966:                groupValidSubElementTypeMap = new HashMap();
2967:                groupValidSubElementTypeMap.put(All.class, null);
2968:                groupValidSubElementTypeMap.put(Choice.class, null);
2969:                groupValidSubElementTypeMap.put(Sequence.class, null);
2970:                groupValidSubElementTypeMap.put(Annotation.class, null);
2971:            }
2972:
2973:            ////////////////////////////////////////////////////////////////
2974:            // See XML Schema annotation
2975:            // (an XML Schema comment)
2976:            public class Annotation extends ContainsSubElements {
2977:                public Annotation() {
2978:                }
2979:
2980:                public String getName() {
2981:                    return "annotation";
2982:                }
2983:
2984:                public String getContentName() {
2985:                    return null;
2986:                }
2987:
2988:                public ElementExpr optimize() {
2989:                    super .optimize();
2990:                    if (subElements.size() == 0)
2991:                        return null;
2992:                    return this ;
2993:                }
2994:
2995:                public boolean compressWhiteSpaceInner() {
2996:                    return true;
2997:                }
2998:
2999:                public boolean writeDTDName(StringBuffer out) {
3000:                    return false;
3001:                }
3002:
3003:                public void readSchema(org.w3c.dom.Element node) {
3004:                    Annotation el = new Annotation();
3005:                    pushCurrent(el);
3006:                    read(node);
3007:                    popCurrent();
3008:                }
3009:
3010:                public Map validSubElementTypeMap() {
3011:                    return annotationValidSubElementTypeMap;
3012:                }
3013:            }
3014:
3015:            static private Map annotationValidSubElementTypeMap = null;
3016:            static {
3017:                annotationValidSubElementTypeMap = new HashMap();
3018:                annotationValidSubElementTypeMap.put(AppInfo.class, null);
3019:                annotationValidSubElementTypeMap.put(Documentation.class, null);
3020:            }
3021:
3022:            ////////////////////////////////////////////////////////////////
3023:            // See XML Schema appInfo
3024:            public class AppInfo extends ContainsSubElements {
3025:                public AppInfo() {
3026:                }
3027:
3028:                public String getContentName() {
3029:                    return null;
3030:                }
3031:
3032:                public boolean compressWhiteSpaceOuter() {
3033:                    return true;
3034:                }
3035:
3036:                public boolean compressWhiteSpaceInner() {
3037:                    return true;
3038:                }
3039:
3040:                public String getName() {
3041:                    return "appinfo";
3042:                }
3043:
3044:                public ElementExpr optimize() {
3045:                    super .optimize();
3046:                    if (subElements.size() == 0)
3047:                        return null;
3048:                    return this ;
3049:                }
3050:
3051:                public boolean writeDTDName(StringBuffer out) {
3052:                    return false;
3053:                }
3054:
3055:                public void readSchema(org.w3c.dom.Element node) {
3056:                    AppInfo el = new AppInfo();
3057:                    pushCurrent(el);
3058:                    read(node);
3059:                    popCurrent();
3060:                }
3061:
3062:                public Map validSubElementTypeMap() {
3063:                    return appInfoValidSubElementTypeMap;
3064:                }
3065:            }
3066:
3067:            static private Map appInfoValidSubElementTypeMap = null;
3068:            static {
3069:                appInfoValidSubElementTypeMap = new HashMap();
3070:                appInfoValidSubElementTypeMap.put(AnyNode.class, null);
3071:                appInfoValidSubElementTypeMap.put(TextNode.class, null);
3072:            }
3073:
3074:            ////////////////////////////////////////////////////////////////
3075:            // See XML Schema documentation
3076:            public class Documentation extends ContainsSubElements {
3077:                public Documentation() {
3078:                }
3079:
3080:                public String getContentName() {
3081:                    return null;
3082:                }
3083:
3084:                public boolean compressWhiteSpaceOuter() {
3085:                    return true;
3086:                }
3087:
3088:                public boolean compressWhiteSpaceInner() {
3089:                    return true;
3090:                }
3091:
3092:                public String getName() {
3093:                    return "documentation";
3094:                }
3095:
3096:                public boolean writeDTDName(StringBuffer out) {
3097:                    return false;
3098:                }
3099:
3100:                public void readSchema(org.w3c.dom.Element node) {
3101:                    Documentation el = new Documentation();
3102:                    pushCurrent(el);
3103:                    read(node);
3104:                    popCurrent();
3105:                }
3106:
3107:                public Map validSubElementTypeMap() {
3108:                    return documentationValidSubElementTypeMap;
3109:                }
3110:            }
3111:
3112:            static private Map documentationValidSubElementTypeMap = null;
3113:            static {
3114:                documentationValidSubElementTypeMap = new HashMap();
3115:                documentationValidSubElementTypeMap.put(AnyNode.class, null);
3116:                documentationValidSubElementTypeMap.put(TextNode.class, null);
3117:            }
3118:
3119:            ////////////////////////////////////////////////////////////////
3120:            // This represents any undefined node
3121:            public class AnyNode extends ContainsSubElements {
3122:                protected String name;
3123:                protected String value;
3124:
3125:                public AnyNode(String n, String v) {
3126:                    name = n;
3127:                    value = v;
3128:                }
3129:
3130:                public String getContentName() {
3131:                    return name;
3132:                }
3133:
3134:                public String getName() {
3135:                    return name;
3136:                }
3137:
3138:                public String getValue() {
3139:                    return value;
3140:                }
3141:
3142:                public boolean compressWhiteSpaceInner() {
3143:                    return findSubElement("TextNode") != null;
3144:                }
3145:
3146:                public ElementExpr optimize() {
3147:                    super .optimize();
3148:                    if (name == null && value == null
3149:                            && subElements.size() == 0)
3150:                        return null;
3151:                    return this ;
3152:                }
3153:
3154:                public boolean writeDTDName(StringBuffer out) {
3155:                    return false;
3156:                }
3157:
3158:                public void writeXMLSchema(XMLWriter out) throws IOException {
3159:                    if (value == null)
3160:                        this .writeXMLSchema(out, true);
3161:                    else {
3162:                        out.startTag(getName());
3163:                        XMLUtil.printXML(out, value, false);
3164:                        this .writeXMLSchema(out, false);
3165:                        out.endTag();
3166:                    }
3167:                }
3168:
3169:                public void readSchema(org.w3c.dom.Element node) {
3170:                    String myName = node.getLocalName();
3171:                    String myValue = node.getNodeValue();
3172:                    AnyNode el = new AnyNode(myName, myValue);
3173:
3174:                    // Should read in attributes too.
3175:                    //System.out.println("Just read AnyNode: myName="+myName+" myValue="+myValue);
3176:                    pushCurrent(el);
3177:                    read(node);
3178:                    popCurrent();
3179:                }
3180:
3181:                public String toString() {
3182:                    return "AnyNode(" + name + ")";
3183:                }
3184:
3185:                public Map validSubElementTypeMap() {
3186:                    return anyNodeValidSubElementTypeMap;
3187:                }
3188:
3189:                public boolean equals(Object o) {
3190:                    if (!(o instanceof  AnyNode))
3191:                        return false;
3192:                    AnyNode el = (AnyNode) o;
3193:                    //System.out.println("value="+value+" el.value="+el.value);
3194:                    if (value == null) {
3195:                        if (el.value != null)
3196:                            return false;
3197:                    } else if (!value.equals(el.value))
3198:                        return false;
3199:                    if (name == null) {
3200:                        if (el.name != null)
3201:                            return false;
3202:                    } else if (!name.equals(el.name))
3203:                        return false;
3204:                    return true;
3205:                }
3206:
3207:                public int hashCode() {
3208:                    int result = 17;
3209:                    result = 37 * result
3210:                            + ((value == null) ? 0 : value.hashCode());
3211:                    result = 37 * result
3212:                            + ((name == null) ? 0 : name.hashCode());
3213:                    result = 37 * result + super .hashCode();
3214:                    return result;
3215:                }
3216:            }
3217:
3218:            static private Map anyNodeValidSubElementTypeMap = null;
3219:            static {
3220:                anyNodeValidSubElementTypeMap = new HashMap();
3221:                anyNodeValidSubElementTypeMap.put(AnyNode.class, null);
3222:                anyNodeValidSubElementTypeMap.put(TextNode.class, null);
3223:            }
3224:
3225:            ////////////////////////////////////////////////////////////////
3226:            // This represents a text element and allows for subelements.
3227:            public class TextNode extends ContainsSubElements {
3228:                protected String text;
3229:
3230:                public TextNode(String text) {
3231:                    this .text = text;
3232:                }
3233:
3234:                public String getText() {
3235:                    return text;
3236:                }
3237:
3238:                public String getName() {
3239:                    return "TextNode";
3240:                }
3241:
3242:                public String getContentName() {
3243:                    return null;
3244:                }
3245:
3246:                public boolean compressWhiteSpaceInner() {
3247:                    return true;
3248:                }
3249:
3250:                public ElementExpr optimize() {
3251:                    super .optimize();
3252:                    if (text == null || text.equals(""))
3253:                        return null;
3254:                    return this ;
3255:                }
3256:
3257:                public boolean writeDTDName(StringBuffer out) {
3258:                    return false;
3259:                }
3260:
3261:                public void writeXMLSchema(XMLWriter out) throws IOException {
3262:                    XMLUtil.printXML(out, text, false);
3263:                    this .writeXMLSchema(out, false);
3264:                }
3265:
3266:                public void readSchema(org.w3c.dom.Element node) {
3267:                    readSchema((Text) node);
3268:                }
3269:
3270:                public void readSchema(Text node) {
3271:                    TextNode el = new TextNode(node.getData());
3272:                    //System.out.println("Just read TextNode: myName="+myName+" myValue="+myValue);
3273:                    pushCurrent(el);
3274:                    read(node);
3275:                    popCurrent();
3276:                }
3277:
3278:                public String toString() {
3279:                    return "TextNode(" + text + ")";
3280:                }
3281:
3282:                public Map validSubElementTypeMap() {
3283:                    return textNodeValidSubElementTypeMap;
3284:                }
3285:
3286:                public boolean equals(Object o) {
3287:                    if (!(o instanceof  TextNode))
3288:                        return false;
3289:                    TextNode el = (TextNode) o;
3290:                    if (text == null) {
3291:                        if (el.text != null)
3292:                            return false;
3293:                    } else if (!text.equals(el.text))
3294:                        return false;
3295:                    return true;
3296:                }
3297:
3298:                public int hashCode() {
3299:                    int result = 17;
3300:                    result = 37 * result
3301:                            + ((text == null) ? 0 : text.hashCode());
3302:                    result = 37 * result + super .hashCode();
3303:                    return result;
3304:                }
3305:            }
3306:
3307:            static private Map textNodeValidSubElementTypeMap = null;
3308:            static {
3309:                textNodeValidSubElementTypeMap = new HashMap();
3310:                textNodeValidSubElementTypeMap.put(AnyNode.class, null);
3311:                textNodeValidSubElementTypeMap.put(TextNode.class, null);
3312:            }
3313:
3314:            ////////////////////////////////////////////////////////////////
3315:            // See XML Schema element
3316:            // This implementation is missing attributes right now.
3317:            public class Element extends ContainsSubElements implements 
3318:                    MinMaxOccurs, CanRef {
3319:                private String elementName;
3320:                private String elementNamespace; // a URI
3321:                private String defaultTargetNamespace;
3322:                private boolean defaultFormQualified;
3323:                private Boolean formQualified;
3324:                // If type is set and there are subelements, then the type
3325:                // is a "comment" about which java type should be used.
3326:                private String type;
3327:                private String xmlSchemaType;
3328:                private String ref;
3329:                private String refWithNamespace;
3330:                private String minOccurs = "1";
3331:                private String maxOccurs = "1";
3332:                private boolean nillable = false;
3333:                private String defaultValue;
3334:                private ElementExpr parentElementExpr;
3335:
3336:                protected Element(String n, String t) {
3337:                    this (n);
3338:                    setType(t);
3339:                    putSchemaTypeDef(type, this );
3340:                }
3341:
3342:                protected Element(String n) {
3343:                    setElementName(n);
3344:                    type = null;
3345:                }
3346:
3347:                private Element() {
3348:                }
3349:
3350:                public String getName() {
3351:                    return "element";
3352:                }
3353:
3354:                public String getContentName() {
3355:                    return elementName;
3356:                }
3357:
3358:                /**
3359:                 * @param n The qualified element name;
3360:                 *          for instance, "address" or "tns:address"
3361:                 */
3362:                private void setElementName(String n) {
3363:                    if (n != null && !n.equals("")) {
3364:                        String prefix = prefixOf(n);
3365:                        if (prefix == null) {
3366:                            //
3367:                            // See XML Schema spec Part 1, section 3.3.2 and search
3368:                            // for "namespace" to figure out where the namespace
3369:                            // comes from.
3370:                            //
3371:                            if (parentElementExpr instanceof  SchemaNode) {
3372:                                elementNamespace = defaultTargetNamespace;
3373:                            } else {
3374:                                if (isFormQualified())
3375:                                    elementNamespace = defaultTargetNamespace;
3376:                                else {
3377:                                    //elementNamespace = "";
3378:                                    elementNamespace = null;
3379:                                }
3380:                            }
3381:                            //System.out.println("n="+n+" elementNamespace="+elementNamespace);
3382:                            /*
3383:                            if (!"dummy".equals(n) &&
3384:                                    ((elementNamespace == null && defaultTargetNamespace != null)
3385:                                    || (elementNamespace != null && !elementNamespace.equals(targetNamespace)))) {
3386:                                System.out.println("Different namespace on "+n+" elementNamespace="+elementNamespace+" targetNamespace="+targetNamespace+" defaultTargetNamespace="+defaultTargetNamespace);
3387:                            }
3388:                             */
3389:                            elementName = n;
3390:                        } else {
3391:                            elementNamespace = getNamespaceURI(prefix);
3392:                            elementName = removePrefix(n);
3393:                        }
3394:                    } else {
3395:                        elementName = null;
3396:                        elementNamespace = null;
3397:                    }
3398:                }
3399:
3400:                public String getElementName() {
3401:                    return elementName;
3402:                }
3403:
3404:                /**
3405:                 * Returns the URI namespace
3406:                 */
3407:                public String getElementNamespace() {
3408:                    return elementNamespace;
3409:                }
3410:
3411:                public String getPrefix() {
3412:                    return getNamespace(elementNamespace);
3413:                }
3414:
3415:                public boolean isFormQualified() {
3416:                    if (formQualified != null)
3417:                        return formQualified.booleanValue();
3418:                    return defaultFormQualified;
3419:                }
3420:
3421:                public String getType() {
3422:                    return type;
3423:                }
3424:
3425:                public boolean hasRef() {
3426:                    return getRef() != null;
3427:                }
3428:
3429:                /**
3430:                 * May return null.
3431:                 */
3432:                public String getRef() {
3433:                    return ref;
3434:                }
3435:
3436:                public Element getRefElement() {
3437:                    if (ref == null)
3438:                        return null;
3439:                    //Element referredElement = getDefinedElement(ref);
3440:                    Element referredElement = getDefinedElementResolvedNamespace(refWithNamespace);
3441:                    return referredElement;
3442:                }
3443:
3444:                public ElementExpr getRefElementExpr() {
3445:                    return getRefElement();
3446:                }
3447:
3448:                /**
3449:                 * Set the type of this element.  The String passed in, @t, should
3450:                 * be a java type like 'java.lang.Integer' or
3451:                 * 'com.sun.forte4j.webdesigner.SOAPTest.Foo' or 'float'.
3452:                 * This type will later get converted into the XML Schema type
3453:                 * ('int' -> 'xsd:int', 'java.lang.String' -> 'xsd:string').
3454:                 */
3455:                public void setType(String t) {
3456:                    if (t != null)
3457:                        t = t.intern();
3458:                    if ("void" == t)
3459:                        t = null;
3460:                    String oldType = type;
3461:                    type = t;
3462:                    if (schemaTypeDefs.containsKey(oldType)) // FIXME
3463:                        schemaTypeDefs.remove(oldType);
3464:                    if (t == null)
3465:                        return;
3466:                    putSchemaTypeDef(type, this );
3467:                    ref = null;
3468:                    if (debug)
3469:                        System.out.println("setType(" + t + ")");
3470:                    if (optionallyDefinedTypes.containsKey(t)) {
3471:                        //System.out.println("Found it!");
3472:                        requiredPredefinedTypes.put(t, "keep"); // Keep this one.  NOI18N
3473:                    }
3474:                }
3475:
3476:                /**
3477:                 * Bypass setType's converstion from java type to XML Schema type.
3478:                 * @t should be the XML Schema type.  This should only be used
3479:                 * for types that are defined previously in this schema
3480:                 * or have special meaning to the eventual reader of this schema
3481:                 * (like, 'SOAP-INC:Array').
3482:                 */
3483:                public void setXMLSchemaType(String t) {
3484:                    if (t == null) {
3485:                        xmlSchemaType = null;
3486:                    } else {
3487:                        xmlSchemaType = normalizeDocumentNamespace(t).intern();
3488:                        ref = null;
3489:                    }
3490:                }
3491:
3492:                public String getJavaType() {
3493:                    //System.out.println("Element.getJavaType: type="+type+" ref="+ref+" xmlSchemaType="+xmlSchemaType);
3494:                    if (type != null)
3495:                        return type;
3496:                    if (ref != null) {
3497:                        Element referredElement = getRefElement();
3498:                        //System.out.println("Found "+referredElement);
3499:                        return referredElement.getJavaType();
3500:                    }
3501:                    if (xmlSchemaType == null)
3502:                        return null;
3503:                    String javaType = schemaTypeToJavaType(xmlSchemaType);
3504:                    if (nillable) {
3505:                        javaType = JavaUtil.toObjectType(javaType);
3506:                    }
3507:                    return javaType;
3508:                }
3509:
3510:                public String getXMLSchemaType() {
3511:                    return xmlSchemaType;
3512:                }
3513:
3514:                public void setMinOccurs(String mino) {
3515:                    if (mino == null)
3516:                        mino = "1";
3517:                    minOccurs = mino.intern();
3518:                }
3519:
3520:                public void setMaxOccurs(String maxo) {
3521:                    if (maxo == null)
3522:                        maxo = "1";
3523:                    maxOccurs = maxo.intern();
3524:                }
3525:
3526:                public String getMinOccurs() {
3527:                    return minOccurs;
3528:                }
3529:
3530:                public String getMaxOccurs() {
3531:                    return maxOccurs;
3532:                }
3533:
3534:                public boolean isNillable() {
3535:                    return nillable;
3536:                }
3537:
3538:                public String getDefault() {
3539:                    return defaultValue;
3540:                }
3541:
3542:                public void setDefault(String d) {
3543:                    defaultValue = d;
3544:                }
3545:
3546:                public void writeDTD(StringBuffer out) {
3547:                    Element firstElement = (Element) elementTable
3548:                            .get(getElementName());
3549:                    if (firstElement == null)
3550:                        elementTable.put(getElementName(), this );
3551:                    else {
3552:                        // Gotta compare
3553:                        if (debug)
3554:                            System.out.println("Found another element named "
3555:                                    + getElementName());
3556:                        if (!equals(firstElement)) {
3557:                            throw new RuntimeException(Common.getMessage(
3558:                                    "MSG_SameNameDifferentContents",
3559:                                    getElementName()));
3560:                        }
3561:                        return;
3562:                    }
3563:
3564:                    out.append("<!ELEMENT " + getElementName() + " ");
3565:                    // "EMPTY" correlates with hasNamedSubElements
3566:                    if (subElements.size() == 0) {
3567:                        if (type == null || type == "void")
3568:                            out.append("()");
3569:                        else
3570:                            out.append("#PCDATA");
3571:                    } else {
3572:                        if (!writeDTDSubElementNames(out))
3573:                            out.append("()");
3574:                    }
3575:                    out.append(">\n");
3576:
3577:                    // Now tell the subelements to print themselves out too
3578:                    super .writeDTD(out);
3579:                }
3580:
3581:                public boolean hasNamedSubElements() {
3582:                    if (subElements.size() == 0) {
3583:                        return false;
3584:                    } else {
3585:                        if (!writeDTDSubElementNames(new StringBuffer()))
3586:                            return false;
3587:                        else
3588:                            return true;
3589:                    }
3590:                }
3591:
3592:                public String getAttributeString() {
3593:                    StringBuffer sb = new StringBuffer();
3594:                    if (elementName != null) {
3595:                        sb.append(" name='");
3596:                        if (elementNamespace != null
3597:                                && !elementNamespace.equals(targetNamespace)) {
3598:                            sb.append(getNamespace(elementNamespace));
3599:                            sb.append(':');
3600:                        }
3601:                        sb.append(elementName);
3602:                        sb.append("'");
3603:                    }
3604:                    if (ref != null) {
3605:                        sb.append(" ref='");
3606:                        sb.append(ref);
3607:                        sb.append("'");
3608:                    }
3609:                    if (xmlSchemaType != null) {
3610:                        sb.append(" type='");
3611:                        sb.append(xmlSchemaType);
3612:                        sb.append("'");
3613:                    } else if (type != null) {
3614:                        String theXmlSchemaType = javaType2XMLSchemaTypeComplex(getType());
3615:                        if (theXmlSchemaType != null) {
3616:                            sb.append(" type='");
3617:                            sb.append(theXmlSchemaType);
3618:                            sb.append("'");
3619:                        } else {
3620:                            //throw new IllegalStateException(Common.getMessage("MSG_FailedToFindXMLSchemaType", type));
3621:                        }
3622:                    }
3623:                    if (minOccurs != "1")
3624:                        sb.append(" minOccurs='" + minOccurs + "'");
3625:                    if (maxOccurs != "1")
3626:                        sb.append(" maxOccurs='" + maxOccurs + "'");
3627:                    if (nillable)
3628:                        sb.append(" nillable='true'");
3629:                    if (defaultValue != null)
3630:                        sb.append(" default='" + defaultValue + "'");
3631:                    if (formQualified != null)
3632:                        sb.append(" form='"
3633:                                + (formQualified.booleanValue() ? "qualified"
3634:                                        : "unqualified") + "'");
3635:                    return sb.toString();
3636:                }
3637:
3638:                public boolean isDefiningNewType() {
3639:                    if (ref == null)
3640:                        return true;
3641:                    return (subElements.size() >= 1 && type != null);
3642:                }
3643:
3644:                public boolean writeDTDName(StringBuffer out) {
3645:                    out.append(getElementName());
3646:                    if ("unbounded" == maxOccurs)
3647:                        out.append("*");
3648:                    return true;
3649:                }
3650:
3651:                public Map validSubElementTypeMap() {
3652:                    return elementValidSubElementTypeMap;
3653:                }
3654:
3655:                public void readSchema(org.w3c.dom.Element node) {
3656:                    String elementName = node.getAttribute("name"); // NOI18N
3657:                    String elementType = node.getAttribute("type"); // NOI18N
3658:                    String elementRef = node.getAttribute("ref"); // NOI18N
3659:                    String minOccurs = node.getAttribute("minOccurs"); // NOI18N
3660:                    String maxOccurs = node.getAttribute("maxOccurs"); // NOI18N
3661:                    String myNillable = node.getAttribute("nillable"); // NOI18N
3662:                    String myDefault = node.getAttribute("default"); // NOI18N
3663:                    String myForm = node.getAttribute("form"); // NOI18N
3664:                    String defaultTargetNamespace;
3665:                    boolean defaultFormQualified;
3666:                    ElementExpr parent = peekCurrent();
3667:                    //System.out.println("elementName="+elementName+" parent="+parent);
3668:                    SchemaNode parentSchema;
3669:                    if (parent instanceof  SchemaNode) {
3670:                        parentSchema = (SchemaNode) parent;
3671:                    } else {
3672:                        parentSchema = (SchemaNode) findAncestor(SchemaNode.class);
3673:                    }
3674:                    if (parentSchema != null) {
3675:                        //
3676:                        // Get the targetNamespace from the instance variable instead of
3677:                        // querying the schema node, since if multiple schema nodes are
3678:                        // merged, only the first keeps it's targetNamespace.
3679:                        //
3680:                        //defaultTargetNamespace = parentSchema.getTargetNamespace();
3681:                        defaultTargetNamespace = targetNamespace;
3682:                        //defaultFormQualified = parentSchema.isElementFormQualified();
3683:                        defaultFormQualified = elementFormQualifiedDefault;
3684:                    } else {
3685:                        defaultTargetNamespace = targetNamespace;
3686:                        defaultFormQualified = false;
3687:                    }
3688:                    Element el = new Element();
3689:                    el.parentElementExpr = parent;
3690:                    el.defaultTargetNamespace = defaultTargetNamespace;
3691:                    el.defaultFormQualified = defaultFormQualified;
3692:                    el.setElementName(elementName);
3693:                    if (myForm != null && !"".equals(myForm))
3694:                        el.formQualified = Boolean.valueOf("qualified"
3695:                                .equals(myForm));
3696:                    if (elementRef != null && !elementRef.equals("")) {
3697:                        el.ref = elementRef.intern();
3698:                        el.refWithNamespace = resolveNamespace(el.ref);
3699:                    }
3700:                    if (elementType != null && !elementType.equals(""))
3701:                        el.setXMLSchemaType(elementType);
3702:                    if (minOccurs != null && !minOccurs.equals(""))
3703:                        el.setMinOccurs(minOccurs);
3704:                    if (maxOccurs != null && !maxOccurs.equals(""))
3705:                        el.setMaxOccurs(maxOccurs);
3706:                    if (myNillable != null
3707:                            && (myNillable.equals("true")
3708:                                    || myNillable.equals("yes") || myNillable
3709:                                    .equals("on")))
3710:                        el.nillable = true;
3711:                    if (myDefault != null && !"".equals(myDefault))
3712:                        el.setDefault(myDefault);
3713:                    pushCurrent(el);
3714:                    read(node);
3715:                    popCurrent();
3716:                }
3717:
3718:                public boolean equals(Object o) {
3719:                    if (!(o instanceof  Element))
3720:                        return false;
3721:                    Element el = (Element) o;
3722:                    //System.out.println("type="+type);
3723:                    if (type != el.type)
3724:                        return false;
3725:                    if (ref != el.ref)
3726:                        return false;
3727:                    if (xmlSchemaType != el.xmlSchemaType)
3728:                        return false;
3729:                    if (minOccurs != el.minOccurs)
3730:                        return false;
3731:                    if (maxOccurs != el.maxOccurs)
3732:                        return false;
3733:                    if (nillable != el.nillable)
3734:                        return false;
3735:                    if (formQualified == null) {
3736:                        if (el.formQualified != null)
3737:                            return false;
3738:                    } else {
3739:                        if (el.formQualified == null
3740:                                || formQualified.booleanValue() != el.formQualified
3741:                                        .booleanValue())
3742:                            return false;
3743:                    }
3744:
3745:                    if (!elementName.equals(el.elementName))
3746:                        return false;
3747:
3748:                    return super .equals(el);
3749:                }
3750:
3751:                public int hashCode() {
3752:                    int result = 17;
3753:                    result = 37 * result
3754:                            + ((type == null) ? 0 : type.hashCode());
3755:                    result = 37 * result + ((ref == null) ? 0 : ref.hashCode());
3756:                    result = 37
3757:                            * result
3758:                            + ((xmlSchemaType == null) ? 0 : xmlSchemaType
3759:                                    .hashCode());
3760:                    result = 37 * result
3761:                            + ((minOccurs == null) ? 0 : minOccurs.hashCode());
3762:                    result = 37 * result
3763:                            + ((maxOccurs == null) ? 0 : maxOccurs.hashCode());
3764:                    result = 37 * result + (nillable ? 1 : 0);
3765:                    result = 37
3766:                            * result
3767:                            + ((elementName == null) ? 0 : elementName
3768:                                    .hashCode());
3769:                    result = 37 * result + super .hashCode();
3770:                    result = 37
3771:                            * result
3772:                            + ((formQualified == null) ? 0 : formQualified
3773:                                    .hashCode());
3774:                    return result;
3775:                }
3776:            }
3777:
3778:            static private Map elementValidSubElementTypeMap = null;
3779:            static {
3780:                elementValidSubElementTypeMap = new HashMap();
3781:                elementValidSubElementTypeMap.put(Annotation.class, null);
3782:                elementValidSubElementTypeMap.put(SimpleType.class, null);
3783:                elementValidSubElementTypeMap.put(ComplexType.class, null);
3784:                elementValidSubElementTypeMap.put(Unique.class, null);
3785:                elementValidSubElementTypeMap.put(Key.class, null);
3786:                elementValidSubElementTypeMap.put(KeyRef.class, null);
3787:            }
3788:
3789:            public class Any extends ContainsSubElements implements 
3790:                    MinMaxOccurs {
3791:                private String minOccurs;
3792:                private String maxOccurs;
3793:                private String namespace;
3794:                private String processContents;
3795:
3796:                public Any() {
3797:                    init();
3798:                }
3799:
3800:                private void init() {
3801:                    minOccurs = "1";
3802:                    maxOccurs = "1";
3803:                }
3804:
3805:                public String getName() {
3806:                    return "any";
3807:                }
3808:
3809:                public String getContentName() {
3810:                    return null;
3811:                }
3812:
3813:                public String getNamespace() {
3814:                    return namespace;
3815:                }
3816:
3817:                public void setNamespace(String n) {
3818:                    namespace = (n == null) ? null : n.intern();
3819:                }
3820:
3821:                public String getProcessContents() {
3822:                    return processContents;
3823:                }
3824:
3825:                public void setProcessContents(String pc) {
3826:                    processContents = (pc == null) ? null : pc.intern();
3827:                }
3828:
3829:                public void setMinOccurs(String mino) {
3830:                    if (mino == null)
3831:                        mino = "1";
3832:                    minOccurs = mino.intern();
3833:                }
3834:
3835:                public void setMaxOccurs(String maxo) {
3836:                    if (maxo == null)
3837:                        maxo = "1";
3838:                    maxOccurs = maxo.intern();
3839:                }
3840:
3841:                public String getMinOccurs() {
3842:                    return minOccurs;
3843:                }
3844:
3845:                public String getMaxOccurs() {
3846:                    return maxOccurs;
3847:                }
3848:
3849:                public String getAttributeString() {
3850:                    StringBuffer sb = new StringBuffer();
3851:                    if (minOccurs != "1")
3852:                        sb.append(" minOccurs='" + minOccurs + "'");
3853:                    if (maxOccurs != "1")
3854:                        sb.append(" maxOccurs='" + maxOccurs + "'");
3855:                    if (namespace != null)
3856:                        sb.append(" namespace='" + namespace + "'");
3857:                    if (processContents != null)
3858:                        sb.append(" processContents='" + processContents + "'");
3859:                    return sb.toString();
3860:                }
3861:
3862:                public Map validSubElementTypeMap() {
3863:                    return anyValidSubElementTypeMap;
3864:                }
3865:
3866:                public boolean writeDTDName(StringBuffer out) {
3867:                    return false;
3868:                }
3869:
3870:                public void readSchema(org.w3c.dom.Element node) {
3871:                    String namespace = node.getAttribute("namespace"); // NOI18N
3872:                    String processContents = node
3873:                            .getAttribute("processContents"); // NOI18N
3874:                    String minOccurs = node.getAttribute("minOccurs"); // NOI18N
3875:                    String maxOccurs = node.getAttribute("maxOccurs"); // NOI18N
3876:                    Any el = new Any();
3877:                    if (namespace != null && !namespace.equals(""))
3878:                        el.setNamespace(namespace);
3879:                    if (processContents != null && !processContents.equals(""))
3880:                        el.setProcessContents(processContents);
3881:                    if (minOccurs != null && !minOccurs.equals(""))
3882:                        el.setMinOccurs(minOccurs);
3883:                    if (maxOccurs != null && !maxOccurs.equals(""))
3884:                        el.setMaxOccurs(maxOccurs);
3885:                    pushCurrent(el);
3886:                    read(node);
3887:                    popCurrent();
3888:                }
3889:
3890:                public boolean equals(Object o) {
3891:                    if (!(o instanceof  Any))
3892:                        return false;
3893:                    Any el = (Any) o;
3894:                    if (minOccurs != el.minOccurs)
3895:                        return false;
3896:                    if (maxOccurs != el.maxOccurs)
3897:                        return false;
3898:                    if (namespace != el.namespace)
3899:                        return false;
3900:                    if (processContents != el.processContents)
3901:                        return false;
3902:                    return super .equals(el);
3903:                }
3904:
3905:                public int hashCode() {
3906:                    int result = 17;
3907:                    result = 37 * result
3908:                            + ((namespace == null) ? 0 : namespace.hashCode());
3909:                    result = 37
3910:                            * result
3911:                            + ((processContents == null) ? 0 : processContents
3912:                                    .hashCode());
3913:                    result = 37 * result
3914:                            + ((minOccurs == null) ? 0 : minOccurs.hashCode());
3915:                    result = 37 * result
3916:                            + ((maxOccurs == null) ? 0 : maxOccurs.hashCode());
3917:                    return result;
3918:                }
3919:            }
3920:
3921:            static private Map anyValidSubElementTypeMap = null;
3922:            static {
3923:                anyValidSubElementTypeMap = new HashMap();
3924:                anyValidSubElementTypeMap.put(Annotation.class, null);
3925:            }
3926:
3927:            public class AnyAttribute extends ContainsSubElements {
3928:                private String namespace;
3929:                private String processContents;
3930:
3931:                public AnyAttribute() {
3932:                }
3933:
3934:                public String getName() {
3935:                    return "anyAttribute";
3936:                }
3937:
3938:                public String getContentName() {
3939:                    return null;
3940:                }
3941:
3942:                public String getNamespace() {
3943:                    return namespace;
3944:                }
3945:
3946:                public void setNamespace(String n) {
3947:                    namespace = (n == null) ? null : n.intern();
3948:                }
3949:
3950:                public String getProcessContents() {
3951:                    return processContents;
3952:                }
3953:
3954:                public void setProcessContents(String pc) {
3955:                    processContents = (pc == null) ? null : pc.intern();
3956:                }
3957:
3958:                public String getAttributeString() {
3959:                    StringBuffer sb = new StringBuffer();
3960:                    if (namespace != null)
3961:                        sb.append(" namespace='" + namespace + "'");
3962:                    if (processContents != null)
3963:                        sb.append(" processContents='" + processContents + "'");
3964:                    return sb.toString();
3965:                }
3966:
3967:                public Map validSubElementTypeMap() {
3968:                    return anyAttributeValidSubElementTypeMap;
3969:                }
3970:
3971:                public boolean writeDTDName(StringBuffer out) {
3972:                    return false;
3973:                }
3974:
3975:                public void readSchema(org.w3c.dom.Element node) {
3976:                    String namespace = node.getAttribute("namespace"); // NOI18N
3977:                    String processContents = node
3978:                            .getAttribute("processContents"); // NOI18N
3979:                    AnyAttribute el = new AnyAttribute();
3980:                    if (namespace != null && !namespace.equals(""))
3981:                        el.setNamespace(namespace);
3982:                    if (processContents != null && !processContents.equals(""))
3983:                        el.setProcessContents(processContents);
3984:                    pushCurrent(el);
3985:                    read(node);
3986:                    popCurrent();
3987:                }
3988:
3989:                public boolean equals(Object o) {
3990:                    if (!(o instanceof  AnyAttribute))
3991:                        return false;
3992:                    AnyAttribute el = (AnyAttribute) o;
3993:                    if (namespace != el.namespace)
3994:                        return false;
3995:                    if (processContents != el.processContents)
3996:                        return false;
3997:                    return super .equals(el);
3998:                }
3999:
4000:                public int hashCode() {
4001:                    int result = 17;
4002:                    result = 37 * result
4003:                            + ((namespace == null) ? 0 : namespace.hashCode());
4004:                    result = 37
4005:                            * result
4006:                            + ((processContents == null) ? 0 : processContents
4007:                                    .hashCode());
4008:                    return result;
4009:                }
4010:            }
4011:
4012:            static private Map anyAttributeValidSubElementTypeMap = null;
4013:            static {
4014:                anyAttributeValidSubElementTypeMap = new HashMap();
4015:                anyAttributeValidSubElementTypeMap.put(Annotation.class, null);
4016:            }
4017:
4018:            ////////////////////////////////////////////////////////////////
4019:            // An Schema Attribute
4020:            // An XML Schema attribute may contain simpleType as a subelement
4021:            // and/or annotation.
4022:            public class Attribute extends ContainsSubElements implements 
4023:                    CanRef {
4024:                private String namespace;
4025:                private String name;
4026:                private String type;
4027:                private String defaultValue;
4028:                private String id;
4029:                private String ref;
4030:                private String fixed;
4031:                private String use;
4032:                private String arrayType; // for rpc/encoded WSDL
4033:
4034:                public Attribute(String n) {
4035:                    this (n, targetNamespace);
4036:                }
4037:
4038:                public Attribute(String n, String ns) {
4039:                    this (n, ns, null);
4040:                }
4041:
4042:                public Attribute(String n, String ns, String type) {
4043:                    if (n == null || n.equals(""))
4044:                        name = null;
4045:                    else
4046:                        name = n.intern();
4047:                    namespace = ns;
4048:                    setType(type);
4049:                }
4050:
4051:                public String getName() {
4052:                    return "attribute";
4053:                }
4054:
4055:                public String getContentName() {
4056:                    return "@" + name;
4057:                }
4058:
4059:                public String getAttributeName() {
4060:                    if (namespace == null || namespace.equals(targetNamespace)) {
4061:                        return name;
4062:                    }
4063:                    return getNamespace(namespace) + ":" + name;
4064:                }
4065:
4066:                public String getAttributeNamespace() {
4067:                    return namespace;
4068:                }
4069:
4070:                public String getAttributeNameNoNS() {
4071:                    return name;
4072:                }
4073:
4074:                private void setType(String ty) {
4075:                    if (ty == null) {
4076:                        type = null;
4077:                        return;
4078:                    }
4079:                    type = normalizeDocumentNamespace(ty).intern();
4080:                }
4081:
4082:                public String getType() {
4083:                    return type;
4084:                }
4085:
4086:                public String getJavaType() {
4087:                    if (type == null)
4088:                        return null;
4089:                    String javaType = schemaTypeToJavaType(type);
4090:                    if (false) {
4091:                        javaType = JavaUtil.toObjectType(javaType);
4092:                    }
4093:                    return javaType;
4094:                }
4095:
4096:                public String getFixed() {
4097:                    return fixed;
4098:                }
4099:
4100:                public boolean isRequired() {
4101:                    return use == "required";
4102:                }
4103:
4104:                public boolean isOptional() {
4105:                    return use == "optional";
4106:                }
4107:
4108:                public boolean isProhibited() {
4109:                    return use == "prohibited";
4110:                }
4111:
4112:                public String getUse() {
4113:                    return use;
4114:                }
4115:
4116:                public boolean isAttributeNamed(String n) {
4117:                    n = resolveNamespace(n);
4118:                    String fullName = resolveNamespace(namespace, name);
4119:                    return n.equals(fullName);
4120:                }
4121:
4122:                public boolean hasRef() {
4123:                    return getRef() != null;
4124:                }
4125:
4126:                /**
4127:                 * May return null.
4128:                 */
4129:                public String getRef() {
4130:                    return ref;
4131:                }
4132:
4133:                public Attribute getRefAttribute() {
4134:                    if (ref == null)
4135:                        return null;
4136:                    Object o = definedAttributes.get(ref);
4137:                    if (o instanceof  Attribute) {
4138:                        Attribute referredAttribute = (Attribute) o;
4139:                        return referredAttribute;
4140:                    } else {
4141:                        throw new IllegalStateException(Common.getMessage(
4142:                                "MSG_FailedToFindRef", ref, this .toString()));
4143:                    }
4144:                }
4145:
4146:                public ElementExpr getRefElementExpr() {
4147:                    return getRefAttribute();
4148:                }
4149:
4150:                public boolean isDefiningNewType() {
4151:                    if (ref == null)
4152:                        return true;
4153:                    return (subElements.size() >= 1 && type != null);
4154:                }
4155:
4156:                public String getArrayType() {
4157:                    return arrayType;
4158:                }
4159:
4160:                public String getDefaultValue() {
4161:                    return defaultValue;
4162:                }
4163:
4164:                public void writeDTD(StringBuffer out) {
4165:                    writeDTD(out, "UNKNOWN");
4166:                }
4167:
4168:                public void writeDTD(StringBuffer out, String elementName) {
4169:                    out.append("<!ATTLIST " + elementName + " " + name + " ");
4170:                    out.append(">\n");
4171:                }
4172:
4173:                public boolean writeDTDName(StringBuffer out) {
4174:                    out.append(name);
4175:                    return false;
4176:                }
4177:
4178:                public void validate() {
4179:
4180:                    super .validate();
4181:                }
4182:
4183:                public Map validSubElementTypeMap() {
4184:                    return attributeValidSubElementTypeMap;
4185:                }
4186:
4187:                public String getAttributeString() {
4188:                    StringBuffer sb = new StringBuffer();
4189:                    if (name != null)
4190:                        sb.append(" name='" + getAttributeName() + "'");
4191:                    if (type != null)
4192:                        sb.append(" type='" + type + "'");
4193:                    if (fixed != null) {
4194:                        sb.append(" fixed='");
4195:                        XMLUtil.printXML(sb, fixed, true);
4196:                        sb.append("'");
4197:                    }
4198:                    if (ref != null)
4199:                        sb.append(" ref='" + ref + "'");
4200:                    if (id != null)
4201:                        sb.append(" id='" + id + "'");
4202:                    if (defaultValue != null) {
4203:                        sb.append(" default='");
4204:                        XMLUtil.printXML(sb, defaultValue, true);
4205:                        sb.append("'");
4206:                    }
4207:                    if (use != null)
4208:                        sb.append(" use='" + use + "'");
4209:                    if (arrayType != null)
4210:                        sb.append(" wsdl:arrayType='" + arrayType + "'");
4211:                    return sb.toString();
4212:                }
4213:
4214:                public void readSchema(org.w3c.dom.Element node) {
4215:                    String myName = node.getAttribute("name"); // NOI18N
4216:                    String myType = node.getAttribute("type"); // NOI18N
4217:                    String myFixed = node.getAttribute("fixed"); // NOI18N
4218:                    String myRef = node.getAttribute("ref"); // NOI18N
4219:                    String myId = node.getAttribute("id"); // NOI18N
4220:                    String myDefault = node.getAttribute("default"); // NOI18N
4221:                    String myUse = node.getAttribute("use"); // NOI18N
4222:                    String myArrayType = node.getAttributeNS(
4223:                            "http://schemas.xmlsoap.org/wsdl/", "arrayType");
4224:
4225:                    Attribute attr = new Attribute(myName);
4226:                    if (myType != null && !myType.equals(""))
4227:                        attr.setType(myType.intern());
4228:                    if (myFixed != null && !myFixed.equals(""))
4229:                        attr.fixed = myFixed.intern();
4230:                    if (myRef != null && !myRef.equals(""))
4231:                        attr.ref = myRef.intern();
4232:                    if (myId != null && !myId.equals(""))
4233:                        attr.id = myId.intern();
4234:                    if (myDefault != null && !myDefault.equals(""))
4235:                        attr.defaultValue = myDefault.intern();
4236:                    if (myUse != null && !myUse.equals(""))
4237:                        attr.use = myUse.intern();
4238:                    if (myArrayType != null && !myArrayType.equals(""))
4239:                        attr.arrayType = myArrayType.intern();
4240:                    pushCurrent(attr);
4241:                    read(node);
4242:                    popCurrent();
4243:                }
4244:
4245:                public boolean equals(Object o) {
4246:                    if (!(o instanceof  Attribute))
4247:                        return false;
4248:                    Attribute el = (Attribute) o;
4249:                    if (name != el.name)
4250:                        return false;
4251:                    if (type != el.type)
4252:                        return false;
4253:                    if (fixed != el.fixed)
4254:                        return false;
4255:                    if (ref != el.ref)
4256:                        return false;
4257:                    if (id != el.id)
4258:                        return false;
4259:                    if (use != el.use)
4260:                        return false;
4261:                    if (arrayType != el.arrayType)
4262:                        return false;
4263:
4264:                    return super .equals(el);
4265:                }
4266:
4267:                public int hashCode() {
4268:                    int result = 17;
4269:                    result = 37 * result
4270:                            + ((name == null) ? 0 : name.hashCode());
4271:                    result = 37 * result
4272:                            + ((type == null) ? 0 : type.hashCode());
4273:                    result = 37 * result
4274:                            + ((fixed == null) ? 0 : fixed.hashCode());
4275:                    result = 37 * result + ((ref == null) ? 0 : ref.hashCode());
4276:                    result = 37 * result + ((id == null) ? 0 : id.hashCode());
4277:                    result = 37 * result + ((use == null) ? 0 : use.hashCode());
4278:                    result = 37 * result
4279:                            + ((arrayType == null) ? 0 : arrayType.hashCode());
4280:                    result = 37 * result + super .hashCode();
4281:                    return result;
4282:                }
4283:            }
4284:
4285:            static private Map attributeValidSubElementTypeMap = null;
4286:            static {
4287:                attributeValidSubElementTypeMap = new HashMap();
4288:                attributeValidSubElementTypeMap.put(Annotation.class, null);
4289:                attributeValidSubElementTypeMap.put(SimpleType.class, null);
4290:            }
4291:
4292:            ////////////////////////////////////////////////////////////////
4293:            // An Schema AttributeGroup
4294:            public class AttributeGroup extends ContainsSubElements implements 
4295:                    CanRef {
4296:                private String name;
4297:                private String ref;
4298:
4299:                public AttributeGroup() {
4300:                }
4301:
4302:                /**
4303:                 * Create it by name.
4304:                 */
4305:                public AttributeGroup(String n) {
4306:                    if (n != null && !n.equals("")) {
4307:                        name = normalizeTargetNamespace(n).intern();
4308:                        putSchemaTypeDef(name, this );
4309:                    }
4310:                }
4311:
4312:                public Map validSubElementTypeMap() {
4313:                    return attributeGroupValidSubElementTypeMap;
4314:                }
4315:
4316:                public String getName() {
4317:                    return "attributeGroup";
4318:                }
4319:
4320:                public String getContentName() {
4321:                    return name;
4322:                }
4323:
4324:                public String getGroupName() {
4325:                    return name;
4326:                }
4327:
4328:                public boolean hasRef() {
4329:                    return getRef() != null;
4330:                }
4331:
4332:                public String getRef() {
4333:                    return ref;
4334:                }
4335:
4336:                public AttributeGroup getRefAttributeGroup() {
4337:                    if (ref == null)
4338:                        return null;
4339:                    Object o = getSchemaTypeDef(ref);
4340:                    if (o instanceof  AttributeGroup) {
4341:                        AttributeGroup referredGroup = (AttributeGroup) o;
4342:                        return referredGroup;
4343:                    } else {
4344:                        throw new IllegalStateException(Common.getMessage(
4345:                                "MSG_FailedToFindRef", ref, this .toString()));
4346:                    }
4347:                }
4348:
4349:                public ElementExpr getRefElementExpr() {
4350:                    return getRefAttributeGroup();
4351:                }
4352:
4353:                public boolean writeDTDName(StringBuffer out) {
4354:                    return writeDTDSubElementNames(out, false);
4355:                }
4356:
4357:                public String getAttributeString() {
4358:                    StringBuffer sb = new StringBuffer();
4359:                    if (name != null)
4360:                        sb.append(" name='" + name + "'");
4361:                    if (ref != null)
4362:                        sb.append(" ref='" + ref + "'");
4363:                    return sb.toString();
4364:                }
4365:
4366:                public void readSchema(org.w3c.dom.Element node) {
4367:                    String myName = node.getAttribute("name"); // NOI18N
4368:                    String myRef = node.getAttribute("ref"); // NOI18N
4369:                    AttributeGroup ag = new AttributeGroup(myName);
4370:                    if (myRef != null && !myRef.equals(""))
4371:                        ag.ref = myRef.intern();
4372:                    pushCurrent(ag);
4373:                    read(node);
4374:                    popCurrent();
4375:                }
4376:
4377:                public boolean equals(Object o) {
4378:                    if (!(o instanceof  AttributeGroup))
4379:                        return false;
4380:                    AttributeGroup el = (AttributeGroup) o;
4381:                    if (name != el.name)
4382:                        return false;
4383:                    if (ref != el.ref)
4384:                        return false;
4385:
4386:                    return super .equals(el);
4387:                }
4388:
4389:                public int hashCode() {
4390:                    int result = 17;
4391:                    result = 37 * result
4392:                            + ((name == null) ? 0 : name.hashCode());
4393:                    result = 37 * result + ((ref == null) ? 0 : ref.hashCode());
4394:                    result = 37 * result + super .hashCode();
4395:                    return result;
4396:                }
4397:            }
4398:
4399:            static private Map attributeGroupValidSubElementTypeMap = null;
4400:            static {
4401:                attributeGroupValidSubElementTypeMap = new HashMap();
4402:                attributeGroupValidSubElementTypeMap
4403:                        .put(Annotation.class, null);
4404:                attributeGroupValidSubElementTypeMap.put(Attribute.class, null);
4405:                attributeGroupValidSubElementTypeMap.put(AttributeGroup.class,
4406:                        null);
4407:                attributeGroupValidSubElementTypeMap.put(AnyAttribute.class,
4408:                        null);
4409:            }
4410:
4411:            ////////////////////////////////////////////////////////////////
4412:
4413:            private class ParserSchemaState {
4414:                private String targetNamespace;
4415:                private String documentNamespace;
4416:                private boolean elementFormQualifiedDefault;
4417:                private boolean attributeFormQualifiedDefault;
4418:
4419:                public ParserSchemaState() {
4420:                    this .targetNamespace = SchemaRep.this .targetNamespace;
4421:                    this .documentNamespace = SchemaRep.this .documentNamespace;
4422:                    this .elementFormQualifiedDefault = SchemaRep.this .elementFormQualifiedDefault;
4423:                    this .attributeFormQualifiedDefault = SchemaRep.this .attributeFormQualifiedDefault;
4424:                }
4425:
4426:                public void reload() {
4427:                    SchemaRep.this .targetNamespace = this .targetNamespace;
4428:                    SchemaRep.this .documentNamespace = this .documentNamespace;
4429:                    SchemaRep.this .elementFormQualifiedDefault = this .elementFormQualifiedDefault;
4430:                    SchemaRep.this .attributeFormQualifiedDefault = this .attributeFormQualifiedDefault;
4431:                }
4432:            }
4433:
4434:            ////////////////////////////////////////////////////////////////
4435:
4436:            //protected String docType;  // Not implemented
4437:            protected Map namespaceTable; // Map<String, String>  example: <xsd, http://www.w3.org/2001/XMLSchema>
4438:            protected String targetNamespace;
4439:            protected String documentNamespace;
4440:            private boolean elementFormQualifiedDefault;
4441:            private boolean attributeFormQualifiedDefault;
4442:            protected ContainsSubElements rootElement;
4443:
4444:            // elementTable is used when creating the DTD to make sure that only
4445:            // 1 element of a particular name is ever created.
4446:            protected Map elementTable; // Map<String, Element>
4447:
4448:            // Several simple types are hard coded into this class and put into
4449:            // optionallyDefinedTypes.  They define how to map these simple types into
4450:            // XML Schema types ('java.lang.Integer' -> 'xsd:int').
4451:            protected Map optionallyDefinedTypes = null; // Map<String, ElementExpr>
4452:
4453:            // Top types defined in this schema.  Mapping of java type name into
4454:            // element expressions (just like optionallyDefinedTypes)
4455:            protected Map definedTypes; // Map<String, ElementExpr>
4456:            protected Map definedTypesFull; // Map<String, ElementExpr>
4457:
4458:            protected Map definedAttributes; // Map<String, Attribute>
4459:
4460:            // Standard types
4461:            protected Map predefinedSchemaTypes; // Map<String, ElementExpr>
4462:
4463:            // requiredPredefinedTypes gets an entry whenever something in
4464:            // optionallyDefinedTypes is used.
4465:            protected Map requiredPredefinedTypes; // Map<String, null>
4466:
4467:            // The client adds elements to the current thing on the stack
4468:            protected Stack currentElementStack; // Stack<ElementExpr>
4469:
4470:            // It's possible to have an Annotation added to the top level
4471:            // and it's checked in writeXMLSchemaStandalone.
4472:            protected Annotation topAnnotation;
4473:
4474:            // It's useful for some clients to know what the last popped was.
4475:            protected ElementExpr lastPopped;
4476:
4477:            // A sample instance of every node that can be read in.
4478:            protected Map sampleNodes;
4479:
4480:            // map from type name to ElementExpr
4481:            private Map schemaTypeDefs; // Map<String, ElementExpr>
4482:
4483:            // Whether or not a URL has been included already or not.
4484:            protected Map includedAlready = new HashMap(); // <String, null>
4485:
4486:            private String currentParsedURI;
4487:
4488:            private boolean useBigDataTypes = true;
4489:
4490:            public SchemaRep() {
4491:                init();
4492:            }
4493:
4494:            public SchemaRep(Document schemaDoc, String uri) {
4495:                init();
4496:                currentParsedURI = uri;
4497:                readDocument(schemaDoc);
4498:            }
4499:
4500:            public SchemaRep(Document schemaDoc, String uri,
4501:                    boolean useBigDataTypes) {
4502:                this .useBigDataTypes = useBigDataTypes;
4503:                init();
4504:                currentParsedURI = uri;
4505:                readDocument(schemaDoc);
4506:            }
4507:
4508:            private void init() {
4509:                targetNamespace = null;
4510:                documentNamespace = null;
4511:                namespaceTable = new HashMap();
4512:                addToNamespace("xml", "http://www.w3.org/XML/1998/namespace");
4513:                addToNamespace("xsd", XSD_NS);
4514:
4515:                schemaTypeDefs = new HashMap();
4516:                predefinedSchemaTypes = new HashMap();
4517:                insertPredefinedSchemaTypes(predefinedSchemaTypes);
4518:
4519:                currentElementStack = new Stack();
4520:                topAnnotation = null;
4521:                definedTypes = new HashMap();
4522:                definedTypesFull = new HashMap();
4523:                definedAttributes = new HashMap();
4524:                //mapSimpleJavaTypesPredefined(definedTypes);
4525:                mapSimpleAttributes(definedAttributes);
4526:                requiredPredefinedTypes = new HashMap();
4527:                if (optionallyDefinedTypes == null) {
4528:                    optionallyDefinedTypes = new HashMap();
4529:                    mapSimpleJavaTypesOptional(optionallyDefinedTypes);
4530:                }
4531:
4532:                // sampleNodes are used while reading an XML Schema in
4533:                sampleNodes = new HashMap();
4534:                putSampleNode(new Element("dummy")); // NOI18N
4535:                putSampleNode(new ComplexType());
4536:                putSampleNode(new SimpleType(null)); // NOI18N
4537:                putSampleNode(new UnionType(null, null)); // NOI18N
4538:                putSampleNode(new Restriction());
4539:                putSampleNode(new Sequence());
4540:                putSampleNode(new Choice());
4541:                putSampleNode(new All());
4542:                putSampleNode(new Group());
4543:                putSampleNode(new Annotation());
4544:                putSampleNode(new AppInfo());
4545:                putSampleNode(new Documentation());
4546:                putSampleNode(new Attribute("dummy")); // NOI18N
4547:                putSampleNode(new AttributeGroup());
4548:                putSampleNode(new MaxExclusive("dummy")); // NOI18N
4549:                putSampleNode(new MinExclusive("dummy")); // NOI18N
4550:                putSampleNode(new Enumeration("dummy")); // NOI18N
4551:                putSampleNode(new Pattern("dummy")); // NOI18N
4552:                putSampleNode(new MinLength("0")); // NOI18N
4553:                putSampleNode(new MaxLength("0")); // NOI18N
4554:                putSampleNode(new TotalDigits("dummy")); // NOI18N
4555:                putSampleNode(new MinInclusive("dummy")); // NOI18N
4556:                putSampleNode(new MaxInclusive("dummy")); // NOI18N
4557:                putSampleNode(new FractionDigits("dummy")); // NOI18N
4558:                putSampleNode(new Length("dummy")); // NOI18N
4559:                putSampleNode(new WhiteSpace("dummy")); // NOI18N
4560:                putSampleNode(new Key());
4561:                putSampleNode(new Unique());
4562:                putSampleNode(new KeyRef());
4563:                putSampleNode(new Selector());
4564:                putSampleNode(new Field());
4565:                putSampleNode(new Include("dummy")); // NOI18N
4566:                putSampleNode(new Import());
4567:                putSampleNode(new SimpleContent());
4568:                putSampleNode(new ComplexContent());
4569:                putSampleNode(new Extension());
4570:                putSampleNode(new ListElement());
4571:                putSampleNode(new Any());
4572:                putSampleNode(new AnyAttribute());
4573:            }
4574:
4575:            /**
4576:             * Example: ns=xsd, URI=http://www.w3.org/2001/XMLSchema
4577:             */
4578:            public void addToNamespace(String ns, String URI) {
4579:                //System.out.println("Adding namespace "+ns+" as "+URI);
4580:                namespaceTable.put(ns, URI);
4581:            }
4582:
4583:            /**
4584:             * Return the namespace URI for a given namespace prefix.
4585:             * Will return null if the namespace URI is unheard of.
4586:             * Example: ns="xsd", returns "http://www.w3.org/2001/XMLSchema"
4587:             */
4588:            public String getNamespaceURI(String ns) {
4589:                return (String) namespaceTable.get(ns);
4590:            }
4591:
4592:            /**
4593:             * Return a namespace name for a given namespace URI.  One will
4594:             * be made up, if it doesn't already exist.
4595:             * Example: URI="http://www.w3.org/2001/XMLSchema", returns "xsd"
4596:             */
4597:            public String getNamespace(String URI) {
4598:                //assert !URI.equals("xml");
4599:                String ns;
4600:                Iterator it = namespaceTable.keySet().iterator();
4601:                while (it.hasNext()) {
4602:                    ns = (String) it.next();
4603:                    if (URI.equals(namespaceTable.get(ns)))
4604:                        return ns;
4605:                }
4606:                ns = guessPrefix(URI);
4607:                //System.out.println("guessing ns: ns="+ns+" gets="+namespaceTable.get(ns)+" URI="+URI);
4608:                String baseNs = ns;
4609:                for (int count = 2; namespaceTable.containsKey(ns); ++count)
4610:                    ns = baseNs + count;
4611:                namespaceTable.put(ns, URI);
4612:                return ns;
4613:            }
4614:
4615:            /**
4616:             * @return the Set of all namespace prefixes in use.
4617:             */
4618:            public Set getAllNamespaces() {
4619:                return namespaceTable.keySet();
4620:            }
4621:
4622:            public String getXSDNamespace() {
4623:                String ns = getNamespace(XSD_NS);
4624:                if (ns == null)
4625:                    return "xsd";
4626:                return ns;
4627:            }
4628:
4629:            public String getXMLNamespace() {
4630:                String ns = getNamespace("http://www.w3.org/XML/1998/namespace");
4631:                if (ns == null)
4632:                    return "xml";
4633:                return ns;
4634:            }
4635:
4636:            public Attribute getAttribute(String name) {
4637:                if (name == null)
4638:                    return null;
4639:                String ns = prefixOf(name);
4640:                if (ns == null)
4641:                    name = resolveNamespace(documentNamespace,
4642:                            removePrefix(name));
4643:                else
4644:                    name = resolveNamespace(ns, removePrefix(name));
4645:                //System.out.println("getAttribute: looking up "+name);
4646:                Attribute result = (Attribute) definedAttributes.get(name);
4647:                if (result == null && ns == null) {
4648:                    // try the other namespace
4649:                    name = resolveNamespace(targetNamespace, name);
4650:                    //System.out.println("getAttribute2: looking up "+name);
4651:                    result = (Attribute) definedAttributes.get(name);
4652:                }
4653:                return result;
4654:            }
4655:
4656:            protected void putSampleNode(ElementExpr ee) {
4657:                sampleNodes.put(ee.getName(), ee);
4658:            }
4659:
4660:            protected ElementExpr getSampleNode(String name) {
4661:                return (ElementExpr) sampleNodes.get(name);
4662:            }
4663:
4664:            public void setTargetNamespace(String ns) {
4665:                targetNamespace = ns;
4666:            }
4667:
4668:            public String getTargetNamespace() {
4669:                return targetNamespace;
4670:            }
4671:
4672:            public void setCurrentParsedURI(String uri) {
4673:                currentParsedURI = uri;
4674:            }
4675:
4676:            protected String getCurrentParsedURI() {
4677:                return currentParsedURI;
4678:            }
4679:
4680:            public void setRootElement(ContainsSubElements el) {
4681:                if (debug)
4682:                    System.out.println("Changing rootElement of " + this 
4683:                            + " to " + el);
4684:                rootElement = el;
4685:            }
4686:
4687:            public ContainsSubElements getRootElement() {
4688:                return rootElement;
4689:            }
4690:
4691:            public void addToTopAnnotation(ElementExpr subElement) {
4692:                if (topAnnotation == null)
4693:                    topAnnotation = new Annotation();
4694:                topAnnotation.addSubElement(subElement);
4695:            }
4696:
4697:            public void addAppInfoToTopAnnotation(String name, String value) {
4698:                AppInfo ai = new AppInfo();
4699:                AnyNode ue = new AnyNode(name, value);
4700:                ai.addSubElement(ue);
4701:                addToTopAnnotation(ai);
4702:            }
4703:
4704:            public void pushCurrent(ElementExpr el) {
4705:                if (currentElementStack.empty()) {
4706:                    //System.out.println("Pushing '"+el+"'");
4707:                    setRootElement((ContainsSubElements) el);
4708:                } else {
4709:                    //System.out.println("Pushing '"+el+"' into '"+peekCurrent()+"'");
4710:                    peekCurrentNeedSub().addSubElement(el);
4711:                }
4712:                currentElementStack.push(el);
4713:            }
4714:
4715:            /**
4716:             * Create the element, then push it onto the stack, making it the
4717:             * current one.
4718:             */
4719:            public void pushElement(String elementName, String elementType) {
4720:                pushCurrent(createElement(elementName, elementType));
4721:            }
4722:
4723:            public void pushSchemaNode() {
4724:                pushCurrent(new SchemaNode());
4725:            }
4726:
4727:            public void pushComplexType() {
4728:                pushCurrent(new ComplexType());
4729:            }
4730:
4731:            public void pushSequence() {
4732:                pushCurrent(new Sequence());
4733:            }
4734:
4735:            public ElementExpr popCurrent() {
4736:                lastPopped = (ElementExpr) currentElementStack.pop();
4737:                return lastPopped;
4738:            }
4739:
4740:            public ElementExpr peekCurrent() {
4741:                return (ElementExpr) currentElementStack.peek();
4742:            }
4743:
4744:            /**
4745:             * Find an ancestor in the current element stack of a certain type.
4746:             * Will return null if not found.
4747:             */
4748:            private ElementExpr findAncestor(Class type) {
4749:                for (int i = currentElementStack.size() - 1; i >= 0; --i) {
4750:                    ElementExpr ee = (ElementExpr) currentElementStack.get(i);
4751:                    if (type.isAssignableFrom(ee.getClass()))
4752:                        return ee;
4753:                }
4754:                return null;
4755:            }
4756:
4757:            /**
4758:             * Same thing as peekCurrent, but the caller needs it to be a
4759:             * ContainsSubElements.  If it isn't an exception is thrown.
4760:             */
4761:            public ContainsSubElements peekCurrentNeedSub() {
4762:                if (!(currentElementStack.peek() instanceof  ContainsSubElements))
4763:                    throw new ClassCastException(
4764:                            "Expected ContainsSubElements, but got "
4765:                                    + currentElementStack.peek().getClass()
4766:                                    + " instead on object "
4767:                                    + currentElementStack.peek());
4768:                return (ContainsSubElements) currentElementStack.peek();
4769:            }
4770:
4771:            public ElementExpr getLastPopped() {
4772:                return lastPopped;
4773:            }
4774:
4775:            /**
4776:             * Create an Element an add it to the current one in the stack.
4777:             */
4778:            public void addElement(String name, String type) {
4779:                Element el = createElement(name);
4780:                el.setType(type);
4781:                if (currentElementStack.empty())
4782:                    setRootElement(el);
4783:                else
4784:                    peekCurrentNeedSub().addSubElement(el);
4785:            }
4786:
4787:            /**
4788:             * Create AppInfo and add it to the current thing in the stack.
4789:             */
4790:            public void addAppInfo(String name, String value) {
4791:                ElementExpr e = peekCurrent();
4792:                Annotation ann;
4793:                if (e instanceof  Annotation)
4794:                    ann = (Annotation) e;
4795:                else
4796:                    ann = new Annotation();
4797:                AppInfo ai = new AppInfo();
4798:                AnyNode ue = new AnyNode(name, value);
4799:                ai.addSubElement(ue);
4800:                ann.addSubElement(ai);
4801:                peekCurrentNeedSub().addSubElement(ann);
4802:            }
4803:
4804:            /**
4805:             * Only works if the current thing in the stack is an Element.
4806:             * @t should be a java type.
4807:             */
4808:            public void setType(String t) {
4809:                ElementExpr e = peekCurrent();
4810:                if (e instanceof  Element)
4811:                    ((Element) e).setType(t);
4812:                else
4813:                    throw new IllegalStateException(Common.getMessage(
4814:                            "MSG_TryingToCallOnWrongClass", "setType", e
4815:                                    .getClass()));
4816:            }
4817:
4818:            public List findAllSubElements(String name) {
4819:                List lst = new LinkedList();
4820:                rootElement.findAllSubElements(name, lst);
4821:                return lst;
4822:            }
4823:
4824:            /**
4825:             * Only works if the current thing in the stack is an Element.
4826:             * @t should be a java type.
4827:             */
4828:            /*
4829:            public void setDefiningType(String t) {
4830:                ElementExpr e = peekCurrent();
4831:                if (e instanceof Element) {
4832:                    Element el = (Element) e;
4833:                    el.setDefiningType(t);
4834:                } else
4835:                    throw new IllegalStateException(Common.getMessage("MSG_TryingToCallOnWrongClass", "setDefiningType", e.getClass()));
4836:            }
4837:             */
4838:
4839:            /**
4840:             * Only works if the current thing in the stack is an Element.
4841:             * @t should be a XML Schema type.
4842:             */
4843:            public void setXMLSchemaType(String t) {
4844:                ElementExpr e = peekCurrent();
4845:                if (e instanceof  Element)
4846:                    ((Element) e).setXMLSchemaType(t);
4847:                else
4848:                    throw new IllegalStateException(Common.getMessage(
4849:                            "MSG_TryingToCallOnWrongClass", "setXMLSchemaType",
4850:                            e.getClass()));
4851:            }
4852:
4853:            /**
4854:             * Only works if the current thing in the stack is an Element or ModelGroup.
4855:             */
4856:            public void setMinOccurs(String t) {
4857:                ElementExpr e = peekCurrent();
4858:                if (e instanceof  Element)
4859:                    ((Element) e).setMinOccurs(t);
4860:                else if (e instanceof  ModelGroup)
4861:                    ((ModelGroup) e).setMinOccurs(t);
4862:                else
4863:                    throw new IllegalStateException(Common.getMessage(
4864:                            "MSG_TryingToCallOnWrongClass", "setMinOccurs", e
4865:                                    .getClass()));
4866:            }
4867:
4868:            /**
4869:             * Only works if the current thing in the stack is an Element or ModelGroup.
4870:             */
4871:            public void setMaxOccurs(String t) {
4872:                ElementExpr e = peekCurrent();
4873:                if (e instanceof  Element)
4874:                    ((Element) e).setMaxOccurs(t);
4875:                else if (e instanceof  ModelGroup)
4876:                    ((ModelGroup) e).setMaxOccurs(t);
4877:                else
4878:                    throw new IllegalStateException(Common.getMessage(
4879:                            "MSG_TryingToCallOnWrongClass", "setMaxOccurs", e
4880:                                    .getClass()));
4881:            }
4882:
4883:            /**
4884:             * Return an Element that represents an ELEMENT.
4885:             */
4886:            public Element createElement(String name) {
4887:                Element el = new Element(name);
4888:                return el;
4889:            }
4890:
4891:            /**
4892:             * Return an Element that represents an ELEMENT.
4893:             */
4894:            public Element createElement(String name, String type) {
4895:                Element el = new Element(name);
4896:                el.setType(type);
4897:                return el;
4898:            }
4899:
4900:            /*
4901:            public Attribute createAttirbute(String name) {
4902:                Attribute attr = (Attribute) attributeTable.get(name);
4903:                if (attr == null) {
4904:                    attr = new Attribute(name);
4905:                    attributeTable.put(name, attr);
4906:                }
4907:                return attr;
4908:            }
4909:             */
4910:
4911:            public void addSubElement(String elementName, ElementExpr subElement) {
4912:                Element el = createElement(elementName);
4913:                el.addSubElement(subElement);
4914:            }
4915:
4916:            public void addSubElement(String elementName, List subElements) {
4917:                Element el = createElement(elementName);
4918:                el.addSubElement(subElements);
4919:            }
4920:
4921:            public void addSubElement(String elementName, String subElementName) {
4922:                Element subElement = createElement(subElementName);
4923:                addSubElement(elementName, subElement);
4924:            }
4925:
4926:            /**
4927:             * This addSubElement creates an Element and then adds it underneath
4928:             * the current one.
4929:             */
4930:            public void addSubElementCurrent(String subElementName) {
4931:                Element subElement = createElement(subElementName);
4932:                peekCurrentNeedSub().addSubElement(subElement);
4933:            }
4934:
4935:            /**
4936:             * This is called before writing out a schema.
4937:             */
4938:            public ElementExpr optimize() {
4939:                if (rootElement == null)
4940:                    return null;
4941:                return rootElement.optimize();
4942:            }
4943:
4944:            /**
4945:             * Returns false if the schema is too simpile to need binding classes.
4946:             */
4947:            /*
4948:            public boolean needsBindingClasses() {
4949:                if (rootElement == null)
4950:                    return false;
4951:                System.out.println("rootElement="+rootElement+" .class="+rootElement.getClass());
4952:                if (rootElement instanceof Element) {
4953:                    Element root = (Element) rootElement;
4954:                    return root.hasNamedSubElements();
4955:                }
4956:                return true;
4957:            }
4958:             */
4959:
4960:            /**
4961:             * If you want a DTD written to a Writer, this is the method
4962:             * to call.
4963:             */
4964:            public void writeDTD(Writer out) throws java.io.IOException {
4965:                if (rootElement == null)
4966:                    return;
4967:                elementTable = new HashMap();
4968:                optimize();
4969:                rootElement.validate();
4970:                StringBuffer outBuffer = new StringBuffer();
4971:                rootElement.writeDTD(outBuffer);
4972:                out.write(outBuffer.toString());
4973:                elementTable = null;
4974:            }
4975:
4976:            /**
4977:             * nice method which returns writeDTD in an InputStream.
4978:             */
4979:            public InputStream dtdInputStream() throws java.io.IOException {
4980:                StringWriter strWriter = new StringWriter();
4981:                PrintWriter pw = new PrintWriter(strWriter);
4982:                writeDTD(pw);
4983:                pw.flush();
4984:                ByteArrayInputStream bais = new ByteArrayInputStream(strWriter
4985:                        .toString().getBytes());
4986:                return bais;
4987:            }
4988:
4989:            /**
4990:             * If you want an XML Schema written to a Writer, this is the method
4991:             * to call.
4992:             */
4993:            public void writeXMLSchemaStandalone(Writer out)
4994:                    throws java.io.IOException {
4995:                if (rootElement == null)
4996:                    return;
4997:                XMLWriter xw = new XMLWriter();
4998:                ContainsSubElements realRootElement = rootElement;
4999:                if (!(realRootElement instanceof  SchemaNode)) {
5000:                    SchemaNode sn = new SchemaNode();
5001:                    sn.addSubElement(realRootElement);
5002:                    realRootElement = sn;
5003:                    if (topAnnotation != null) {
5004:                        sn.addSubElement(topAnnotation);
5005:                    }
5006:                }
5007:
5008:                if (true || optimize() != null) {
5009:                    realRootElement.validate();
5010:                    realRootElement.writeXMLSchema(xw);
5011:                }
5012:                xw.writeTo(out);
5013:            }
5014:
5015:            /**
5016:             * Convience method which returns writeXMLSchemaStandalone in an
5017:             * InputStream.
5018:             */
5019:            public InputStream xmlSchemaInputStream()
5020:                    throws java.io.IOException {
5021:                StringWriter strWriter = new StringWriter();
5022:                PrintWriter pw = new PrintWriter(strWriter);
5023:                writeXMLSchemaStandalone(pw);
5024:                pw.flush();
5025:                ByteArrayInputStream bais = new ByteArrayInputStream(strWriter
5026:                        .toString().getBytes());
5027:                return bais;
5028:            }
5029:
5030:            public void writeXMLSchema(XMLWriter out) throws IOException {
5031:                if (rootElement == null)
5032:                    return;
5033:                rootElement.writeXMLSchema(out);
5034:            }
5035:
5036:            public void readSchemaFromLocation(String schemaLocation)
5037:                    throws IOException, SAXException {
5038:                if (debug)
5039:                    System.out.println("Reading schema from " + schemaLocation);
5040:                if (schemaLocation == null || "".equals(schemaLocation))
5041:                    return;
5042:
5043:                String oldParsedURI = currentParsedURI;
5044:                try {
5045:                    javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory
5046:                            .newInstance();
5047:                    dbf.setNamespaceAware(true);
5048:                    dbf.setIgnoringComments(true);
5049:                    dbf.setIgnoringElementContentWhitespace(true);
5050:                    javax.xml.parsers.DocumentBuilder db = dbf
5051:                            .newDocumentBuilder();
5052:                    Document doc = null;
5053:                    IOException ioException = null;
5054:                    SAXException saxException = null;
5055:                    try {
5056:                        doc = db.parse(schemaLocation);
5057:                        currentParsedURI = schemaLocation;
5058:                    } catch (java.io.FileNotFoundException e) {
5059:                        ioException = e;
5060:                    } catch (org.xml.sax.SAXParseException e) {
5061:                        // Apache will throw this one for a file not found error,
5062:                        // it really should be java.io.FileNotFoundException
5063:                        saxException = e;
5064:                    }
5065:                    if (ioException != null || saxException != null) {
5066:                        //System.out.println("currentParsedURI="+currentParsedURI);
5067:                        if (currentParsedURI != null) {
5068:                            // Try making a relative URI out of this.
5069:                            java.net.URI uri;
5070:                            try {
5071:                                uri = new java.net.URI(currentParsedURI);
5072:                            } catch (java.net.URISyntaxException e) {
5073:                                uri = new File(currentParsedURI).toURI();
5074:                            }
5075:                            if (debug)
5076:                                System.out.println("uri=" + uri);
5077:                            java.net.URI schemaLocationURI = uri
5078:                                    .resolve(schemaLocation);
5079:                            currentParsedURI = schemaLocationURI.toString();
5080:                            if (debug)
5081:                                System.out
5082:                                        .println("Since the first try failed, now trying to read currentParsedURI:"
5083:                                                + currentParsedURI);
5084:                            doc = db.parse(currentParsedURI);
5085:                            ioException = null;
5086:                            saxException = null;
5087:                        }
5088:                    }
5089:                    if (ioException != null)
5090:                        throw ioException;
5091:                    if (saxException != null)
5092:                        throw saxException;
5093:                    org.w3c.dom.Element childNode = doc.getDocumentElement();
5094:                    if (childNode != null) {
5095:                        if (!childNode.getLocalName().equals("schema")) // NOI18N
5096:                            throw new IllegalStateException(Common.getMessage(
5097:                                    "MSG_ExpectedNode", "schema", childNode
5098:                                            .getNodeName()));
5099:                        // Make sure to preserve the old stuff.
5100:                        readSchemaElement(childNode);
5101:                    }
5102:                } catch (javax.xml.parsers.ParserConfigurationException e) {
5103:                    throw new Schema2BeansRuntimeException(Common.getMessage(
5104:                            "MSG_FailedToParse", schemaLocation), e);
5105:                } finally {
5106:                    currentParsedURI = oldParsedURI;
5107:                }
5108:            }
5109:
5110:            public void readDocument(Document doc) {
5111:                includedAlready.clear();
5112:                org.w3c.dom.Element childNode = doc.getDocumentElement();
5113:                if (childNode != null) {
5114:                    if (!childNode.getLocalName().equals("schema")) // NOI18N
5115:                        throw new IllegalStateException(Common.getMessage(
5116:                                "MSG_ExpectedNode", "schema", childNode
5117:                                        .getNodeName()));
5118:                    pushSchemaNode();
5119:                    peekCurrentNeedSub().readSchema(childNode);
5120:                    readSchemaElement(childNode);
5121:                    popCurrent();
5122:                }
5123:            }
5124:
5125:            public void readSchemaElement(org.w3c.dom.Element el) {
5126:                NamedNodeMap attrs = el.getAttributes();
5127:                String theTargetNamespace = null;
5128:                String theDocumentNamespaceURI = null;
5129:                for (int i = 0, size = attrs.getLength(); i < size; ++i) {
5130:                    Node attr = attrs.item(i);
5131:                    //System.out.println("readSchemaElement: attr.prefix="+attr.getPrefix()+" localname="+attr.getLocalName()+" nodename="+attr.getNodeName()+" nodevalue="+attr.getNodeValue());
5132:                    if ("xmlns".equals(attr.getPrefix())) {
5133:                        addToNamespace(attr.getLocalName(), attr.getNodeValue());
5134:                    } else if ("targetNamespace".equals(attr.getNodeName())) {
5135:                        theTargetNamespace = attr.getNodeValue();
5136:                    } else if ("xmlns".equals(attr.getNodeName())) {
5137:                        theDocumentNamespaceURI = attr.getNodeValue();
5138:                    }
5139:                }
5140:                if (theDocumentNamespaceURI != null) {
5141:                    documentNamespace = theDocumentNamespaceURI;
5142:                    //System.out.println("readSchemaElement: just set documentNamespace to "+documentNamespace);
5143:                }
5144:                if (theTargetNamespace != null) {
5145:                    // This needs to be done after all the namespaces have been read
5146:                    targetNamespace = theTargetNamespace;
5147:                    //System.out.println("readSchemaElement: just set targetNamespace to "+targetNamespace);
5148:                }
5149:                ContainsSubElements re = getRootElement();
5150:                if (re instanceof  SchemaNode) {
5151:                    SchemaNode schemaNode = (SchemaNode) re;
5152:                    schemaNode.merge(el);
5153:                }
5154:                read(el);
5155:            }
5156:
5157:            protected void read(Node node) {
5158:                String nodeName;
5159:                boolean ignoreUnknown = false;
5160:                boolean keepText = false;
5161:                if (peekCurrent() instanceof  AnyNode
5162:                        || peekCurrent() instanceof  Documentation
5163:                        || peekCurrent() instanceof  AppInfo
5164:                        || peekCurrent() instanceof  TextNode) {
5165:                    keepText = true;
5166:                    ignoreUnknown = true;
5167:                }
5168:                AnyNode anyNode = new AnyNode("dummy1", "dummy2"); // NOI18N
5169:                TextNode textNode = new TextNode("dummy"); // NOI18N
5170:                NodeList children = node.getChildNodes();
5171:                for (int i = 0; i < children.getLength(); ++i) {
5172:                    Node childNode = children.item(i);
5173:                    if (childNode instanceof  org.w3c.dom.Element) {
5174:                        org.w3c.dom.Element childElement = (org.w3c.dom.Element) childNode;
5175:                        //nodeName = childElement.getNodeName().intern();
5176:                        nodeName = childElement.getLocalName().intern();
5177:                        //System.out.println("Found a "+nodeName);
5178:                        ElementExpr ee = getSampleNode(nodeName);
5179:                        if (ee == null) {
5180:                            if (!ignoreUnknown)
5181:                                System.out
5182:                                        .println("SchemaRep Warning: unknown node at "
5183:                                                + getXPathExpr(childElement));
5184:                            anyNode.readSchema(childElement);
5185:                        } else {
5186:                            ee.readSchema(childElement);
5187:                        }
5188:                    } else if (keepText && childNode instanceof  Text) {
5189:                        textNode.readSchema((Text) childNode);
5190:                    }
5191:                }
5192:            }
5193:
5194:            static public String getXPathExpr(Node node) {
5195:                return getXPathExpr(node, true);
5196:            }
5197:
5198:            static public String getXPathExpr(Node node, boolean addDescription) {
5199:                if (node instanceof  Document)
5200:                    return "/";
5201:                Node parentNode = node.getParentNode();
5202:                if (parentNode instanceof  Document)
5203:                    return "/" + node.getNodeName();
5204:                String curNodeName = node.getNodeName();
5205:                if (addDescription && node instanceof  org.w3c.dom.Element) {
5206:                    String nameAttr = ((org.w3c.dom.Element) node)
5207:                            .getAttribute("name");
5208:                    if (nameAttr != null && !"".equals(nameAttr))
5209:                        curNodeName += " name='" + nameAttr + "'";
5210:                }
5211:                return getXPathExpr(node.getParentNode(), addDescription) + "/"
5212:                        + curNodeName;
5213:            }
5214:
5215:            public String schemaTypeToJavaType(String xmlSchemaType) {
5216:                ElementExpr schemaTypeDef = getSchemaTypeDef(xmlSchemaType);
5217:                if (schemaTypeDef == null) {
5218:                    System.out.println(Common.getMessage(
5219:                            "MSG_UnableToFindTypeDef", xmlSchemaType));
5220:                    return null;
5221:                }
5222:
5223:                String javaType = null;
5224:                //System.out.println("schemaTypeToJavaType: "+xmlSchemaType+" schemaTypeDef="+schemaTypeDef);
5225:                if (schemaTypeDef instanceof  HasJavaTypeName) {
5226:                    javaType = ((SchemaRep.HasJavaTypeName) schemaTypeDef)
5227:                            .getJavaTypeName();
5228:                } else {
5229:                    System.out.println("!!! What's the java type of "
5230:                            + schemaTypeDef + " for " + xmlSchemaType);
5231:                }
5232:                //System.out.println("schemaTypeToJavaType: "+xmlSchemaType+" -> "+javaType);
5233:                return javaType;
5234:            }
5235:
5236:            /**
5237:             * Get an ElementExpr node for a named type.
5238:             * null is an acceptable return value if not found.
5239:             * If @param typeName is null, null is returned.
5240:             * If @param typeName's namespace is not set, then we first
5241:             * check the documentNamespace, then the targetNamespace.
5242:             */
5243:            public ElementExpr getSchemaTypeDef(String origTypeName) {
5244:                String typeName = origTypeName;
5245:                //System.out.println("getSchemaTypeDef: looking up "+typeName);
5246:                if (typeName == null)
5247:                    return null;
5248:                typeName = resolveNamespace(typeName);
5249:                ElementExpr result = (ElementExpr) schemaTypeDefs.get(typeName);
5250:                if (result != null)
5251:                    return result;
5252:                String ns = prefixOf(origTypeName);
5253:                if (ns == null)
5254:                    typeName = canonicalQName(documentNamespace,
5255:                            removePrefix(origTypeName));
5256:                result = (ElementExpr) schemaTypeDefs.get(typeName);
5257:                if (result != null)
5258:                    return result;
5259:                /*
5260:                if (result == null && ns == null) {
5261:                    // try the other namespace
5262:                    typeName = resolveNamespace(targetNamespace, typeName);
5263:                    System.out.println("getSchemaTypeDef2: looking up "+typeName);
5264:                    result = (ElementExpr) schemaTypeDefs.get(typeName);
5265:                }
5266:                 */
5267:                return (ElementExpr) definedTypes.get(origTypeName);
5268:            }
5269:
5270:            /**
5271:             * Same thing as getSchemaTypeDef, but for already resolved type names.
5272:             */
5273:            public ElementExpr getSchemaTypeDefResolvedNamespace(String typeName) {
5274:                ElementExpr result = (ElementExpr) schemaTypeDefs.get(typeName);
5275:                if (result == null) {
5276:                    result = (ElementExpr) definedTypes.get(typeName);
5277:                }
5278:                return result;
5279:            }
5280:
5281:            /**
5282:             * @return the Set of all defined element names in a format that
5283:             *         can be passed to getSchemaTypeDefResolvedNamespace.
5284:             */
5285:            public Set/*<String>*/getSchemaTypeNames() {
5286:                return schemaTypeDefs.keySet();
5287:            }
5288:
5289:            public Element getDefinedElement(String typeName) {
5290:                String t = resolveNamespace(typeName);
5291:                return getDefinedElementResolvedNamespace(t);
5292:            }
5293:
5294:            /**
5295:             * @param typeName is the resolved type name "{http://foo}login"
5296:             * @return the Element which defines it, or null if not found.
5297:             */
5298:            public Element getDefinedElementResolvedNamespace(String typeName) {
5299:                return (Element) definedTypesFull.get(typeName);
5300:            }
5301:
5302:            /**
5303:             * @return the Set of all defined element names in a format that
5304:             *         can be passed to getDefinedElementResolvedNamespace.
5305:             */
5306:            public Set/*<String>*/getDefinedElementNames() {
5307:                return definedTypesFull.keySet();
5308:            }
5309:
5310:            public void putSchemaTypeDef(String typeName, ElementExpr ee) {
5311:                if (typeName == null)
5312:                    return;
5313:                String ns = prefixOf(typeName);
5314:                if (ns == null)
5315:                    typeName = resolveNamespace(targetNamespace,
5316:                            removePrefix(typeName));
5317:                else
5318:                    typeName = resolveNamespace(ns, removePrefix(typeName));
5319:                //System.out.println("putSchemaTypeDef: putting in "+typeName);
5320:                schemaTypeDefs.put(typeName, ee);
5321:            }
5322:
5323:            /**
5324:             * Will convert a typeName into {namespace}typeName format.
5325:             * eg: 'xsd:string' -> '{http://www.w3.org/2001/XMLSchema}string'
5326:             * eg: 'item' -> 'item'
5327:             */
5328:            public String resolveNamespace(String typeName) {
5329:                return resolveNamespaceDefault(typeName, targetNamespace);
5330:            }
5331:
5332:            protected String resolveNamespaceDefault(String typeName,
5333:                    String defaultNS) {
5334:                if (typeName == null)
5335:                    return null;
5336:                String prefix = prefixOf(typeName);
5337:                //System.out.println("resolveNamespace1: ns="+ns+" typeName="+typeName);
5338:                typeName = resolveNamespaceDefault(prefix, defaultNS,
5339:                        removePrefix(typeName));
5340:                //System.out.println("resolveNamespace2: typeName="+typeName);
5341:                return typeName;
5342:            }
5343:
5344:            public String resolveNamespace(String ns, String type) {
5345:                return resolveNamespaceDefault(ns, targetNamespace, type);
5346:            }
5347:
5348:            protected String resolveNamespaceDefault(String prefix,
5349:                    String defaultNS, String type) {
5350:                String uri;
5351:                if (prefix == null) {
5352:                    if (defaultNS == null)
5353:                        return type;
5354:                    uri = defaultNS;
5355:                } else {
5356:                    uri = getNamespaceURI(prefix);
5357:                    if (uri == null) {
5358:                        System.out
5359:                                .println("resolveNamespace: Namespace prefix '"
5360:                                        + prefix + "' was not found (type="
5361:                                        + type + ").");
5362:                        new Exception().printStackTrace();
5363:                    }
5364:                }
5365:                return canonicalQName(uri, type);
5366:            }
5367:
5368:            public static String canonicalQName(String namespaceURI,
5369:                    String localPart) {
5370:                if (namespaceURI == null || namespaceURI.equals(""))
5371:                    return localPart;
5372:                return "{" + namespaceURI + "}" + localPart;
5373:            }
5374:
5375:            /**
5376:             * Will add a namespace prefix to a type if the targetNamespace != null.
5377:             * eg: targetNamespace='j2ee' type='ejbType' -> 'j2ee:ejbType'
5378:             * eg: targetNamespace='j2ee' type='xsd:string' -> 'xsd:string'
5379:             * eg: targetNamespace=null type='item' -> 'item'
5380:             */
5381:            protected String normalizeTargetNamespace(String type) {
5382:                if (type == null)
5383:                    return null;
5384:                if (targetNamespace == null)
5385:                    return type;
5386:                if (type.indexOf(':') >= 0)
5387:                    return type;
5388:                return normalizeNamespace(targetNamespace, type);
5389:            }
5390:
5391:            /**
5392:             * return prefix ':' localPart
5393:             * eg: namespaceURI="http://www.w3.org/XML/1998/namespace" localPart="id" -> "xml:id"
5394:             * eg: namespaceURI="" localPart="foo" -> "foo"
5395:             * eg: namespaceURI=null localPart="bar" -> "bar"
5396:             */
5397:            protected String normalizeNamespace(String namespaceURI,
5398:                    String localPart) {
5399:                if (localPart == null)
5400:                    return null;
5401:                if (namespaceURI == null || "".equals(namespaceURI))
5402:                    return localPart;
5403:                String prefix = getNamespace(namespaceURI);
5404:                return prefix + ":" + localPart;
5405:            }
5406:
5407:            protected String normalizeDocumentNamespace(String type) {
5408:                if (type == null)
5409:                    return null;
5410:                if (documentNamespace == null)
5411:                    return type;
5412:                if (type.indexOf(':') >= 0)
5413:                    return type;
5414:                return normalizeNamespace(documentNamespace, type);
5415:            }
5416:
5417:            /**
5418:             * @param schemaTypeName The name of a leaf schema element, like 'integer'.
5419:             * @param javaType  The java class schemaTypeName gets mapped to, like 'int'.
5420:             */
5421:            public void setSchemaTypeMapping(String schemaTypeNamespace,
5422:                    String schemaTypeName, String javaType) {
5423:                //System.out.println("setSchemaTypeMapping: schemaTypeNamespace="+schemaTypeNamespace+" schemaTypeName="+schemaTypeName+" javaType="+javaType);
5424:                String ns;
5425:                SimpleType st;
5426:                if (schemaTypeNamespace == null) {
5427:                    st = new SimpleType(schemaTypeName, javaType);
5428:                } else {
5429:                    ns = getNamespace(schemaTypeNamespace);
5430:                    st = new SimpleType(ns + ":" + schemaTypeName, javaType);
5431:                }
5432:            }
5433:
5434:            /**
5435:             * Setup the schema to java type mapping to make more sense for J2ME.
5436:             */
5437:            public void setSchemaTypesForME(boolean isFloatingPoint) {
5438:                setSchemaTypeMapping(XSD_NS, "anyURI", "java.lang.String");
5439:                setSchemaTypeMapping(XSD_NS, "decimal",
5440:                        isFloatingPoint ? "double" : "java.lang.String");
5441:                setSchemaTypeMapping(XSD_NS, "integer", "long");
5442:                if (!isFloatingPoint) {
5443:                    setSchemaTypeMapping(XSD_NS, "double", "java.lang.String");
5444:                    setSchemaTypeMapping(XSD_NS, "float", "java.lang.String");
5445:                }
5446:            }
5447:
5448:            private void insertPredefinedSchemaTypes(Map st) {
5449:                //System.out.println("Hit insertPredefinedSchemaTypes");
5450:                String namespace = getXSDNamespace() + ":";
5451:                String[] types = new String[] { "java.lang.String",
5452:                        "java.util.Calendar", "java.util.Calendar", "long",
5453:                        "int", "char", "short", "double", "float", "byte",
5454:                        "boolean", "java.lang.String", "long", "long", "long",
5455:                        "long", "long", "int", "short", "byte", "java.net.URI",
5456:                        "javax.xml.namespace.QName", "java.lang.String",
5457:                        "java.lang.String", "java.lang.String",
5458:                        "java.lang.String", "java.lang.String",
5459:                        "java.lang.String", "java.lang.String", "int",
5460:                        "java.lang.String", "java.lang.String",
5461:                        "java.lang.String", "java.lang.String" };
5462:                String[] schemaType = new String[] { "string", "dateTime",
5463:                        "date", "long", "int", "char", "short", "double",
5464:                        "float", "byte", "boolean", "NMTOKEN",
5465:                        "positiveInteger", "nonNegativeInteger",
5466:                        "nonPositiveInteger", "negativeInteger",
5467:                        "unsignedLong", "unsignedInt", "unsignedShort",
5468:                        "unsignedByte", "anyURI", "QName", "NCName", "Name",
5469:                        "duration", "time", "ID", "token", "normalizedString",
5470:                        "gYear", "gYearMonth", "gMonthDay", "gDay", "gMonth" };
5471:                for (int i = 0; i < schemaType.length; ++i)
5472:                    st.put(schemaType[i], new SimpleType(namespace
5473:                            + schemaType[i], types[i]));
5474:                if (useBigDataTypes) {
5475:                    st.put("decimal", new SimpleType(namespace + "decimal",
5476:                            "java.math.BigDecimal"));
5477:                    st.put("integer", new SimpleType(namespace + "integer",
5478:                            "java.math.BigInteger"));
5479:                } else {
5480:                    st.put("decimal", new SimpleType(namespace + "decimal",
5481:                            "double"));
5482:                    st.put("integer", new SimpleType(namespace + "integer",
5483:                            "long"));
5484:                }
5485:                String[] whiteSpaceReplace = new String[] { "normalizedString" };
5486:                for (int i = 0; i < whiteSpaceReplace.length; ++i) {
5487:                    SimpleType t = (SimpleType) st.get(whiteSpaceReplace[i]);
5488:                    Restriction restrict = new Restriction(namespace + "string");
5489:                    t.addSubElement(restrict);
5490:                    WhiteSpace ws = new WhiteSpace("replace");
5491:                    restrict.addSubElement(ws);
5492:                }
5493:                String[] whiteSpaceCollapse = new String[] { "token",
5494:                        "NMTOKEN", "Name", "NCName", "ID" };
5495:                for (int i = 0; i < whiteSpaceCollapse.length; ++i) {
5496:                    SimpleType t = (SimpleType) st.get(whiteSpaceCollapse[i]);
5497:                    Restriction restrict = new Restriction(namespace
5498:                            + "normalizedString");
5499:                    t.addSubElement(restrict);
5500:                    WhiteSpace ws = new WhiteSpace("collapse");
5501:                    restrict.addSubElement(ws);
5502:                }
5503:                addRestriction((SimpleType) st.get("nonPositiveInteger"),
5504:                        namespace + "integer", new MaxInclusive("0"));
5505:                addRestriction((SimpleType) st.get("negativeInteger"),
5506:                        namespace + "nonPositiveInteger", new MaxExclusive("0"));
5507:                addRestriction((SimpleType) st.get("nonNegativeInteger"),
5508:                        namespace + "integer", new MinInclusive("0"));
5509:                addRestriction((SimpleType) st.get("unsignedLong"), namespace
5510:                        + "nonNegativeInteger", new MinInclusive("0"));
5511:                addRestriction((SimpleType) st.get("unsignedInt"), namespace
5512:                        + "unsignedLong", new MinInclusive("0"));
5513:                addRestriction((SimpleType) st.get("positiveInteger"),
5514:                        namespace + "nonNegativeInteger", new MinExclusive("0"));
5515:
5516:                st.put("hexBinary", new HexBinary());
5517:                st.put("base64Binary", new Base64Binary());
5518:            }
5519:
5520:            protected void addRestriction(ContainsSubElements cse,
5521:                    String restrictionBase, RestrictionType rt) {
5522:                Restriction restrict = new Restriction(restrictionBase);
5523:                cse.addSubElement(restrict);
5524:                restrict.addSubElement(rt);
5525:            }
5526:
5527:            /**
5528:             * Map simple types to our schema.
5529:             */
5530:            public void mapSimpleJavaTypesOptional(Map optionalElementMap) {
5531:                //System.out.println("Hit mapSimpleJavaTypesOptional");
5532:                String namespace = getXSDNamespace() + ":";
5533:                // These guys are ones that we are willing to add to the XML Schema,
5534:                // but are optional (not everyone uses everyone of them).
5535:                String[] types = new String[] { "java.lang.Integer",
5536:                        "java.lang.Short", "java.lang.Long",
5537:                        "java.lang.Double", "java.lang.Float",
5538:                        "java.lang.Boolean", "java.lang.Character",
5539:                        "java.lang.StringBuffer", "java.lang.Byte",
5540:                        "java.math.BigInteger", "char[]", "char" };
5541:                String[] restrictions = new String[] { "int", "short", "long",
5542:                        "double", "float", "boolean", "string", "string",
5543:                        "byte", "integer", "string", "string" };
5544:                for (int i = 0; i < types.length; ++i)
5545:                    optionalElementMap.put(types[i], new SimpleType(
5546:                            javaType2XMLSchemaType(types[i]), new Restriction(
5547:                                    namespace + restrictions[i])));
5548:            }
5549:
5550:            private void mapSimpleAttributes(Map a) {
5551:                a.put("xml:lang", new Attribute("lang", getNamespaceURI("xml"),
5552:                        "xsd:string"));
5553:            }
5554:
5555:            /**
5556:             * Map simple types to our schema.
5557:             */
5558:            public void mapSimpleJavaTypesPredefined(Map definedElementMap) {
5559:                //System.out.println("Hit mapSimpleJavaTypesPredefined");
5560:                String namespace = getXSDNamespace() + ":";
5561:                // These guys are already defined in XML Schema.  The java
5562:                // types have 1-to-1 mappings.
5563:                String[] types = new String[] { "java.lang.String", "String",
5564:                        "java.math.BigDecimal", "java.util.Calendar", "long",
5565:                        "int", "char", "short", "double", "float", "byte",
5566:                        "boolean" };
5567:                String[] schemaType = new String[] { "string", "string",
5568:                        "decimal", "dateTime", "long", "int", "char", "short",
5569:                        "double", "float", "byte", "boolean" };
5570:                for (int i = 0; i < types.length; ++i) {
5571:                    ElementExpr def = getSchemaTypeDef(schemaType[i]);
5572:                    if (def == null)
5573:                        def = new SimpleType(namespace + schemaType[i],
5574:                                types[i]);
5575:                    definedElementMap.put(types[i], def);
5576:                }
5577:            }
5578:
5579:            /**
5580:             * Define some helpful java to XML Schema data types that allow us
5581:             * to go back and forth between the two (allows me to setup a 1-to-1
5582:             * mapping with the client proxy generator).
5583:             */
5584:            public static void printExtraJavaTypes(Writer out, int level)
5585:                    throws java.io.IOException {
5586:                // Create one of ourselves to get around the problem of calling
5587:                // a nonstatic method (that does not need any context)
5588:                // from a static method.
5589:                SchemaRep schema = new SchemaRep();
5590:                Map elementMap = new HashMap();
5591:                schema.mapSimpleJavaTypesOptional(elementMap);
5592:                Iterator it = elementMap.keySet().iterator();
5593:                XMLWriter xw = new XMLWriter(false);
5594:                while (it.hasNext()) {
5595:                    Object key = it.next();
5596:                    ElementExpr el = (ElementExpr) elementMap.get(key);
5597:                    el.writeXMLSchema(xw);
5598:                }
5599:                xw.writeTo(out);
5600:                out.write("\n"); // NOI18N
5601:            }
5602:
5603:            private static String javaType2XMLSchemaType(String typeName) {
5604:                return javaType2XMLSchemaType(typeName, false);
5605:            }
5606:
5607:            /**
5608:             * Convert a java type into an XML Schema type.
5609:             * eg, java.lang.String -> xsd:string
5610:             */
5611:            private static String javaType2XMLSchemaType(String typeName,
5612:                    boolean unknownOkay) {
5613:                // BEGIN_NOI18N
5614:                if ("java.lang.String".equals(typeName)
5615:                        || "String".equals(typeName))
5616:                    return "xsd:string";
5617:                if ("java.lang.Integer".equals(typeName)
5618:                        || "java.lang.Short".equals(typeName)
5619:                        || "java.lang.Long".equals(typeName)
5620:                        || "java.lang.Double".equals(typeName)
5621:                        || "java.lang.Boolean".equals(typeName)
5622:                        || "java.lang.Character".equals(typeName)
5623:                        || "java.lang.Float".equals(typeName)
5624:                        || "java.lang.StringBuffer".equals(typeName)
5625:                        || "java.lang.Byte".equals(typeName)
5626:                        || "java.math.BigInteger".equals(typeName)
5627:                        || "char".equals(typeName))
5628:                    return typeName;
5629:                if ("char[]".equals(typeName))
5630:                    return "char_lb_rb";
5631:                if (JavaUtil.isPrimitiveType(typeName))
5632:                    return "xsd:" + typeName;
5633:                if ("java.math.BigDecimal".equals(typeName))
5634:                    return "xsd:decimal";
5635:                if ("java.util.Calendar".equals(typeName))
5636:                    return "xsd:dateTime";
5637:                if ("java.net.URI".equals(typeName))
5638:                    return "xsd:anyURI";
5639:                if ("javax.xml.namespace.QName".equals(typeName))
5640:                    return "xsd:QName";
5641:                if (!unknownOkay) {
5642:                    String err = "javaType2XMLSchemaType: No known XML Schema type for '"
5643:                            + typeName + "'.";
5644:                    System.out.println(err);
5645:                    return typeName;
5646:                }
5647:                return null;
5648:                // END_NOI18N
5649:            }
5650:
5651:            /**
5652:             * Takes a Java type (like 'java.lang.String' or 'double') and
5653:             * says whether or not javaType2XMLSchemaType will return a good,
5654:             * predefined type for it.
5655:             */
5656:            private static boolean isXMLSchemaDefinedType(String typeName) {
5657:                if (javaType2XMLSchemaType(typeName, true) == null)
5658:                    return false;
5659:                return true;
5660:            }
5661:
5662:            public String javaType2XMLSchemaTypeComplex(String type) {
5663:                //System.out.println("javaType2XMLSchemaTypeComplex type="+type);
5664:                Object el;
5665:                el = definedTypes.get(type);
5666:                if (el == null)
5667:                    el = optionallyDefinedTypes.get(type);
5668:                if (el == null)
5669:                    el = predefinedSchemaTypes.get(type);
5670:                if (el == null) {
5671:                    if (debug)
5672:                        System.out.println("No type found for " + type);
5673:                    return javaType2XMLSchemaType(type);
5674:                }
5675:                if (el instanceof  SimpleType)
5676:                    return ((SimpleType) el).getTypeName();
5677:                if (el instanceof  String)
5678:                    return (String) el;
5679:                if (el instanceof  Element)
5680:                    return ((Element) el).getElementName();
5681:                return el.getClass().toString();
5682:            }
5683:
5684:            public boolean isDefinedType(String type) {
5685:                if (optionallyDefinedTypes.containsKey(type))
5686:                    return true;
5687:                if (definedTypes.containsKey(type))
5688:                    return true;
5689:                return false;
5690:            }
5691:
5692:            public boolean isPredefinedType(String type) {
5693:                boolean rv = false;
5694:                if (predefinedSchemaTypes.get(type) != null)
5695:                    rv = true;
5696:                return rv;
5697:            }
5698:
5699:            /*
5700:             * Removes any namespace prefix.
5701:             *    eg: 'xsd:element' -> 'element'
5702:             */
5703:            public static String removePrefix(String typeName) {
5704:                int pos = typeName.indexOf(':');
5705:                if (pos < 0)
5706:                    return typeName;
5707:                return typeName.substring(pos + 1);
5708:            }
5709:
5710:            /**
5711:             * eg: 'xsd:element' -> 'xsd'
5712:             */
5713:            public static String prefixOf(String typeName) {
5714:                int pos = typeName.indexOf(':');
5715:                if (pos < 0)
5716:                    return null;
5717:                return typeName.substring(0, pos);
5718:            }
5719:
5720:            /**
5721:             * Guess what a prefix of this namespaceURI might be.
5722:             */
5723:            public static String guessPrefix(String namespaceURI) {
5724:                if ("http://www.w3.org/XML/1998/namespace".equals(namespaceURI))
5725:                    return "xml";
5726:                String prefix;
5727:                int pos = namespaceURI.lastIndexOf('/');
5728:                if (pos >= 0)
5729:                    prefix = namespaceURI.substring(pos + 1, namespaceURI
5730:                            .length());
5731:                else
5732:                    prefix = namespaceURI;
5733:                prefix = prefix.replace('#', '_').replace('\'', '_').replace(
5734:                        '"', '_').replace(':', '_');
5735:                // Not supposed to have a prefix that starts with xml
5736:                if (prefix.startsWith("xml"))
5737:                    prefix = "x" + prefix;
5738:                return prefix;
5739:            }
5740:
5741:            /**
5742:             * Try to figure out what prefix to use for the namespaceURI
5743:             * using the namespace context mapping, and if that fails then it
5744:             * calls guessPrefix.
5745:             */
5746:            public String guessPrefixFromURI(String uri) {
5747:                String prefix = getNamespace(uri);
5748:                if (prefix != null)
5749:                    return prefix;
5750:                return guessPrefix(uri);
5751:            }
5752:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.