feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.parser;
|
||||
|
||||
/**
|
||||
* Enumeration used to represent the type of the schema component
|
||||
* that is being parsed when the AnnotationParser is called.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
final public class AnnotationContext {
|
||||
|
||||
/** Display name of the context. */
|
||||
private final String name;
|
||||
|
||||
private AnnotationContext( String _name ) {
|
||||
this.name = _name;
|
||||
}
|
||||
|
||||
public String toString() { return name; }
|
||||
|
||||
|
||||
|
||||
public static final AnnotationContext SCHEMA
|
||||
= new AnnotationContext("schema");
|
||||
public static final AnnotationContext NOTATION
|
||||
= new AnnotationContext("notation");
|
||||
public static final AnnotationContext ELEMENT_DECL
|
||||
= new AnnotationContext("element");
|
||||
public static final AnnotationContext IDENTITY_CONSTRAINT
|
||||
= new AnnotationContext("identityConstraint");
|
||||
public static final AnnotationContext XPATH
|
||||
= new AnnotationContext("xpath");
|
||||
public static final AnnotationContext MODELGROUP_DECL
|
||||
= new AnnotationContext("modelGroupDecl");
|
||||
public static final AnnotationContext SIMPLETYPE_DECL
|
||||
= new AnnotationContext("simpleTypeDecl");
|
||||
public static final AnnotationContext COMPLEXTYPE_DECL
|
||||
= new AnnotationContext("complexTypeDecl");
|
||||
public static final AnnotationContext PARTICLE
|
||||
= new AnnotationContext("particle");
|
||||
public static final AnnotationContext MODELGROUP
|
||||
= new AnnotationContext("modelGroup");
|
||||
public static final AnnotationContext ATTRIBUTE_USE
|
||||
= new AnnotationContext("attributeUse");
|
||||
public static final AnnotationContext WILDCARD
|
||||
= new AnnotationContext("wildcard");
|
||||
public static final AnnotationContext ATTRIBUTE_GROUP
|
||||
= new AnnotationContext("attributeGroup");
|
||||
public static final AnnotationContext ATTRIBUTE_DECL
|
||||
= new AnnotationContext("attributeDecl");
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.parser;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Used to parse <xs:annotation>.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public abstract class AnnotationParser {
|
||||
/**
|
||||
* Called every time a new <xs:annotation> element
|
||||
* is found.
|
||||
*
|
||||
* The sub-tree rooted at <xs:annotation> will be
|
||||
* sent to this ContentHandler as if it is a whole document.
|
||||
*
|
||||
* @param context
|
||||
* indicates the schema component that owns this annotation.
|
||||
* Always non-null.
|
||||
* @param parentElementName
|
||||
* local name of the element that contains <xs:annotation>.
|
||||
* (e.g., "element", "attribute", ... )
|
||||
* @param errorHandler
|
||||
* The error handler that the client application specifies.
|
||||
* The returned content handler can send its errors to this
|
||||
* object.
|
||||
* @param entityResolver
|
||||
* The entity resolver that is currently in use. Again,
|
||||
* The returned content handler can use this object
|
||||
* if it needs to resolve entities.
|
||||
*/
|
||||
public abstract ContentHandler getContentHandler(
|
||||
AnnotationContext context,
|
||||
String parentElementName,
|
||||
ErrorHandler errorHandler,
|
||||
EntityResolver entityResolver );
|
||||
|
||||
/**
|
||||
* Once the SAX events are fed to the ContentHandler,
|
||||
* this method will be called to retrieve the parsed result.
|
||||
*
|
||||
* @param existing
|
||||
* An annotation object which was returned from another
|
||||
* AnnotationParser before. Sometimes, one schema component
|
||||
* can have multiple <:xs:annotation> elements and
|
||||
* this parameter is used to merge all those annotations
|
||||
* together. If there is no existing object, null will be
|
||||
* passed.
|
||||
* @return
|
||||
* Any object, including null.
|
||||
*/
|
||||
public abstract Object getResult( Object existing );
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.parser;
|
||||
|
||||
/**
|
||||
* Factory for {@link AnnotationParser}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface AnnotationParserFactory {
|
||||
AnnotationParser create();
|
||||
}
|
||||
183
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/JAXPParser.java
Normal file
183
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/JAXPParser.java
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
|
||||
import com.sun.xml.internal.xsom.impl.parser.Messages;
|
||||
|
||||
/**
|
||||
* Standard XMLParser implemented by using JAXP.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class JAXPParser implements XMLParser {
|
||||
|
||||
// not in older JDK, so must be duplicated here, otherwise javax.xml.XMLConstants should be used
|
||||
private static final String ACCESS_EXTERNAL_SCHEMA = "http://javax.xml.XMLConstants/property/accessExternalSchema";
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(JAXPParser.class.getName());
|
||||
|
||||
private final SAXParserFactory factory;
|
||||
|
||||
public JAXPParser( SAXParserFactory factory ) {
|
||||
factory.setNamespaceAware(true); // just in case
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Unsafe, use JAXPParser(factory) instead with
|
||||
* security features initialized by setting
|
||||
* XMLConstants.FEATURE_SECURE_PROCESSING feature.
|
||||
*/
|
||||
public JAXPParser() {
|
||||
this( SAXParserFactory.newInstance());
|
||||
}
|
||||
|
||||
public void parse( InputSource source, ContentHandler handler,
|
||||
ErrorHandler errorHandler, EntityResolver entityResolver )
|
||||
|
||||
throws SAXException, IOException {
|
||||
|
||||
try {
|
||||
SAXParser saxParser = allowFileAccess(factory.newSAXParser(), false);
|
||||
XMLReader reader = new XMLReaderEx(saxParser.getXMLReader());
|
||||
|
||||
reader.setContentHandler(handler);
|
||||
if(errorHandler!=null)
|
||||
reader.setErrorHandler(errorHandler);
|
||||
if(entityResolver!=null)
|
||||
reader.setEntityResolver(entityResolver);
|
||||
reader.parse(source);
|
||||
} catch( ParserConfigurationException e ) {
|
||||
// in practice this won't happen
|
||||
SAXParseException spe = new SAXParseException(e.getMessage(),null,e);
|
||||
errorHandler.fatalError(spe);
|
||||
throw spe;
|
||||
}
|
||||
}
|
||||
|
||||
private static SAXParser allowFileAccess(SAXParser saxParser, boolean disableSecureProcessing) throws SAXException {
|
||||
|
||||
// if feature secure processing enabled, nothing to do, file is allowed,
|
||||
// or user is able to control access by standard JAXP mechanisms
|
||||
if (disableSecureProcessing) {
|
||||
return saxParser;
|
||||
}
|
||||
|
||||
try {
|
||||
saxParser.setProperty(ACCESS_EXTERNAL_SCHEMA, "file");
|
||||
LOGGER.log(Level.FINE, Messages.format(Messages.JAXP_SUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA));
|
||||
} catch (SAXException ignored) {
|
||||
// nothing to do; support depends on version JDK or SAX implementation
|
||||
LOGGER.log(Level.CONFIG, Messages.format(Messages.JAXP_UNSUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA), ignored);
|
||||
}
|
||||
return saxParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* XMLReader with improved error message for entity resolution failure.
|
||||
*
|
||||
* TODO: this class is completely stand-alone, so it shouldn't be
|
||||
* an inner class.
|
||||
*/
|
||||
private static class XMLReaderEx extends XMLFilterImpl {
|
||||
|
||||
private Locator locator;
|
||||
|
||||
XMLReaderEx( XMLReader parent ) {
|
||||
this.setParent(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves entities and reports user-friendly error messages.
|
||||
*
|
||||
* <p>
|
||||
* Some XML parser (at least Xerces) does not report much information
|
||||
* when it fails to resolve an entity, which is often quite
|
||||
* frustrating. For example, if you are behind a firewall and the
|
||||
* schema contains a reference to www.w3.org, and there is no
|
||||
* entity resolver, the parser will just throw an IOException
|
||||
* that doesn't contain any information about where that reference
|
||||
* occurs nor what it is accessing.
|
||||
*
|
||||
* <p>
|
||||
* By implementing an EntityResolver and resolving the reference
|
||||
* by ourselves, we can report an error message with all the
|
||||
* necessary information to fix the problem.
|
||||
*
|
||||
* <p>
|
||||
* Note that we still need to the client-specified entity resolver
|
||||
* to let the application handle entity resolution. Here we just catch
|
||||
* an IOException and add more information.
|
||||
*/
|
||||
@Override
|
||||
public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
|
||||
try {
|
||||
InputSource is=null;
|
||||
|
||||
// ask the client-specified entity resolver first
|
||||
if( this.getEntityResolver()!=null)
|
||||
is = this.getEntityResolver().resolveEntity(publicId,systemId);
|
||||
if( is!=null ) return is; // if that succeeds, fine.
|
||||
|
||||
// rather than returning null, resolve it now
|
||||
// so that we can detect errors.
|
||||
is = new InputSource( new URL(systemId).openStream() );
|
||||
is.setSystemId(systemId);
|
||||
is.setPublicId(publicId);
|
||||
return is;
|
||||
} catch( IOException e ) {
|
||||
// catch this error and provide a nice error message, rather than
|
||||
// just throwing this IOException.
|
||||
SAXParseException spe = new SAXParseException(
|
||||
Messages.format(Messages.ERR_ENTITY_RESOLUTION_FAILURE,
|
||||
systemId, e.toString()), // use the toString method to get the class name
|
||||
locator, e );
|
||||
if(this.getErrorHandler()!=null)
|
||||
this.getErrorHandler().fatalError(spe);
|
||||
throw spe;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDocumentLocator(Locator locator) {
|
||||
super.setDocumentLocator(locator);
|
||||
this.locator = locator;
|
||||
}
|
||||
}
|
||||
}
|
||||
142
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/SchemaDocument.java
Normal file
142
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/SchemaDocument.java
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.parser;
|
||||
|
||||
import com.sun.xml.internal.xsom.XSSchema;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents a parsed XML schema document.
|
||||
*
|
||||
* <p>
|
||||
* Unlike schema components defined in <tt>XS****</tt> interfaces,
|
||||
* which are inherently de-coupled from where it was loaded from,
|
||||
* {@link SchemaDocument} represents a single XML infoset that
|
||||
* is a schema document.
|
||||
*
|
||||
* <p>
|
||||
* This concept is often useful in tracking down the reference
|
||||
* relationship among schema documents.
|
||||
*
|
||||
* @see XSOMParser#getDocuments()
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface SchemaDocument {
|
||||
/**
|
||||
* Gets the system ID of the schema document.
|
||||
*
|
||||
* @return
|
||||
* null if {@link XSOMParser} was not given the system Id.
|
||||
*/
|
||||
String getSystemId();
|
||||
|
||||
/**
|
||||
* The namespace that this schema defines.
|
||||
*
|
||||
* <p>
|
||||
* More precisely, this method simply returns the <tt>targetNamespace</tt> attribute
|
||||
* of the schema document. When schemas are referenced in certain ways
|
||||
* (AKA chameleon schema), schema components in this schema document
|
||||
* may end up defining components in other namespaces.
|
||||
*
|
||||
* @return
|
||||
* can be "" but never null.
|
||||
*/
|
||||
String getTargetNamespace();
|
||||
|
||||
/**
|
||||
* Gets {@link XSSchema} component that contains all the schema
|
||||
* components defined in this namespace.
|
||||
*
|
||||
* <p>
|
||||
* The returned {@link XSSchema} contains not just components
|
||||
* defined in this {@link SchemaDocument} but all the other components
|
||||
* defined in all the schemas that collectively define this namespace.
|
||||
*
|
||||
* @return
|
||||
* never null.
|
||||
*/
|
||||
XSSchema getSchema();
|
||||
|
||||
/**
|
||||
* Set of {@link SchemaDocument}s that are included/imported from this document.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null. read-only.
|
||||
*/
|
||||
Set<SchemaDocument> getReferencedDocuments();
|
||||
|
||||
/**
|
||||
* Gets the {@link SchemaDocument}s that are included from this document.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null. read-only.
|
||||
* this set is always a subset of {@link #getReferencedDocuments()}.
|
||||
*/
|
||||
Set<SchemaDocument> getIncludedDocuments();
|
||||
|
||||
/**
|
||||
* Gets the {@link SchemaDocument}s that are imported from this document.
|
||||
*
|
||||
* @param targetNamespace
|
||||
* The namespace URI of the import that you want to
|
||||
* get {@link SchemaDocument}s for.
|
||||
* @return
|
||||
* can be empty but never null. read-only.
|
||||
* this set is always a subset of {@link #getReferencedDocuments()}.
|
||||
*/
|
||||
Set<SchemaDocument> getImportedDocuments(String targetNamespace);
|
||||
|
||||
/**
|
||||
* Returns true if this document includes the given document.
|
||||
*
|
||||
* <p>
|
||||
* Note that this method returns false if this document
|
||||
* imports the given document.
|
||||
*/
|
||||
boolean includes(SchemaDocument doc);
|
||||
|
||||
/**
|
||||
* Returns true if this document imports the given document.
|
||||
*
|
||||
* <p>
|
||||
* Note that this method returns false if this document
|
||||
* includes the given document.
|
||||
*/
|
||||
boolean imports(SchemaDocument doc);
|
||||
|
||||
/**
|
||||
* Set of {@link SchemaDocument}s that include/import this document.
|
||||
*
|
||||
* <p>
|
||||
* This works as the opposite of {@link #getReferencedDocuments()}.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null. read-only.
|
||||
*/
|
||||
Set<SchemaDocument> getReferers();
|
||||
}
|
||||
67
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/XMLParser.java
Normal file
67
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/XMLParser.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Interface that hides the detail of parsing mechanism.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface XMLParser {
|
||||
/**
|
||||
* Parses the document identified by the given input source
|
||||
* and sends SAX events to the given content handler.
|
||||
*
|
||||
* <p>
|
||||
* This method must be re-entrant.
|
||||
*
|
||||
* @param errorHandler
|
||||
* Errors found during the parsing must be reported to
|
||||
* this handler so that XSOM can recognize that something went wrong.
|
||||
* Always a non-null valid object
|
||||
* @param entityResolver
|
||||
* Entity resolution should be done through this interface.
|
||||
* Can be null.
|
||||
*
|
||||
* @exception SAXException
|
||||
* If ErrorHandler throws a SAXException, this method
|
||||
* will tunnel it to the caller. All the other errors
|
||||
* must be reported to the error handler.
|
||||
*/
|
||||
void parse( InputSource source, ContentHandler handler,
|
||||
ErrorHandler errorHandler, EntityResolver entityResolver )
|
||||
|
||||
throws SAXException, IOException;
|
||||
}
|
||||
271
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/XSOMParser.java
Normal file
271
jdkSrc/jdk8/com/sun/xml/internal/xsom/parser/XSOMParser.java
Normal file
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.xsom.parser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.sun.xml.internal.xsom.XSSchemaSet;
|
||||
import com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx;
|
||||
import com.sun.xml.internal.xsom.impl.parser.ParserContext;
|
||||
import com.sun.xml.internal.xsom.impl.parser.state.Schema;
|
||||
|
||||
/**
|
||||
* Parses possibly multiple W3C XML Schema files and compose
|
||||
* them into one grammar.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class XSOMParser {
|
||||
|
||||
private EntityResolver entityResolver;
|
||||
private ErrorHandler userErrorHandler;
|
||||
|
||||
private AnnotationParserFactory apFactory;
|
||||
|
||||
private final ParserContext context;
|
||||
|
||||
/**
|
||||
* Creates a new XSOMParser by using a SAX parser from JAXP.
|
||||
* @deprecated Unsafe, use XSOMParser(factory) instead with
|
||||
* security features initialized by setting
|
||||
* XMLConstants.FEATURE_SECURE_PROCESSING feature.
|
||||
*/
|
||||
public XSOMParser() {
|
||||
this(new JAXPParser());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new XSOMParser that uses the given SAXParserFactory
|
||||
* for creating new SAX parsers.
|
||||
*
|
||||
* The caller needs to configure
|
||||
* it properly. Don't forget to call <code>setNamespaceAware(true)</code>
|
||||
* or you'll see some strange errors.
|
||||
*/
|
||||
public XSOMParser( SAXParserFactory factory ) {
|
||||
this( new JAXPParser(factory) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new XSOMParser that reads XML Schema from non-standard
|
||||
* inputs.
|
||||
*
|
||||
* By implementing the {@link XMLParser} interface, XML Schema
|
||||
* can be read from something other than XML.
|
||||
*
|
||||
* @param parser
|
||||
* This parser will be called to parse XML Schema documents.
|
||||
*/
|
||||
public XSOMParser(XMLParser parser) {
|
||||
context = new ParserContext(this,parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a new XML Schema document.
|
||||
*
|
||||
* <p>
|
||||
* When using this method, XSOM does not know the system ID of
|
||||
* this document, therefore, when this stream contains relative
|
||||
* references to other schemas, XSOM will fail to resolve them.
|
||||
* To specify an system ID with a stream, use {@link InputSource}
|
||||
*/
|
||||
public void parse( InputStream is ) throws SAXException {
|
||||
parse(new InputSource(is));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a new XML Schema document.
|
||||
*
|
||||
* <p>
|
||||
* When using this method, XSOM does not know the system ID of
|
||||
* this document, therefore, when this reader contains relative
|
||||
* references to other schemas, XSOM will fail to resolve them.
|
||||
* To specify an system ID with a reader, use {@link InputSource}
|
||||
*/
|
||||
public void parse( Reader reader ) throws SAXException {
|
||||
parse(new InputSource(reader));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a new XML Schema document.
|
||||
*/
|
||||
public void parse( File schema ) throws SAXException, IOException {
|
||||
parse(schema.toURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a new XML Schema document.
|
||||
*/
|
||||
public void parse( URL url ) throws SAXException {
|
||||
parse( url.toExternalForm() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a new XML Schema document.
|
||||
*/
|
||||
public void parse( String systemId ) throws SAXException {
|
||||
parse(new InputSource(systemId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a new XML Schema document.
|
||||
*
|
||||
* <p>
|
||||
* Note that if the {@link InputSource} does not have a system ID,
|
||||
* XSOM will fail to resolve them.
|
||||
*/
|
||||
public void parse( InputSource source ) throws SAXException {
|
||||
context.parse(source);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the parser implemented as a ContentHandler.
|
||||
*
|
||||
* One can feed XML Schema as SAX events to this interface to
|
||||
* parse a schema. To parse multiple schema files, feed multiple
|
||||
* sets of events.
|
||||
*
|
||||
* <p>
|
||||
* If you don't send a complete event sequence from a startDocument
|
||||
* event to an endDocument event, the state of XSOMParser can become
|
||||
* unstable. This sometimes happen when you encounter an error while
|
||||
* generating SAX events. Don't call the getResult method in that case.
|
||||
*
|
||||
* <p>
|
||||
* This way of reading XML Schema can be useful when XML Schema is
|
||||
* not available as a stand-alone XML document.
|
||||
* For example, one can feed XML Schema inside a WSDL document.
|
||||
*/
|
||||
public ContentHandler getParserHandler() {
|
||||
NGCCRuntimeEx runtime = context.newNGCCRuntime();
|
||||
Schema s = new Schema(runtime,false,null);
|
||||
runtime.setRootHandler(s);
|
||||
return runtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parsed result. Don't call this method until
|
||||
* you parse all the schemas.
|
||||
*
|
||||
* @return
|
||||
* If there was any parse error, this method returns null.
|
||||
* To receive error information, specify your error handler
|
||||
* through the setErrorHandler method.
|
||||
* @exception SAXException
|
||||
* This exception will never be thrown unless it is thrown
|
||||
* by an error handler.
|
||||
*/
|
||||
public XSSchemaSet getResult() throws SAXException {
|
||||
return context.getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set of {@link SchemaDocument} that represents
|
||||
* parsed documents so far.
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null.
|
||||
*/
|
||||
public Set<SchemaDocument> getDocuments() {
|
||||
return new HashSet<SchemaDocument>(context.parsedDocuments.keySet());
|
||||
}
|
||||
|
||||
public EntityResolver getEntityResolver() {
|
||||
return entityResolver;
|
||||
}
|
||||
/**
|
||||
* Set an entity resolver that is used to resolve things
|
||||
* like <xsd:import> and <xsd:include>.
|
||||
*/
|
||||
public void setEntityResolver( EntityResolver resolver ) {
|
||||
this.entityResolver = resolver;
|
||||
}
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return userErrorHandler;
|
||||
}
|
||||
/**
|
||||
* Set an error handler that receives all the errors encountered
|
||||
* during the parsing.
|
||||
*/
|
||||
public void setErrorHandler(ErrorHandler errorHandler) {
|
||||
this.userErrorHandler = errorHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the annotation parser.
|
||||
*
|
||||
* Annotation parser can be used to parse application-specific
|
||||
* annotations inside a schema.
|
||||
*
|
||||
* <p>
|
||||
* For each annotation, new instance of this class will be
|
||||
* created and used to parse <xs:annotation>.
|
||||
*/
|
||||
public void setAnnotationParser( final Class annParser ) {
|
||||
setAnnotationParser( new AnnotationParserFactory() {
|
||||
public AnnotationParser create() {
|
||||
try {
|
||||
return (AnnotationParser)annParser.newInstance();
|
||||
} catch( InstantiationException e ) {
|
||||
throw new InstantiationError(e.getMessage());
|
||||
} catch( IllegalAccessException e ) {
|
||||
throw new IllegalAccessError(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the annotation parser factory.
|
||||
*
|
||||
* <p>
|
||||
* The specified factory will be used to create AnnotationParsers.
|
||||
*/
|
||||
public void setAnnotationParser( AnnotationParserFactory factory ) {
|
||||
this.apFactory = factory;
|
||||
}
|
||||
|
||||
public AnnotationParserFactory getAnnotationParserFactory() {
|
||||
return apFactory;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user