jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/ModelLoader.java
changeset 32904 42076a665ea1
parent 25871 b80b84e87032
child 33547 e4c76ac38b12
equal deleted inserted replaced
32803:51b2db2fa04c 32904:42076a665ea1
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    36 import com.sun.tools.internal.xjc.reader.internalizer.DOMForest;
    36 import com.sun.tools.internal.xjc.reader.internalizer.DOMForest;
    37 import com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner;
    37 import com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner;
    38 import com.sun.tools.internal.xjc.reader.internalizer.InternalizationLogic;
    38 import com.sun.tools.internal.xjc.reader.internalizer.InternalizationLogic;
    39 import com.sun.tools.internal.xjc.reader.internalizer.SCDBasedBindingSet;
    39 import com.sun.tools.internal.xjc.reader.internalizer.SCDBasedBindingSet;
    40 import com.sun.tools.internal.xjc.reader.internalizer.VersionChecker;
    40 import com.sun.tools.internal.xjc.reader.internalizer.VersionChecker;
    41 import com.sun.tools.internal.xjc.reader.relaxng.RELAXNGCompiler;
       
    42 import com.sun.tools.internal.xjc.reader.relaxng.RELAXNGInternalizationLogic;
       
    43 import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder;
    41 import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder;
    44 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl;
    42 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl;
    45 import com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker;
    43 import com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker;
    46 import com.sun.tools.internal.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker;
    44 import com.sun.tools.internal.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker;
    47 import com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker;
    45 import com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker;
    52 import com.sun.xml.internal.xsom.parser.JAXPParser;
    50 import com.sun.xml.internal.xsom.parser.JAXPParser;
    53 import com.sun.xml.internal.xsom.parser.XMLParser;
    51 import com.sun.xml.internal.xsom.parser.XMLParser;
    54 import com.sun.xml.internal.xsom.parser.XSOMParser;
    52 import com.sun.xml.internal.xsom.parser.XSOMParser;
    55 import javax.xml.XMLConstants;
    53 import javax.xml.XMLConstants;
    56 
    54 
    57 import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
       
    58 import com.sun.xml.internal.rngom.ast.util.CheckingSchemaBuilder;
       
    59 import com.sun.xml.internal.rngom.digested.DPattern;
       
    60 import com.sun.xml.internal.rngom.digested.DSchemaBuilderImpl;
       
    61 import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
       
    62 import com.sun.xml.internal.rngom.parse.Parseable;
       
    63 import com.sun.xml.internal.rngom.parse.compact.CompactParseable;
       
    64 import com.sun.xml.internal.rngom.parse.xml.SAXParseable;
       
    65 import com.sun.xml.internal.rngom.xml.sax.XMLReaderCreator;
       
    66 import org.w3c.dom.Document;
    55 import org.w3c.dom.Document;
    67 import org.w3c.dom.Element;
    56 import org.w3c.dom.Element;
    68 import org.w3c.dom.NodeList;
    57 import org.w3c.dom.NodeList;
    69 import org.xml.sax.Attributes;
    58 import org.xml.sax.Attributes;
    70 import org.xml.sax.ContentHandler;
    59 import org.xml.sax.ContentHandler;
    71 import org.xml.sax.EntityResolver;
    60 import org.xml.sax.EntityResolver;
    72 import org.xml.sax.ErrorHandler;
    61 import org.xml.sax.ErrorHandler;
    73 import org.xml.sax.InputSource;
    62 import org.xml.sax.InputSource;
    74 import org.xml.sax.SAXException;
    63 import org.xml.sax.SAXException;
    75 import org.xml.sax.SAXParseException;
    64 import org.xml.sax.SAXParseException;
    76 import org.xml.sax.XMLFilter;
       
    77 import org.xml.sax.XMLReader;
       
    78 import org.xml.sax.helpers.XMLFilterImpl;
    65 import org.xml.sax.helpers.XMLFilterImpl;
    79 
    66 
    80 /**
    67 /**
    81  * Builds a {@link Model} object.
    68  * Builds a {@link Model} object.
    82  *
    69  *
   139 
   126 
   140                 checkTooManySchemaErrors();
   127                 checkTooManySchemaErrors();
   141                 grammar = loadDTD(opt.getGrammars()[0], bindFile );
   128                 grammar = loadDTD(opt.getGrammars()[0], bindFile );
   142                 break;
   129                 break;
   143 
   130 
   144             case RELAXNG :
       
   145                 checkTooManySchemaErrors();
       
   146                 grammar = loadRELAXNG();
       
   147                 break;
       
   148 
       
   149             case RELAXNG_COMPACT :
       
   150                 checkTooManySchemaErrors();
       
   151                 grammar = loadRELAXNGCompact();
       
   152                 break;
       
   153 
       
   154             case WSDL:
   131             case WSDL:
   155                 grammar = annotateXMLSchema( loadWSDL() );
   132                 grammar = annotateXMLSchema( loadWSDL() );
   156                 break;
   133                 break;
   157 
   134 
   158             case XMLSCHEMA:
   135             case XMLSCHEMA:
   203 
   180 
   204             String[] msg = null;
   181             String[] msg = null;
   205             switch(guess) {
   182             switch(guess) {
   206             case DTD:
   183             case DTD:
   207                 msg = new String[]{"DTD","-dtd"};
   184                 msg = new String[]{"DTD","-dtd"};
   208                 break;
       
   209             case RELAXNG:
       
   210                 msg = new String[]{"RELAX NG","-relaxng"};
       
   211                 break;
       
   212             case RELAXNG_COMPACT:
       
   213                 msg = new String[]{"RELAX NG compact syntax","-relaxng-compact"};
       
   214                 break;
   185                 break;
   215             case WSDL:
   186             case WSDL:
   216                 msg = new String[]{"WSDL","-wsdl"};
   187                 msg = new String[]{"WSDL","-wsdl"};
   217                 break;
   188                 break;
   218             }
   189             }
   526             scdBasedBindingSet.apply(result,errorReceiver);
   497             scdBasedBindingSet.apply(result,errorReceiver);
   527 
   498 
   528         return result;
   499         return result;
   529     }
   500     }
   530 
   501 
   531     /**
       
   532      * Parses a RELAX NG grammar into an annotated grammar.
       
   533      */
       
   534     private Model loadRELAXNG() throws SAXException {
       
   535 
       
   536         // build DOM forest
       
   537         final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );
       
   538 
       
   539         // use JAXP masquerading to validate the input document.
       
   540         // DOMForest -> ExtensionBindingChecker -> RNGOM
       
   541 
       
   542         XMLReaderCreator xrc = new XMLReaderCreator() {
       
   543             public XMLReader createXMLReader() {
       
   544 
       
   545                 // foreset parser cannot change the receivers while it's working,
       
   546                 // so we need to have one XMLFilter that works as a buffer
       
   547                 XMLFilter buffer = new XMLFilterImpl() {
       
   548                     @Override
       
   549                     public void parse(InputSource source) throws IOException, SAXException {
       
   550                         forest.createParser().parse( source, this, this, this );
       
   551                     }
       
   552                 };
       
   553 
       
   554                 XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
       
   555                 f.setParent(buffer);
       
   556 
       
   557                 f.setEntityResolver(opt.entityResolver);
       
   558 
       
   559                 return f;
       
   560             }
       
   561         };
       
   562 
       
   563         Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );
       
   564 
       
   565         return loadRELAXNG(p);
       
   566 
       
   567     }
       
   568 
       
   569     /**
       
   570      * Loads RELAX NG compact syntax
       
   571      */
       
   572     private Model loadRELAXNGCompact() {
       
   573         if(opt.getBindFiles().length>0)
       
   574             errorReceiver.error(new SAXParseException(
       
   575                 Messages.format(Messages.ERR_BINDING_FILE_NOT_SUPPORTED_FOR_RNC),null));
       
   576 
       
   577         // TODO: entity resolver?
       
   578         Parseable p = new CompactParseable( opt.getGrammars()[0], errorReceiver );
       
   579 
       
   580         return loadRELAXNG(p);
       
   581 
       
   582     }
       
   583 
       
   584     /**
       
   585      * Common part between the XML syntax and the compact syntax.
       
   586      */
       
   587     private Model loadRELAXNG(Parseable p) {
       
   588         SchemaBuilder sb = new CheckingSchemaBuilder(new DSchemaBuilderImpl(),errorReceiver);
       
   589 
       
   590         try {
       
   591             DPattern out = (DPattern)p.parse(sb);
       
   592             return RELAXNGCompiler.build(out,codeModel,opt);
       
   593         } catch (IllegalSchemaException e) {
       
   594             errorReceiver.error(e.getMessage(),e);
       
   595             return null;
       
   596         }
       
   597     }
       
   598 }
   502 }