From commits-return-12215-archive-asf-public=cust-asf.ponee.io@poi.apache.org Fri Apr 5 21:49:04 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 6B7CA18060F for ; Fri, 5 Apr 2019 23:49:03 +0200 (CEST) Received: (qmail 394 invoked by uid 500); 5 Apr 2019 21:49:02 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 381 invoked by uid 99); 5 Apr 2019 21:49:02 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Apr 2019 21:49:02 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id AE94B3A01BF for ; Fri, 5 Apr 2019 21:49:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1857035 - /xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java Date: Fri, 05 Apr 2019 21:49:01 -0000 To: commits@poi.apache.org From: kiwiwings@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190405214901.AE94B3A01BF@svn01-us-west.apache.org> Author: kiwiwings Date: Fri Apr 5 21:49:01 2019 New Revision: 1857035 URL: http://svn.apache.org/viewvc?rev=1857035&view=rev Log: (XMLBEANS-536) - remove reflections in XmlBeans Modified: xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java Modified: xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java?rev=1857035&r1=1857034&r2=1857035&view=diff ============================================================================== --- xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java (original) +++ xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java Fri Apr 5 21:49:01 2019 @@ -15,17 +15,18 @@ package org.apache.xmlbeans; -import javax.xml.namespace.QName; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Constructor; -import java.lang.ref.SoftReference; -import java.io.File; +import org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem; +import org.apache.xmlbeans.impl.schema.PathResourceLoader; +import org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl; +import org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler; +import org.apache.xmlbeans.impl.store.Locale; +import org.w3c.dom.Node; +import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamReader; - -import org.w3c.dom.Node; +import java.io.File; +import java.lang.ref.SoftReference; +import java.lang.reflect.Field; /** * Provides an assortment of utilities @@ -34,6 +35,9 @@ import org.w3c.dom.Node; */ public final class XmlBeans { + private static final String HOLDER_CLASS_NAME = "TypeSystemHolder"; + private static final String TYPE_SYSTEM_FIELD = "typeSystem"; + private static String XMLBEANS_TITLE = "org.apache.xmlbeans"; private static String XMLBEANS_VERSION = "3.0.3"; private static String XMLBEANS_VENDOR = "Apache Software Foundation"; @@ -127,17 +131,6 @@ public final class XmlBeans return getQNameCache().getName( namespaceUri, localPart ); } - private static final Method _getContextTypeLoaderMethod = buildGetContextTypeLoaderMethod(); - private static final Method _getBuiltinSchemaTypeSystemMethod = buildGetBuiltinSchemaTypeSystemMethod(); - private static final Method _getNoTypeMethod = buildGetNoTypeMethod(); - private static final Method _typeLoaderBuilderMethod = buildTypeLoaderBuilderMethod(); - private static final Method _compilationMethod = buildCompilationMethod(); - private static final Method _nodeToCursorMethod = buildNodeToCursorMethod(); - private static final Method _nodeToXmlObjectMethod = buildNodeToXmlObjectMethod(); - private static final Method _nodeToXmlStreamMethod = buildNodeToXmlStreamMethod(); - private static final Method _streamToNodeMethod = buildStreamToNodeMethod(); - private static final Constructor _pathResourceLoaderConstructor = buildPathResourceLoaderConstructor(); - private static RuntimeException causedException ( RuntimeException e, Throwable cause ) { e.initCause( cause ); @@ -145,123 +138,6 @@ public final class XmlBeans return e; } - private static XmlException wrappedException(Throwable e) - { - if (e instanceof XmlException) - return (XmlException) e; - - return new XmlException( e.getMessage(), e ); - } - - private static final Constructor buildConstructor ( String className, Class[] args ) - { - try - { - return - Class.forName( - className, false, XmlBeans.class.getClassLoader() ). - getConstructor( args ); - } - catch ( Exception e ) - { - throw causedException( - new IllegalStateException( - "Cannot load constructor for " + className + - ": verify that xbean.jar is on the classpath" ), e ); - } - } - - private static final Method buildMethod ( String className, String methodName, Class[] args ) - { - try - { - return - Class.forName( - className, false, XmlBeans.class.getClassLoader() ). - getMethod( methodName, args ); - } - catch ( Exception e ) - { - throw causedException( - new IllegalStateException( - "Cannot load " + methodName + - ": verify that xbean.jar is on the classpath" ), e ); - } - } - - private static final Method buildNoArgMethod ( String className, String methodName ) - { - return buildMethod( className, methodName, new Class[ 0 ] ); - } - - private static final Method buildNodeMethod ( String className, String methodName ) - { - return buildMethod( className, methodName, new Class[] { Node.class } ); - } - - private static Method buildGetContextTypeLoaderMethod() - { - return buildNoArgMethod( "org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl", "getContextTypeLoader" ); - } - - - private static final Method buildGetBuiltinSchemaTypeSystemMethod() - { - return buildNoArgMethod( "org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem", "get" ); - } - - private static final Method buildGetNoTypeMethod() - { - return buildNoArgMethod( "org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem", "getNoType" ); - } - - private static final Method buildTypeLoaderBuilderMethod ( ) - { - return - buildMethod( - "org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl", "build", - new Class[] { SchemaTypeLoader[].class, ResourceLoader.class, ClassLoader.class } ); - } - - private static final Method buildCompilationMethod() - { - return - buildMethod( - "org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler", "compile", - new Class[] { String.class, SchemaTypeSystem.class, XmlObject[].class, BindingConfig.class, SchemaTypeLoader.class, Filer.class, XmlOptions.class } ); - } - - private static final Method buildNodeToCursorMethod() - { - return buildNodeMethod( "org.apache.xmlbeans.impl.store.Locale", "nodeToCursor" ); - } - - private static final Method buildNodeToXmlObjectMethod() - { - return buildNodeMethod( "org.apache.xmlbeans.impl.store.Locale", "nodeToXmlObject" ); - } - - private static final Method buildNodeToXmlStreamMethod() - { - return buildNodeMethod( "org.apache.xmlbeans.impl.store.Locale", "nodeToXmlStream" ); - } - - private static final Method buildStreamToNodeMethod() - { - return - buildMethod( - "org.apache.xmlbeans.impl.store.Locale", "streamToNode", - new Class[] { XMLStreamReader.class } ); - } - - private static final Constructor buildPathResourceLoaderConstructor() - { - return - buildConstructor( - "org.apache.xmlbeans.impl.schema.PathResourceLoader", - new Class[] { File[].class } ); - } - /** * Compiles an XPath, returning a String equal to that which was passed, * but whose identity is that of one which has been precompiled and cached. @@ -324,142 +200,44 @@ public final class XmlBeans * The "parse" methods of XmlBeans all delegate to the * "parseInstance" methods of the context type loader. */ - public static SchemaTypeLoader getContextTypeLoader() - { - try - { - return (SchemaTypeLoader)_getContextTypeLoaderMethod.invoke(null); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to SchemaTypeLoaderImpl.getContextTypeLoader(): verify that version of xbean.jar is correct"), e); - } - catch (InvocationTargetException e) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static SchemaTypeLoader getContextTypeLoader() { + return SchemaTypeLoaderImpl.getContextTypeLoader(); } /** * Returns the builtin type system. This SchemaTypeSystem contains * only the 46 builtin types defined by the XML Schema specification. */ - public static SchemaTypeSystem getBuiltinTypeSystem() - { - try - { - return (SchemaTypeSystem)_getBuiltinSchemaTypeSystemMethod.invoke(null); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to BuiltinSchemaTypeSystem.get(): verify that version of xbean.jar is correct"), e); - } - catch (InvocationTargetException e) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static SchemaTypeSystem getBuiltinTypeSystem() { + return BuiltinSchemaTypeSystem.get(); } /** * Creates an XmlCursor for a DOM node which is implemented by XmlBwans */ - public static XmlCursor nodeToCursor ( Node n ) - { - try - { - return (XmlCursor) _nodeToCursorMethod.invoke( null, new Object[] { n } ); - } - catch ( IllegalAccessException e ) - { - throw causedException( - new IllegalStateException( - "No access to nodeToCursor verify that version of xbean.jar is correct" ), e ); - } - catch ( InvocationTargetException e ) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static XmlCursor nodeToCursor ( Node n ) { + return Locale.nodeToCursor(n); } /** * Creates an XmlObject for a DOM node which is implemented by XmlBwans */ - public static XmlObject nodeToXmlObject ( Node n ) - { - try - { - return (XmlObject) _nodeToXmlObjectMethod.invoke( null, new Object[] { n } ); - } - catch ( IllegalAccessException e ) - { - throw causedException( - new IllegalStateException( - "No access to nodeToXmlObject verify that version of xbean.jar is correct" ), e ); - } - catch ( InvocationTargetException e ) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static XmlObject nodeToXmlObject ( Node n ) { + return Locale.nodeToXmlObject(n); } /** * Creates an XmlObject for a DOM node which is implemented by XmlBwans */ - public static XMLStreamReader nodeToXmlStreamReader ( Node n ) - { - try - { - return (XMLStreamReader) _nodeToXmlStreamMethod.invoke( null, new Object[] { n } ); - } - catch ( IllegalAccessException e ) - { - throw causedException( - new IllegalStateException( - "No access to nodeToXmlStreamReader verify that version of xbean.jar is correct" ), e ); - } - catch ( InvocationTargetException e ) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static XMLStreamReader nodeToXmlStreamReader ( Node n ) { + return Locale.nodeToXmlStream(n); } /** * Returns the XmlObject for a DOM node which is implemented by XmlBwans */ - public static Node streamToNode ( XMLStreamReader xs ) - { - try - { - return (Node) _streamToNodeMethod.invoke( null, new Object[] { xs } ); - } - catch ( IllegalAccessException e ) - { - throw causedException( - new IllegalStateException( - "No access to streamToNode verify that version of xbean.jar is correct" ), e ); - } - catch ( InvocationTargetException e ) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static Node streamToNode ( XMLStreamReader xs ) { + return Locale.streamToNode(xs); } /** @@ -495,32 +273,12 @@ public final class XmlBeans * @param schemas The schema definitions from which to build the schema type system. * @param options Options specifying an error listener and/or validation behavior. */ - public static SchemaTypeLoader loadXsd(XmlObject[] schemas, XmlOptions options) throws XmlException - { - try - { - SchemaTypeSystem sts = - (SchemaTypeSystem) - _compilationMethod.invoke( - null, new Object[] { null, null, schemas, null, getContextTypeLoader(), null, options }); - - if (sts == null) - return null; - - return - typeLoaderUnion( - new SchemaTypeLoader[] { sts, getContextTypeLoader() } ); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to SchemaTypeLoaderImpl.forSchemaXml(): verify that version of xbean.jar is correct"), e); - } - catch (InvocationTargetException e) - { - throw wrappedException(e.getCause()); - } + public static SchemaTypeLoader loadXsd(XmlObject[] schemas, XmlOptions options) throws XmlException { + SchemaTypeSystem sts = SchemaTypeSystemCompiler.compile(null, null, schemas, null, getContextTypeLoader(), null, options); + return (sts == null) ? null : typeLoaderUnion(sts, getContextTypeLoader()); } + /** *

