elena 2003/11/14 11:35:53 Modified: java/src/org/apache/xerces/dom DOMImplementationSourceImpl.java PSVIDOMImplementationImpl.java java/src/org/apache/xerces/impl/xs XMLSchemaLoader.java Added: java/src/org/apache/xerces/impl/xs XSImplementationImpl.java Log: Add implemenation of xs.XSLoader and xs.XSImplementation. Revision Changes Path 1.12 +28 -16 xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java Index: DOMImplementationSourceImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- DOMImplementationSourceImpl.java 13 Nov 2003 22:47:15 -0000 1.11 +++ DOMImplementationSourceImpl.java 14 Nov 2003 19:35:53 -0000 1.12 @@ -62,6 +62,7 @@ import org.apache.xerces.dom3.DOMImplementationList; import org.apache.xerces.dom3.DOMImplementationSource; import org.apache.xerces.dom3.bootstrap.DOMImplementationListImpl; +import org.apache.xerces.impl.xs.XSImplementationImpl; import org.w3c.dom.DOMImplementation; /** @@ -102,6 +103,12 @@ if (testImpl(impl, features)) { return impl; } + // if not try the XSImplementation + impl = XSImplementationImpl.getDOMImplementation(); + if (testImpl(impl, features)) { + return impl; + } + return null; } @@ -119,22 +126,27 @@ * features. */ public DOMImplementationList getDOMImplementationList(String features) { - // first check whether the CoreDOMImplementation would do - DOMImplementation impl = CoreDOMImplementationImpl.getDOMImplementation(); + // first check whether the CoreDOMImplementation would do + DOMImplementation impl = CoreDOMImplementationImpl.getDOMImplementation(); DOMImplementationListImpl list = new DOMImplementationListImpl(); - if (testImpl(impl, features)) { - list.add(impl); - } - impl = DOMImplementationImpl.getDOMImplementation(); - if (testImpl(impl, features)) { - list.add(impl); - } - impl = PSVIDOMImplementationImpl.getDOMImplementation(); - if (testImpl(impl, features)) { - list.add(impl); - } - return list; - } + if (testImpl(impl, features)) { + list.add(impl); + } + impl = DOMImplementationImpl.getDOMImplementation(); + if (testImpl(impl, features)) { + list.add(impl); + } + impl = PSVIDOMImplementationImpl.getDOMImplementation(); + if (testImpl(impl, features)) { + list.add(impl); + } + + impl = XSImplementationImpl.getDOMImplementation(); + if (testImpl(impl, features)) { + list.add(impl); + } + return list; + } boolean testImpl(DOMImplementation impl, String features) { 1.3 +2 -2 xml-xerces/java/src/org/apache/xerces/dom/PSVIDOMImplementationImpl.java Index: PSVIDOMImplementationImpl.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/PSVIDOMImplementationImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PSVIDOMImplementationImpl.java 19 Nov 2002 01:41:36 -0000 1.2 +++ PSVIDOMImplementationImpl.java 14 Nov 2003 19:35:53 -0000 1.3 @@ -116,7 +116,7 @@ */ public boolean hasFeature(String feature, String version) { return super.hasFeature(feature, version) || - feature.equalsIgnoreCase("PSVI"); + feature.equalsIgnoreCase("psvi"); } // hasFeature(String,String):boolean /** 1.20 +327 -36 xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java Index: XMLSchemaLoader.java =================================================================== RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- XMLSchemaLoader.java 7 Nov 2003 00:26:18 -0000 1.19 +++ XMLSchemaLoader.java 14 Nov 2003 19:35:53 -0000 1.20 @@ -57,47 +57,64 @@ package org.apache.xerces.impl.xs; -import org.apache.xerces.xni.parser.XMLComponent; -import org.apache.xerces.xni.parser.XMLComponentManager; -import org.apache.xerces.xni.parser.XMLConfigurationException; -import org.apache.xerces.xni.parser.XMLErrorHandler; -import org.apache.xerces.xni.parser.XMLEntityResolver; -import org.apache.xerces.xni.parser.XMLInputSource; -import org.apache.xerces.xni.XNIException; -import org.apache.xerces.xni.grammars.XMLGrammarLoader; -import org.apache.xerces.xni.grammars.XMLGrammarDescription; -import org.apache.xerces.xni.grammars.XMLGrammarPool; -import org.apache.xerces.xni.grammars.Grammar; -import org.xml.sax.InputSource; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.util.Hashtable; +import java.util.Locale; +import java.util.StringTokenizer; +import java.util.Vector; +import org.apache.xerces.dom.DOMErrorImpl; +import org.apache.xerces.dom.DOMMessageFormatter; +import org.apache.xerces.dom.DOMStringListImpl; +import org.apache.xerces.dom3.DOMConfiguration; +import org.apache.xerces.dom3.DOMError; +import org.apache.xerces.dom3.DOMErrorHandler; +import org.apache.xerces.dom3.DOMStringList; +import org.apache.xerces.impl.Constants; +import org.apache.xerces.impl.XMLEntityManager; import org.apache.xerces.impl.XMLErrorReporter; import org.apache.xerces.impl.dv.InvalidDatatypeValueException; import org.apache.xerces.impl.xs.models.CMBuilder; +import org.apache.xerces.impl.xs.models.CMNodeFactory; import org.apache.xerces.impl.xs.traversers.XSDHandler; -import org.apache.xerces.impl.Constants; -import org.apache.xerces.impl.XMLEntityManager; +import org.apache.xerces.util.DOMErrorHandlerWrapper; +import org.apache.xerces.util.DefaultErrorHandler; import org.apache.xerces.util.SymbolTable; import org.apache.xerces.util.XMLSymbols; -import org.apache.xerces.util.DefaultErrorHandler; - -import java.util.Locale; -import java.util.Hashtable; -import java.util.StringTokenizer; -import java.io.IOException; -import java.io.Reader; -import java.io.InputStream; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.Vector; -import org.apache.xerces.impl.xs.models.CMNodeFactory; +import org.apache.xerces.xni.XNIException; +import org.apache.xerces.xni.grammars.Grammar; +import org.apache.xerces.xni.grammars.XMLGrammarDescription; +import org.apache.xerces.xni.grammars.XMLGrammarLoader; +import org.apache.xerces.xni.grammars.XMLGrammarPool; +import org.apache.xerces.xni.grammars.XSGrammar; +import org.apache.xerces.xni.parser.XMLComponent; +import org.apache.xerces.xni.parser.XMLComponentManager; +import org.apache.xerces.xni.parser.XMLConfigurationException; +import org.apache.xerces.xni.parser.XMLEntityResolver; +import org.apache.xerces.xni.parser.XMLErrorHandler; +import org.apache.xerces.xni.parser.XMLInputSource; +import org.apache.xerces.xs.DOMInputList; +import org.apache.xerces.xs.StringList; +import org.apache.xerces.xs.XSLoader; +import org.apache.xerces.xs.XSModel; +import org.w3c.dom.DOMException; +import org.w3c.dom.ls.DOMInput; +import org.xml.sax.InputSource; /** - * This class implements XMLGrammarLoader. It is designed to interact - * either with a proxy for a user application which wants to preparse schemas, - * or with our own Schema validator. It is hoped that none of these "external" - * classes will therefore need to communicate directly + * This class implements xni.grammars.XMLGrammarLoader. + * It also serves as implementation of xs.XSLoader interface and DOMConfiguration interface. + * + * This class is designed to interact either with a proxy for a user application + * which wants to preparse schemas, or with our own Schema validator. + * It is hoped that none of these "external" classes will therefore need to communicate directly * with XSDHandler in future. * <p>This class only knows how to make XSDHandler do its thing. * The caller must ensure that all its properties (schemaLocation, JAXPSchemaSource @@ -107,7 +124,9 @@ * @version $Id$ */ -public class XMLSchemaLoader implements XMLGrammarLoader, XMLComponent { +public class XMLSchemaLoader implements XMLGrammarLoader, XMLComponent, + // XML Component API + XSLoader, DOMConfiguration { // Feature identifiers: @@ -210,6 +229,10 @@ private CMBuilder fCMBuilder; // boolean that tells whether we've tested the JAXP property. private boolean fJAXPProcessed = false; + + private DOMStringList fRecognizedParameters = null; + /** DOM L3 error handler */ + private DOMErrorHandlerWrapper fErrorHandler = null; // containers @@ -978,8 +1001,276 @@ } } } - - + + + /* (non-Javadoc) + * @see org.apache.xerces.xs.XSLoader#getConfig() + */ + public DOMConfiguration getConfig() { + return this; + } + + /* (non-Javadoc) + * @see org.apache.xerces.xs.XSLoader#load(org.w3c.dom.ls.DOMInput) + */ + public XSModel load(DOMInput is) { + try { + Grammar g = loadGrammar(dom2xmlInputSource(is)); + return ((XSGrammar) g).toXSModel(); + } catch (Exception e) { + if (fErrorHandler != null) { + DOMErrorImpl error = new DOMErrorImpl(); + error.fException = e; + error.fMessage = e.getMessage(); + error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; + fErrorHandler.getErrorHandler().handleError(error); + } + return null; + } + } + + /* (non-Javadoc) + * @see org.apache.xerces.xs.XSLoader#loadInputList(org.apache.xerces.xs.DOMInputList) + */ + public XSModel loadInputList(DOMInputList is) { + int length = is.getLength(); + if (length == 0) { + return null; + } + SchemaGrammar[] gs = new SchemaGrammar[length]; + for (int i = 0; i < length; i++) { + try { + gs[i] = (SchemaGrammar) loadGrammar(dom2xmlInputSource(is.item(i))); + } catch (Exception e) { + if (fErrorHandler != null) { + DOMErrorImpl error = new DOMErrorImpl(); + error.fException = e; + error.fMessage = e.getMessage(); + error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; + fErrorHandler.getErrorHandler().handleError(error); + } + return null; + } + } + return new XSModelImpl(gs); + } + + /* (non-Javadoc) + * @see org.apache.xerces.xs.XSLoader#loadURI(java.lang.String) + */ + public XSModel loadURI(String uri) { + try { + Grammar g = loadGrammar(new XMLInputSource(null, uri, null)); + return ((XSGrammar)g).toXSModel(); + } + catch (Exception e){ + if (fErrorHandler != null) { + DOMErrorImpl error = new DOMErrorImpl(); + error.fException = e; + error.fMessage = e.getMessage(); + error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; + fErrorHandler.getErrorHandler().handleError(error); + } + return null; + } + } + + /* (non-Javadoc) + * @see org.apache.xerces.xs.XSLoader#loadURIList(org.apache.xerces.xs.StringList) + */ + public XSModel loadURIList(StringList uriList) { + int length = uriList.getLength(); + if (length == 0) { + return null; + } + SchemaGrammar[] gs = new SchemaGrammar[length]; + for (int i = 0; i < length; i++) { + try { + gs[i] = + (SchemaGrammar) loadGrammar(new XMLInputSource(null, uriList.item(i), null)); + } catch (Exception e) { + if (fErrorHandler != null) { + DOMErrorImpl error = new DOMErrorImpl(); + error.fException = e; + error.fMessage = e.getMessage(); + error.fSeverity = DOMError.SEVERITY_FATAL_ERROR; + fErrorHandler.getErrorHandler().handleError(error); + } + return null; + } + } + return new XSModelImpl(gs); + } + + /* (non-Javadoc) + * @see org.apache.xerces.dom3.DOMConfiguration#canSetParameter(java.lang.String, java.lang.Object) + */ + public boolean canSetParameter(String name, Object value) { + if(value instanceof Boolean){ + boolean state = ((Boolean)value).booleanValue(); + if (name.equals(Constants.DOM_VALIDATE) || + name.equals(SCHEMA_FULL_CHECKING) || + name.equals(CONTINUE_AFTER_FATAL_ERROR) || + name.equals(ALLOW_JAVA_ENCODINGS) || + name.equals(STANDARD_URI_CONFORMANT_FEATURE)){ + return true; + + } + return false; + } + if (name.equals(Constants.DOM_ERROR_HANDLER)|| + name.equals(SYMBOL_TABLE) || + name.equals(ERROR_REPORTER) || + name.equals(ERROR_HANDLER) || + name.equals(ENTITY_RESOLVER) || + name.equals(XMLGRAMMAR_POOL) || + name.equals(SCHEMA_LOCATION) || + name.equals(SCHEMA_NONS_LOCATION) || + name.equals(JAXP_SCHEMA_SOURCE)){ + return true; + } + return false; + } + + /* (non-Javadoc) + * @see org.apache.xerces.dom3.DOMConfiguration#getParameter(java.lang.String) + */ + public Object getParameter(String name) throws DOMException { + if (name.equals(Constants.DOM_ERROR_HANDLER)){ + if (fErrorHandler != null){ + return fErrorHandler.getErrorHandler(); + } + } + try { + boolean feature = getFeature(name); + return (feature) ? Boolean.TRUE : Boolean.FALSE; + } catch (Exception e) { + Object property; + try { + property = getProperty(name); + return property; + } catch (Exception ex) { + String msg = + DOMMessageFormatter.formatMessage( + DOMMessageFormatter.DOM_DOMAIN, + "FEATURE_NOT_SUPPORTED", + new Object[] { name }); + throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); + } + } + } + + /* (non-Javadoc) + * @see org.apache.xerces.dom3.DOMConfiguration#getParameterNames() + */ + public DOMStringList getParameterNames() { + if (fRecognizedParameters == null){ + Vector v = new Vector(); + v.add("validate"); + v.add(SYMBOL_TABLE); + v.add(ERROR_REPORTER); + v.add(ERROR_HANDLER); + v.add(ENTITY_RESOLVER); + v.add(XMLGRAMMAR_POOL); + v.add(SCHEMA_LOCATION); + v.add(SCHEMA_NONS_LOCATION); + v.add(JAXP_SCHEMA_SOURCE); + v.add(SCHEMA_FULL_CHECKING); + v.add(CONTINUE_AFTER_FATAL_ERROR); + v.add(ALLOW_JAVA_ENCODINGS); + v.add(STANDARD_URI_CONFORMANT_FEATURE); + fRecognizedParameters = new DOMStringListImpl(v); + } + return fRecognizedParameters; + } + + /* (non-Javadoc) + * @see org.apache.xerces.dom3.DOMConfiguration#setParameter(java.lang.String, java.lang.Object) + */ + public void setParameter(String name, Object value) throws DOMException { + if (value instanceof Boolean) { + boolean state = ((Boolean) value).booleanValue(); + if (name.equals("validate") && state) { + return; + } + try { + setFeature(name, state); + } catch (Exception e) { + String msg = + DOMMessageFormatter.formatMessage( + DOMMessageFormatter.DOM_DOMAIN, + "FEATURE_NOT_SUPPORTED", + new Object[] { name }); + throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); + } + return; + } + if (name.equals(Constants.DOM_ERROR_HANDLER)) { + if (value instanceof DOMErrorHandler) { + try { + fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value); + setErrorHandler(fErrorHandler); + } catch (XMLConfigurationException e) { + } + } else { + // REVISIT: type mismatch + String msg = + DOMMessageFormatter.formatMessage( + DOMMessageFormatter.DOM_DOMAIN, + "FEATURE_NOT_SUPPORTED", + new Object[] { name }); + throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); + } + return; + + } + + try { + setProperty(name, value); + } catch (Exception ex) { + + String msg = + DOMMessageFormatter.formatMessage( + DOMMessageFormatter.DOM_DOMAIN, + "FEATURE_NOT_SUPPORTED", + new Object[] { name }); + throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); + + } + + } + + private XMLInputSource dom2xmlInputSource(DOMInput is) { + // need to wrap the DOMInput with an XMLInputSource + XMLInputSource xis = null; + // if there is a string data, use a StringReader + // according to DOM, we need to treat such data as "UTF-16". + if (is.getStringData() != null) { + xis = new XMLInputSource(is.getPublicId(), is.getSystemId(), + is.getBaseURI(), new StringReader(is.getStringData()), + "UTF-16"); + } + // check whether there is a Reader + // according to DOM, we need to treat such reader as "UTF-16". + else if (is.getCharacterStream() != null) { + xis = new XMLInputSource(is.getPublicId(), is.getSystemId(), + is.getBaseURI(), is.getCharacterStream(), + "UTF-16"); + } + // check whether there is an InputStream + else if (is.getByteStream() != null) { + xis = new XMLInputSource(is.getPublicId(), is.getSystemId(), + is.getBaseURI(), is.getByteStream(), + is.getEncoding()); + } + // otherwise, just use the public/system/base Ids + else { + xis = new XMLInputSource(is.getPublicId(), is.getSystemId(), + is.getBaseURI()); + } + + return xis; + } } // XMLGrammarLoader 1.1 xml-xerces/java/src/org/apache/xerces/impl/xs/XSImplementationImpl.java Index: XSImplementationImpl.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 2003, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.xerces.impl.xs; import org.apache.xerces.dom.CoreDOMImplementationImpl; import org.apache.xerces.dom.DOMMessageFormatter; import org.apache.xerces.impl.xs.util.StringListImpl; import org.apache.xerces.xs.StringList; import org.apache.xerces.xs.XSException; import org.apache.xerces.xs.XSImplementation; import org.apache.xerces.xs.XSLoader; import org.w3c.dom.DOMImplementation; /** * Implements XSImplementation interface that allows one to retrieve an instance of <code>XSLoader</code>. * This interface should be implemented on the same object that implements * DOMImplementation. */ public class XSImplementationImpl extends CoreDOMImplementationImpl implements XSImplementation { // // Data // // static /** Dom implementation singleton. */ static XSImplementationImpl singleton = new XSImplementationImpl(); // // Public methods // /** NON-DOM: Obtain and return the single shared object */ public static DOMImplementation getDOMImplementation() { return singleton; } // // DOMImplementation methods // /** * Test if the DOM implementation supports a specific "feature" -- * currently meaning language and level thereof. * * @param feature The package name of the feature to test. * In Level 1, supported values are "HTML" and "XML" (case-insensitive). * At this writing, org.apache.xerces.dom supports only XML. * * @param version The version number of the feature being tested. * This is interpreted as "Version of the DOM API supported for the * specified Feature", and in Level 1 should be "1.0" * * @return true iff this implementation is compatable with the specified * feature and version. */ public boolean hasFeature(String feature, String version) { return (feature.equalsIgnoreCase("XS-Loader") && (version == null || version.equals("1.0")) || super.hasFeature(feature, version)); } // hasFeature(String,String):boolean /* (non-Javadoc) * @see org.apache.xerces.xs.XSImplementation#createXSLoader(org.apache.xerces.xs.StringList) */ public XSLoader createXSLoader(StringList versions) throws XSException { XSLoader loader = new XMLSchemaLoader(); if (versions == null){ return loader; } for (int i=0; i<versions.getLength();i++){ if (!versions.item(i).equals("1.0")){ String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { versions.item(i) }); throw new XSException(XSException.NOT_SUPPORTED_ERR, msg); } } return loader; } /* (non-Javadoc) * @see org.apache.xerces.xs.XSImplementation#getRecognizedVersions() */ public StringList getRecognizedVersions() { StringListImpl list = new StringListImpl(new String[]{"1.0"}, 1); return null; } } // class XSImplementationImpl
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]