Returns the SchemaTypeSystem that results from compiling the XML * schema definitions passed.

@@ -664,20 +422,8 @@ public final class XmlBeans * @param filer The Filer instance used to create binary binding files and source text files. * @param options Options specifying an error listener and/or validation behavior. */ - public static SchemaTypeSystem compileXmlBeans(String name, SchemaTypeSystem system, XmlObject[] schemas, BindingConfig config, SchemaTypeLoader typepath, Filer filer, XmlOptions options) throws XmlException - { - try - { - return (SchemaTypeSystem)_compilationMethod.invoke(null, new Object[] { name, system, schemas, config, typepath != null ? typepath : getContextTypeLoader(), filer, options }); - } - catch (IllegalAccessException e) - { - throw new IllegalStateException("No access to SchemaTypeLoaderImpl.forSchemaXml(): verify that version of xbean.jar is correct"); - } - catch (InvocationTargetException e) - { - throw wrappedException(e.getCause()); - } + public static SchemaTypeSystem compileXmlBeans(String name, SchemaTypeSystem system, XmlObject[] schemas, BindingConfig config, SchemaTypeLoader typepath, Filer filer, XmlOptions options) throws XmlException { + return SchemaTypeSystemCompiler.compile(name, system, schemas, config, typepath != null ? typepath : getContextTypeLoader(), filer, options); } @@ -686,49 +432,16 @@ public final class XmlBeans * SchemaTypeLoader searches the given list of SchemaTypeLoaders * in order from first to last. */ - public static SchemaTypeLoader typeLoaderUnion(SchemaTypeLoader[] typeLoaders) - { - try - { - if (typeLoaders.length == 1) - return typeLoaders[0]; - - return (SchemaTypeLoader)_typeLoaderBuilderMethod.invoke(null, new Object[] {typeLoaders, null, null}); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to SchemaTypeLoaderImpl: verify that version of xbean.jar is correct"), e); - } - catch (InvocationTargetException e) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static SchemaTypeLoader typeLoaderUnion(SchemaTypeLoader... typeLoaders) { + return (typeLoaders.length == 1) ? typeLoaders[0] : SchemaTypeLoaderImpl.build(typeLoaders, null, null); } /** * Returns a SchemaTypeLoader that searches for compiled schema types * in the given ClassLoader. */ - public static SchemaTypeLoader typeLoaderForClassLoader(ClassLoader loader) - { - try - { - return (SchemaTypeLoader)_typeLoaderBuilderMethod.invoke(null, new Object[] {null, null, loader}); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to SchemaTypeLoaderImpl: verify that version of xbean.jar is correct"), e); - } - catch (InvocationTargetException e) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static SchemaTypeLoader typeLoaderForClassLoader(ClassLoader loader) { + return SchemaTypeLoaderImpl.build(null, null, loader); } /** @@ -737,28 +450,10 @@ public final class XmlBeans * * @see XmlBeans#resourceLoaderForPath(File[]) */ - public static SchemaTypeLoader typeLoaderForResource(ResourceLoader resourceLoader) - { - try - { - return (SchemaTypeLoader)_typeLoaderBuilderMethod.invoke(null, new Object[] {null, resourceLoader, null}); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to SchemaTypeLoaderImpl: verify that version of xbean.jar is correct"), e); - } - catch (InvocationTargetException e) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static SchemaTypeLoader typeLoaderForResource(ResourceLoader resourceLoader) { + return SchemaTypeLoaderImpl.build(null, resourceLoader, null); } - private static final String HOLDER_CLASS_NAME = "TypeSystemHolder"; - private static final String TYPE_SYSTEM_FIELD = "typeSystem"; - /** * Returns the SchemaTypeSystem of the given name (as returned by * {@link SchemaTypeSystem#getName}) for the given ClassLoader. @@ -807,27 +502,8 @@ public final class XmlBeans * Returns a new ResourceLoader for a search path where each component of * the path is either a directory or a compiled xbean jar. */ - public static ResourceLoader resourceLoaderForPath(File[] path) - { - try - { - return (ResourceLoader)_pathResourceLoaderConstructor.newInstance(new Object[] {path}); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to SchemaTypeLoaderImpl: verify that version of xbean.jar is correct"), e); - } - catch (InstantiationException e) - { - throw causedException(new IllegalStateException(e.getMessage()), e); - } - catch (InvocationTargetException e) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + public static ResourceLoader resourceLoaderForPath(File[] path) { + return new PathResourceLoader(path); } /** @@ -854,23 +530,8 @@ public final class XmlBeans } } - private static SchemaType getNoType() - { - try - { - return (SchemaType)_getNoTypeMethod.invoke(null); - } - catch (IllegalAccessException e) - { - throw causedException(new IllegalStateException("No access to SchemaTypeLoaderImpl.getContextTypeLoader(): verify that version of xbean.jar is correct"), e); - } - catch (InvocationTargetException e) - { - Throwable t = e.getCause(); - IllegalStateException ise = new IllegalStateException(t.getMessage()); - ise.initCause(t); // use initCause() to support Java 1.4 - throw ise; - } + private static SchemaType getNoType() { + return org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem.getNoType(); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org