[jboss-svn-commits] JBoss Common SVN: r2774 - in jbossxb/tags: 2.0.0.CR8 and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Mar 28 09:19:42 EDT 2008
Author: alex.loubyansky at jboss.com
Date: 2008-03-28 09:19:42 -0400 (Fri, 28 Mar 2008)
New Revision: 2774
Added:
jbossxb/tags/2.0.0.CR8/
jbossxb/tags/2.0.0.CR8/.classpath
jbossxb/tags/2.0.0.CR8/pom.xml
jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java
jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java
Removed:
jbossxb/tags/2.0.0.CR8/.classpath
jbossxb/tags/2.0.0.CR8/pom.xml
jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java
jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java
Log:
[maven-release-plugin] copy for tag 2.0.0.CR8
Copied: jbossxb/tags/2.0.0.CR8 (from rev 2752, jbossxb/trunk)
Deleted: jbossxb/tags/2.0.0.CR8/.classpath
===================================================================
--- jbossxb/trunk/.classpath 2008-03-27 12:41:03 UTC (rev 2752)
+++ jbossxb/tags/2.0.0.CR8/.classpath 2008-03-28 13:19:42 UTC (rev 2774)
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.0.2/activation-1.0.2.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.3.GA/jboss-common-core-2.2.3.GA.jar"/>
- <classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA.jar"/>
- <classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1.jar"/>
- <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA.jar" sourcepath="/M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA-sources.jar"/>
- <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta11/jboss-reflect-2.0.0.Beta11.jar" sourcepath="/M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta11/jboss-reflect-2.0.0.Beta11-sources.jar"/>
- <classpathentry kind="lib" path="src/test/resources"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
Copied: jbossxb/tags/2.0.0.CR8/.classpath (from rev 2772, jbossxb/trunk/.classpath)
===================================================================
--- jbossxb/tags/2.0.0.CR8/.classpath (rev 0)
+++ jbossxb/tags/2.0.0.CR8/.classpath 2008-03-28 13:19:42 UTC (rev 2774)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.0.2/activation-1.0.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.4.GA/jboss-common-core-2.2.4.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.9.1/xercesImpl-2.9.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-log4j/2.0.4.GA/jboss-common-logging-log4j-2.0.4.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA.jar" sourcepath="/M2_REPO/org/jboss/jboss-test/1.0.4.GA/jboss-test-1.0.4.GA-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta11/jboss-reflect-2.0.0.Beta11.jar" sourcepath="/M2_REPO/org/jboss/jboss-reflect/2.0.0.Beta11/jboss-reflect-2.0.0.Beta11-sources.jar"/>
+ <classpathentry kind="lib" path="src/test/resources"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Deleted: jbossxb/tags/2.0.0.CR8/pom.xml
===================================================================
--- jbossxb/trunk/pom.xml 2008-03-27 12:41:03 UTC (rev 2752)
+++ jbossxb/tags/2.0.0.CR8/pom.xml 2008-03-28 13:19:42 UTC (rev 2774)
@@ -1,144 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-parent</artifactId>
- <version>3</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>jbossxb</artifactId>
- <packaging>jar</packaging>
- <version>2.0.0-SNAPSHOT</version>
- <name>JBoss XML Binding</name>
- <url>http://www.jboss.org</url>
- <description>JBoss XML Binding</description>
- <scm>
- <connection>scm:svn:https://svn.jboss.org/repos/common/jbossxb/trunk</connection>
- </scm>
- <build>
- <finalName>jboss-xml-binding</finalName>
- <plugins>
- <plugin>
- <artifactId>maven-release-plugin</artifactId>
- <configuration>
- <!-- The tagBase property is needed during the release process so that the maven release plugin
- will create the release tag in the appropriate location. -->
- <tagBase>https://svn.jboss.org/repos/common/jbossxb/tags</tagBase>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <testFailureIgnore>true</testFailureIgnore>
- <redirectTestOutputToFile>true</redirectTestOutputToFile>
- <includes>
- <include>**/*TestCase.java</include>
- </includes>
- <forkMode>pertest</forkMode> <!-- required to correctly run the PojoServer tests -->
- </configuration>
- </plugin>
- </plugins>
- </build>
- <repositories>
- <repository>
- <id>repository.jboss.org</id>
- <name>JBoss Repository</name>
- <layout>default</layout>
- <url>http://repository.jboss.org/maven2/</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- <repository>
- <id>snapshots.jboss.org</id>
- <name>JBoss Snapshot Repository</name>
- <layout>default</layout>
- <url>http://snapshots.jboss.org/maven2/</url>
- <releases>
- <enabled>false</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </repository>
- </repositories>
-
- <dependencies>
- <dependency>
- <groupId>jboss</groupId>
- <artifactId>jboss-common-logging-spi</artifactId>
- <version>2.0.4.GA</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>jboss</groupId>
- <artifactId>jboss-common-logging-log4j</artifactId>
- <version>2.0.4.GA</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- <version>2.2.3.GA</version>
- <exclusions>
- <exclusion>
- <groupId>jboss</groupId>
- <artifactId>jboss-common-logging-spi</artifactId>
- </exclusion>
- <exclusion>
- <groupId>apache-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- </exclusion>
- <exclusion>
- <groupId>apache-slide</groupId>
- <artifactId>webdavlib</artifactId>
- </exclusion>
- <exclusion>
- <groupId>apache-xerces</groupId>
- <artifactId>xml-apis</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-reflect</artifactId>
- <version>2.0.0.Beta11</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>apache-xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- <version>2.9.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>wutka-dtdparser</groupId>
- <artifactId>dtdparser121</artifactId>
- <version>1.2.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>javax.activation</groupId>
- <artifactId>activation</artifactId>
- <version>1.0.2</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>javax.xml.bind</groupId>
- <artifactId>jaxb-api</artifactId>
- <version>2.1</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-test</artifactId>
- <version>1.0.4.GA</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
Copied: jbossxb/tags/2.0.0.CR8/pom.xml (from rev 2773, jbossxb/trunk/pom.xml)
===================================================================
--- jbossxb/tags/2.0.0.CR8/pom.xml (rev 0)
+++ jbossxb/tags/2.0.0.CR8/pom.xml 2008-03-28 13:19:42 UTC (rev 2774)
@@ -0,0 +1,156 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>3</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jbossxb</artifactId>
+ <packaging>jar</packaging>
+ <version>2.0.0.CR8</version>
+ <name>JBoss XML Binding</name>
+ <url>http://www.jboss.org</url>
+ <description>JBoss XML Binding</description>
+ <scm>
+ <connection>scm:svn:https://svn.jboss.org/repos/common/jbossxb/tags/2.0.0.CR8</connection>
+ </scm>
+ <build>
+ <finalName>jboss-xml-binding</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <!-- The tagBase property is needed during the release process so that the maven release plugin
+ will create the release tag in the appropriate location. -->
+ <tagBase>https://svn.jboss.org/repos/common/jbossxb/tags</tagBase>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testFailureIgnore>true</testFailureIgnore>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <includes>
+ <include>**/*TestCase.java</include>
+ </includes>
+ <forkMode>pertest</forkMode> <!-- required to correctly run the PojoServer tests -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <layout>default</layout>
+ <url>http://repository.jboss.org/maven2/</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshot Repository</name>
+ <layout>default</layout>
+ <url>http://snapshots.jboss.org/maven2/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common-logging-spi</artifactId>
+ <version>2.0.4.GA</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common-logging-log4j</artifactId>
+ <version>2.0.4.GA</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <version>2.2.4.GA</version>
+ <exclusions>
+ <exclusion>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common-logging-spi</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>apache-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>apache-slide</groupId>
+ <artifactId>webdavlib</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>apache-xerces</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ <version>2.0.0.Beta11</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>apache-xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.9.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>wutka-dtdparser</groupId>
+ <artifactId>dtdparser121</artifactId>
+ <version>1.2.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.0.2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>1.0.4.GA</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Deleted: jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java 2008-03-27 12:41:03 UTC (rev 2752)
+++ jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java 2008-03-28 13:19:42 UTC (rev 2774)
@@ -1,504 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.xb.binding.sunday.unmarshalling;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.jboss.logging.Logger;
-import org.jboss.util.xml.JBossEntityResolver;
-import org.jboss.xb.binding.JBossXBRuntimeException;
-import org.jboss.xb.builder.JBossXBBuilder;
-import org.w3c.dom.ls.LSInput;
-import org.xml.sax.InputSource;
-
-/**
- * A default SchemaBindingResolver that uses a JBossEntityResolver to locate
- * the schema xsd.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class DefaultSchemaResolver implements SchemaBindingResolver
-{
- private static Logger log = Logger.getLogger(DefaultSchemaResolver.class);
-
- private String baseURI;
- private JBossEntityResolver resolver;
- private boolean cacheResolvedSchemas = true;
- /** Namespace to SchemaBinding cache */
- private Map<String, SchemaBinding> schemasByUri = Collections.emptyMap();
- /** Namespace to JBossXBBuilder binding class */
- private WeakHashMap<String, Class> uriToClass = new WeakHashMap<String, Class>();
- /** SchemaLocation to JBossXBBuilder binding class */
- private WeakHashMap<String, Class> schemaLocationToClass = new WeakHashMap<String, Class>();
- /** Namespace to SchemaBindingInitializer */
- private Map<String, SchemaBindingInitializer> schemaInitByUri = Collections.emptyMap();
- /** Namespace to processAnnotations flag used with the XsdBinder.bind call */
- private Map<String, Boolean> schemaParseAnnotationsByUri = Collections.emptyMap();
-
- public DefaultSchemaResolver()
- {
- this(new JBossEntityResolver());
- }
-
- public DefaultSchemaResolver(JBossEntityResolver resolver)
- {
- this.resolver = resolver;
- }
-
- /**
- * @return true if resolved SchemaBinding's are cached, false otherwise
- */
- public boolean isCacheResolvedSchemas()
- {
- return cacheResolvedSchemas;
- }
-
- /**
- * Passing in true will make the schema resolver to cache successfully resolved
- * schemas (which is the default) with namespace URI being the identifier of a schema.
- * False will flush the cache and make the schema resolver to resolve schemas
- * on each request.
- * @param cacheResolvedSchemas
- */
- public void setCacheResolvedSchemas(boolean cacheResolvedSchemas)
- {
- this.cacheResolvedSchemas = cacheResolvedSchemas;
- if(!cacheResolvedSchemas)
- {
- schemasByUri = Collections.emptyMap();
- }
- }
-
- /**
- * Registers a location for the namespace URI.<p>
- *
- * This location is looked using the JBossEntityResolver, i.e. it is a classpath location
- *
- * @param nsUri the namespace location
- * @param location the classpath location
- */
- public void addSchemaLocation(String nsUri, String location)
- {
- resolver.registerLocalEntity(nsUri, location);
- }
-
-
- /**
- * Removes a location for the namespace URI.
- *
- * @todo actually remove it rather than setting null
- * @param nsUri the namespace location
- */
- public void removeSchemaLocation(String nsUri)
- {
- resolver.registerLocalEntity(nsUri, null);
- }
-
- /**
- * Whether to parse annotations for this namespace.
- *
- * @param nsUri the namespace
- * @param value the value of the option
- */
- public void addSchemaParseAnnotations(String nsUri, Boolean value)
- {
- if (nsUri == null)
- throw new IllegalArgumentException("Null namespace uri");
- if (value == null)
- throw new IllegalArgumentException("Null value");
- switch(schemaParseAnnotationsByUri.size())
- {
- case 0:
- schemaParseAnnotationsByUri = Collections.singletonMap(nsUri, value);
- break;
- case 1:
- schemaParseAnnotationsByUri = new HashMap<String, Boolean>(schemaParseAnnotationsByUri);
- default:
- schemaParseAnnotationsByUri.put(nsUri, value);
- }
- }
-
- /**
- * Removes the parse annotation configuration for this namespace
- *
- * @param nsUri the namespace
- * @return the previous value
- */
- public Boolean removeSchemaParseAnnotations(String nsUri)
- {
- if (nsUri == null)
- throw new IllegalArgumentException("Null namespace uri");
- return schemaParseAnnotationsByUri.remove(nsUri);
- }
-
- /**
- * Registers a SchemaBindingInitializer for the namespace URI.
- * When the schema binding that corresponds to the namespace URI
- * is resolved, the init(SchemaBinding schema) method will be invoked on the
- * instance of SchemaBindingInitializer with the SchemaBinding returned from the
- * XsdBinder.bind() method.
- *
- * @param nsUri the namespace URI to register the schema initializer for
- * @param sbiClassName the class name SchemaBindingInitializer
- * @throws Exception for any error
- */
- public void addSchemaInitializer(String nsUri, String sbiClassName) throws Exception
- {
- if (sbiClassName == null)
- throw new IllegalArgumentException("Null class name");
- Class clazz = Thread.currentThread().getContextClassLoader().loadClass(sbiClassName);
- Object object = clazz.newInstance();
- if (object instanceof SchemaBindingInitializer == false)
- throw new IllegalArgumentException(clazz.getName() + " is not an instance of " + SchemaBindingInitializer.class.getName());
- SchemaBindingInitializer sbi = (SchemaBindingInitializer) object;
- addSchemaInitializer(nsUri, sbi);
- }
-
- /**
- * Registers an instance of SchemaBindingInitializer for the namespace URI.
- * When the schema binding that corresponds to the namespace URI
- * is resolved, the init(SchemaBinding schema) method will be invoked on the
- * instance of SchemaBindingInitializer with the SchemaBinding returned from the
- * XsdBinder.bind() method.
- *
- * @param nsUri the namespace URI to register the schema initializer for
- * @param sbi an instance of SchemaBindingInitializer
- */
- public void addSchemaInitializer(String nsUri, SchemaBindingInitializer sbi)
- {
- if (nsUri == null)
- throw new IllegalArgumentException("Null namespace uri");
- if (sbi == null)
- throw new IllegalArgumentException("Null schema binding initializer");
- switch(schemaInitByUri.size())
- {
- case 0:
- schemaInitByUri = Collections.singletonMap(nsUri, sbi);
- break;
- case 1:
- schemaInitByUri = new HashMap<String, SchemaBindingInitializer>(schemaInitByUri);
- default:
- schemaInitByUri.put(nsUri, sbi);
- }
- }
-
- /**
- * Unregisters and returns the SchemaBindingInitializer for the namespace URI.
- * @param nsUri the namespace URI to unregister SchemaBindingInitializer for
- * @return unregistered SchemaBindingInitializer for the namespace URI or null
- * if there was no SchemaBindingInitialzer registered for the namespace URI
- */
- public SchemaBindingInitializer removeSchemaInitializer(String nsUri)
- {
- if (nsUri == null)
- throw new IllegalArgumentException("Null namespace uri");
- return schemaInitByUri.remove(nsUri);
- }
-
- /**
- * Add an in-memory schema.
- *
- * @param nsUri schema namespace
- * @param reference the schema reference class name
- * @throws Exception for any error
- */
- public void addClassBinding(String nsUri, String reference) throws Exception
- {
- if (reference == null)
- throw new IllegalArgumentException("Null reference class");
-
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Class clazz = cl.loadClass(reference);
- addClassBinding(nsUri, clazz);
- }
-
- public void addClassBinding(String nsUri, Class clazz)
- {
- uriToClass.put(nsUri, clazz);
- }
- public Class removeClassBinding(String nsUri)
- {
- return uriToClass.remove(nsUri);
- }
-
- public void addClassBindingForLocation(String schemaLocation, Class clazz)
- {
- schemaLocationToClass.put(schemaLocation, clazz);
- }
- public Class removeClassBindingForLocation(String schemaLocation)
- {
- return schemaLocationToClass.remove(schemaLocation);
- }
-
- public String getBaseURI()
- {
- return baseURI;
- }
-
- public void setBaseURI(String baseURI)
- {
- this.baseURI = baseURI;
- }
-
- /**
- * Uses the JBossEntityResolver.resolveEntity by:
- *
- * 1. Using the nsUri as the systemID
- * 2. Using the schemaLocation as the systemID
- * 3. If that fails, the baseURI is not null, the xsd is located using URL(baseURL, schemaLocation)
- * 4. If the baseURI is null, the xsd is located using URL(schemaLocation)
- */
- public SchemaBinding resolve(String nsURI, String baseURI, String schemaLocation)
- {
- boolean trace = log.isTraceEnabled();
- // Was the schema binding based on the nsURI
- boolean foundByNS = false;
- SchemaBinding schema = schemasByUri.get(nsURI);
- if(schema != null)
- {
- if(trace)
- log.trace("resolved cached schema, nsURI="+nsURI+", schema: " + schema);
- return schema;
- }
-
- // Look for a class binding by schemaLocation
- Class bindingClass = resolveClassFromSchemaLocation(schemaLocation, trace);
- if (bindingClass == null)
- {
- // Next look by namespace
- bindingClass = uriToClass.get(nsURI);
- if(bindingClass != null)
- foundByNS = true;
- }
- if (bindingClass != null)
- {
- if( trace )
- {
- log.trace("found bindingClass, nsURI="+nsURI
- +", baseURI="+baseURI
- +", schemaLocation="+schemaLocation
- +", class="+bindingClass);
- }
- schema = JBossXBBuilder.build(bindingClass);
- }
- else
- {
- // Parse the schema
- InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
- if( trace )
- {
- log.trace("found schema InputSource, nsURI="+nsURI
- +", baseURI="+baseURI
- +", schemaLocation="+schemaLocation);
- }
-
- if (is != null)
- {
- if( baseURI == null )
- baseURI = this.baseURI;
-
- Boolean processAnnotationsBoolean = schemaParseAnnotationsByUri.get(nsURI);
- boolean processAnnotations = (processAnnotationsBoolean == null) ? true : processAnnotationsBoolean.booleanValue();
- try
- {
- schema = XsdBinder.bind(is.getByteStream(), null, baseURI, processAnnotations);
- foundByNS = true;
- }
- catch(RuntimeException e)
- {
- String msg = "Failed to parse schema for nsURI="+nsURI
- +", baseURI="+baseURI
- +", schemaLocation="+schemaLocation;
- throw new JBossXBRuntimeException(msg, e);
- }
- }
- }
-
- if(schema != null)
- {
- schema.setSchemaResolver(this);
- SchemaBindingInitializer sbi = schemaInitByUri.get(nsURI);
- if(sbi != null)
- {
- schema = sbi.init(schema);
- }
-
- if(schema != null && nsURI.length() > 0 && cacheResolvedSchemas && foundByNS)
- {
- if(schemasByUri == Collections.EMPTY_MAP)
- {
- schemasByUri = new HashMap<String, SchemaBinding>();
- }
- schemasByUri.put(nsURI, schema);
- }
- }
-
- if(trace)
- {
- log.trace("resolved schema: " + schema);
- }
-
- return schema;
- }
-
- /**
- * Lookup a binding class by schemaLocation. This first uses the
- * schemaLocation as is, then parses this as a URI to obtain the
- * final path component. This allows registration of a binding class
- * using jboss_5_0.dtd rather than http://www.jboss.org/j2ee/schema/jboss_5_0.xsd
- *
- * @param schemaLocation the schema location from the parser
- * @param trace - logging trace flag
- * @return the binding class if found.
- */
- protected Class resolveClassFromSchemaLocation(String schemaLocation,
- boolean trace)
- {
- Class bindingClass = schemaLocationToClass.get(schemaLocation);
- if (bindingClass == null && schemaLocation != null && schemaLocation.length() > 0)
- {
- // Parse the schemaLocation as a uri to get the final path component
- try
- {
- URI url = new URI(schemaLocation);
- String path = url.getPath();
- if( path == null )
- path = url.getSchemeSpecificPart();
- int slash = path.lastIndexOf('/');
- String filename;
- if( slash >= 0 )
- filename = path.substring(slash + 1);
- else
- filename = path;
-
- if(path.length() == 0)
- return null;
-
- if (trace)
- log.trace("Mapped schemaLocation to filename: " + filename);
- bindingClass = schemaLocationToClass.get(filename);
- }
- catch (URISyntaxException e)
- {
- if (trace)
- log.trace("schemaLocation: is not a URI, using systemId as resource", e);
- }
- }
- return bindingClass;
- }
-
- public LSInput resolveAsLSInput(String nsURI, String baseURI, String schemaLocation)
- {
- LSInput lsInput = null;
- InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
- if (is != null)
- {
- String publicId = is.getPublicId();
- String systemId = is.getSystemId();
- lsInput = new LSInputAdaptor(publicId, systemId, baseURI);
- lsInput.setCharacterStream(is.getCharacterStream());
- lsInput.setByteStream(is.getByteStream());
- lsInput.setEncoding(is.getEncoding());
- }
- return lsInput;
- }
-
- private InputSource getInputSource(String nsURI, String baseURI, String schemaLocation)
- {
- boolean trace = log.isTraceEnabled();
- InputSource is = null;
-
- if( trace )
- log.trace("getInputSource, nsURI="+nsURI+", baseURI="+baseURI+", schemaLocation="+schemaLocation);
-
- // First try what is requested
- try
- {
- is = resolver.resolveEntity(nsURI, schemaLocation);
- if (trace)
- log.trace("Resolved schema using namespace as publicId and schemaLocation as systemId");
- }
- catch (Exception e)
- {
- if (trace)
- log.trace("Failed to use nsUri/schemaLocation", e);
- }
-
- // Next, try to use the baseURI to resolve the schema location
- if(baseURI == null)
- {
- baseURI = this.baseURI;
- }
-
- if (is == null && baseURI != null && schemaLocation != null)
- {
- try
- {
- URL url = new URL(baseURI);
- url = new URL(url, schemaLocation);
- String resolvedSchemaLocation = url.toString();
- // No point if the schema location was already absolute
- if (schemaLocation.equals(resolvedSchemaLocation) == false)
- {
- is = resolver.resolveEntity(null, url.toString());
- if( trace && is != null )
- log.trace("Resolved schema location using baseURI");
- }
- }
- catch (Exception e)
- {
- if (trace)
- log.trace("Failed to use schema location with baseURI", e);
- }
- }
-
- // Finally, just try the namespace as the system id
- if (is == null && nsURI != null)
- {
- try
- {
- is = resolver.resolveEntity(null, nsURI);
- if( trace && is != null )
- log.trace("Resolved namespace as system id");
- }
- catch (Exception e)
- {
- if (trace)
- log.trace("Failed to use namespace as system id", e);
- }
- }
- if( trace )
- {
- log.trace("getInputSource, nsURI="+nsURI+", baseURI="
- +baseURI+", schemaLocation="+schemaLocation+", is="+is);
- }
- return is;
- }
-
-}
Copied: jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java (from rev 2756, jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java)
===================================================================
--- jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java (rev 0)
+++ jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java 2008-03-28 13:19:42 UTC (rev 2774)
@@ -0,0 +1,510 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.xb.binding.sunday.unmarshalling;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.xb.binding.JBossXBRuntimeException;
+import org.jboss.xb.builder.JBossXBBuilder;
+import org.w3c.dom.ls.LSInput;
+import org.xml.sax.InputSource;
+
+/**
+ * A default SchemaBindingResolver that uses a JBossEntityResolver to locate
+ * the schema xsd.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DefaultSchemaResolver implements SchemaBindingResolver
+{
+ private static Logger log = Logger.getLogger(DefaultSchemaResolver.class);
+
+ private String baseURI;
+ private JBossEntityResolver resolver;
+ private boolean cacheResolvedSchemas = true;
+ /** Namespace to SchemaBinding cache */
+ private Map<String, SchemaBinding> schemasByUri = Collections.emptyMap();
+ /** Namespace to JBossXBBuilder binding class */
+ private WeakHashMap<String, Class> uriToClass = new WeakHashMap<String, Class>();
+ /** SchemaLocation to JBossXBBuilder binding class */
+ private WeakHashMap<String, Class> schemaLocationToClass = new WeakHashMap<String, Class>();
+ /** Namespace to SchemaBindingInitializer */
+ private Map<String, SchemaBindingInitializer> schemaInitByUri = Collections.emptyMap();
+ /** Namespace to processAnnotations flag used with the XsdBinder.bind call */
+ private Map<String, Boolean> schemaParseAnnotationsByUri = Collections.emptyMap();
+
+ public DefaultSchemaResolver()
+ {
+ this(new JBossEntityResolver());
+ }
+
+ public DefaultSchemaResolver(JBossEntityResolver resolver)
+ {
+ this.resolver = resolver;
+ }
+
+ /**
+ * @return true if resolved SchemaBinding's are cached, false otherwise
+ */
+ public boolean isCacheResolvedSchemas()
+ {
+ return cacheResolvedSchemas;
+ }
+
+ /**
+ * Passing in true will make the schema resolver to cache successfully resolved
+ * schemas (which is the default) with namespace URI being the identifier of a schema.
+ * False will flush the cache and make the schema resolver to resolve schemas
+ * on each request.
+ * @param cacheResolvedSchemas
+ */
+ public void setCacheResolvedSchemas(boolean cacheResolvedSchemas)
+ {
+ this.cacheResolvedSchemas = cacheResolvedSchemas;
+ if(!cacheResolvedSchemas)
+ {
+ schemasByUri = Collections.emptyMap();
+ }
+ }
+
+ /**
+ * Registers a location for the namespace URI.<p>
+ *
+ * This location is looked using the JBossEntityResolver, i.e. it is a classpath location
+ *
+ * @param nsUri the namespace location
+ * @param location the classpath location
+ */
+ public void addSchemaLocation(String nsUri, String location)
+ {
+ resolver.registerLocalEntity(nsUri, location);
+ }
+
+
+ /**
+ * Removes a location for the namespace URI.
+ *
+ * @todo actually remove it rather than setting null
+ * @param nsUri the namespace location
+ */
+ public void removeSchemaLocation(String nsUri)
+ {
+ resolver.registerLocalEntity(nsUri, null);
+ }
+
+ /**
+ * Whether to parse annotations for this namespace.
+ *
+ * @param nsUri the namespace
+ * @param value the value of the option
+ */
+ public void addSchemaParseAnnotations(String nsUri, Boolean value)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ if (value == null)
+ throw new IllegalArgumentException("Null value");
+ switch(schemaParseAnnotationsByUri.size())
+ {
+ case 0:
+ schemaParseAnnotationsByUri = Collections.singletonMap(nsUri, value);
+ break;
+ case 1:
+ schemaParseAnnotationsByUri = new HashMap<String, Boolean>(schemaParseAnnotationsByUri);
+ default:
+ schemaParseAnnotationsByUri.put(nsUri, value);
+ }
+ }
+
+ /**
+ * Removes the parse annotation configuration for this namespace
+ *
+ * @param nsUri the namespace
+ * @return the previous value
+ */
+ public Boolean removeSchemaParseAnnotations(String nsUri)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ return schemaParseAnnotationsByUri.remove(nsUri);
+ }
+
+ /**
+ * Registers a SchemaBindingInitializer for the namespace URI.
+ * When the schema binding that corresponds to the namespace URI
+ * is resolved, the init(SchemaBinding schema) method will be invoked on the
+ * instance of SchemaBindingInitializer with the SchemaBinding returned from the
+ * XsdBinder.bind() method.
+ *
+ * @param nsUri the namespace URI to register the schema initializer for
+ * @param sbiClassName the class name SchemaBindingInitializer
+ * @throws Exception for any error
+ */
+ public void addSchemaInitializer(String nsUri, String sbiClassName) throws Exception
+ {
+ if (sbiClassName == null)
+ throw new IllegalArgumentException("Null class name");
+ Class clazz = Thread.currentThread().getContextClassLoader().loadClass(sbiClassName);
+ Object object = clazz.newInstance();
+ if (object instanceof SchemaBindingInitializer == false)
+ throw new IllegalArgumentException(clazz.getName() + " is not an instance of " + SchemaBindingInitializer.class.getName());
+ SchemaBindingInitializer sbi = (SchemaBindingInitializer) object;
+ addSchemaInitializer(nsUri, sbi);
+ }
+
+ /**
+ * Registers an instance of SchemaBindingInitializer for the namespace URI.
+ * When the schema binding that corresponds to the namespace URI
+ * is resolved, the init(SchemaBinding schema) method will be invoked on the
+ * instance of SchemaBindingInitializer with the SchemaBinding returned from the
+ * XsdBinder.bind() method.
+ *
+ * @param nsUri the namespace URI to register the schema initializer for
+ * @param sbi an instance of SchemaBindingInitializer
+ */
+ public void addSchemaInitializer(String nsUri, SchemaBindingInitializer sbi)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ if (sbi == null)
+ throw new IllegalArgumentException("Null schema binding initializer");
+ switch(schemaInitByUri.size())
+ {
+ case 0:
+ schemaInitByUri = Collections.singletonMap(nsUri, sbi);
+ break;
+ case 1:
+ schemaInitByUri = new HashMap<String, SchemaBindingInitializer>(schemaInitByUri);
+ default:
+ schemaInitByUri.put(nsUri, sbi);
+ }
+ }
+
+ /**
+ * Unregisters and returns the SchemaBindingInitializer for the namespace URI.
+ * @param nsUri the namespace URI to unregister SchemaBindingInitializer for
+ * @return unregistered SchemaBindingInitializer for the namespace URI or null
+ * if there was no SchemaBindingInitialzer registered for the namespace URI
+ */
+ public SchemaBindingInitializer removeSchemaInitializer(String nsUri)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ return schemaInitByUri.remove(nsUri);
+ }
+
+ /**
+ * Add an in-memory schema.
+ *
+ * @param nsUri schema namespace
+ * @param reference the schema reference class name
+ * @throws Exception for any error
+ */
+ public void addClassBinding(String nsUri, String reference) throws Exception
+ {
+ if (reference == null)
+ throw new IllegalArgumentException("Null reference class");
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class clazz = cl.loadClass(reference);
+ addClassBinding(nsUri, clazz);
+ }
+
+ public void addClassBinding(String nsUri, Class clazz)
+ {
+ uriToClass.put(nsUri, clazz);
+ }
+ public Class removeClassBinding(String nsUri)
+ {
+ return uriToClass.remove(nsUri);
+ }
+
+ public void addClassBindingForLocation(String schemaLocation, Class clazz)
+ {
+ schemaLocationToClass.put(schemaLocation, clazz);
+ }
+ public Class removeClassBindingForLocation(String schemaLocation)
+ {
+ return schemaLocationToClass.remove(schemaLocation);
+ }
+
+ public String getBaseURI()
+ {
+ return baseURI;
+ }
+
+ public void setBaseURI(String baseURI)
+ {
+ this.baseURI = baseURI;
+ }
+
+ /**
+ * Uses the JBossEntityResolver.resolveEntity by:
+ *
+ * 1. Using the nsUri as the systemID
+ * 2. Using the schemaLocation as the systemID
+ * 3. If that fails, the baseURI is not null, the xsd is located using URL(baseURL, schemaLocation)
+ * 4. If the baseURI is null, the xsd is located using URL(schemaLocation)
+ */
+ public SchemaBinding resolve(String nsURI, String baseURI, String schemaLocation)
+ {
+ boolean trace = log.isTraceEnabled();
+ // Was the schema binding based on the nsURI
+ boolean foundByNS = false;
+ SchemaBinding schema = schemasByUri.get(nsURI);
+ if(schema != null)
+ {
+ if(trace)
+ log.trace("resolved cached schema, nsURI="+nsURI+", schema: " + schema);
+ return schema;
+ }
+
+ // Look for a class binding by schemaLocation
+ Class bindingClass = resolveClassFromSchemaLocation(schemaLocation, trace);
+ if (bindingClass == null)
+ {
+ // Next look by namespace
+ bindingClass = uriToClass.get(nsURI);
+ if(bindingClass != null)
+ foundByNS = true;
+ }
+ if (bindingClass != null)
+ {
+ if( trace )
+ {
+ log.trace("found bindingClass, nsURI="+nsURI
+ +", baseURI="+baseURI
+ +", schemaLocation="+schemaLocation
+ +", class="+bindingClass);
+ }
+ schema = JBossXBBuilder.build(bindingClass);
+ }
+ else
+ {
+ // Parse the schema
+ InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
+ if( trace )
+ {
+ String msg = (is == null ? "couldn't find" : "found") +
+ " schema InputSource, nsURI=" + nsURI +
+ ", baseURI=" + baseURI + ", schemaLocation=" +
+ schemaLocation;
+ log.trace(msg);
+ }
+
+ if (is != null)
+ {
+ if( baseURI == null )
+ baseURI = this.baseURI;
+
+ Boolean processAnnotationsBoolean = schemaParseAnnotationsByUri.get(nsURI);
+ boolean processAnnotations = (processAnnotationsBoolean == null) ? true : processAnnotationsBoolean.booleanValue();
+ try
+ {
+ schema = XsdBinder.bind(is.getByteStream(), null, baseURI, processAnnotations);
+ foundByNS = true;
+ }
+ catch(RuntimeException e)
+ {
+ String msg = "Failed to parse schema for nsURI="+nsURI
+ +", baseURI="+baseURI
+ +", schemaLocation="+schemaLocation;
+ throw new JBossXBRuntimeException(msg, e);
+ }
+ }
+ }
+
+ if(schema != null)
+ {
+ schema.setSchemaResolver(this);
+ SchemaBindingInitializer sbi = schemaInitByUri.get(nsURI);
+ if(sbi != null)
+ {
+ schema = sbi.init(schema);
+ }
+
+ if(schema != null && nsURI.length() > 0 && cacheResolvedSchemas && foundByNS)
+ {
+ if(schemasByUri == Collections.EMPTY_MAP)
+ {
+ schemasByUri = new HashMap<String, SchemaBinding>();
+ }
+ schemasByUri.put(nsURI, schema);
+ }
+ }
+
+ if(trace)
+ {
+ log.trace("resolved schema: " + schema);
+ }
+
+ return schema;
+ }
+
+ /**
+ * Lookup a binding class by schemaLocation. This first uses the
+ * schemaLocation as is, then parses this as a URI to obtain the
+ * final path component. This allows registration of a binding class
+ * using jboss_5_0.dtd rather than http://www.jboss.org/j2ee/schema/jboss_5_0.xsd
+ *
+ * @param schemaLocation the schema location from the parser
+ * @param trace - logging trace flag
+ * @return the binding class if found.
+ */
+ protected Class resolveClassFromSchemaLocation(String schemaLocation,
+ boolean trace)
+ {
+ Class bindingClass = schemaLocationToClass.get(schemaLocation);
+ if (bindingClass == null && schemaLocation != null && schemaLocation.length() > 0)
+ {
+ // Parse the schemaLocation as a uri to get the final path component
+ try
+ {
+ URI url = new URI(schemaLocation);
+ String path = url.getPath();
+ if( path == null )
+ path = url.getSchemeSpecificPart();
+ int slash = path.lastIndexOf('/');
+ String filename;
+ if( slash >= 0 )
+ filename = path.substring(slash + 1);
+ else
+ filename = path;
+
+ if(path.length() == 0)
+ return null;
+
+ if (trace)
+ log.trace("Mapped schemaLocation to filename: " + filename);
+ bindingClass = schemaLocationToClass.get(filename);
+ }
+ catch (URISyntaxException e)
+ {
+ if (trace)
+ log.trace("schemaLocation: is not a URI, using systemId as resource", e);
+ }
+ }
+ return bindingClass;
+ }
+
+ public LSInput resolveAsLSInput(String nsURI, String baseURI, String schemaLocation)
+ {
+ LSInput lsInput = null;
+ InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
+ if (is != null)
+ {
+ String publicId = is.getPublicId();
+ String systemId = is.getSystemId();
+ lsInput = new LSInputAdaptor(publicId, systemId, baseURI);
+ lsInput.setCharacterStream(is.getCharacterStream());
+ lsInput.setByteStream(is.getByteStream());
+ lsInput.setEncoding(is.getEncoding());
+ }
+ return lsInput;
+ }
+
+ private InputSource getInputSource(String nsURI, String baseURI, String schemaLocation)
+ {
+ boolean trace = log.isTraceEnabled();
+ InputSource is = null;
+
+ if( trace )
+ log.trace("getInputSource, nsURI="+nsURI+", baseURI="+baseURI+", schemaLocation="+schemaLocation);
+
+ // First try what is requested
+ try
+ {
+ is = resolver.resolveEntity(nsURI, schemaLocation);
+ if (trace)
+ {
+ String msg = (is == null ? "Couldn't resolve" : "Resolved") +
+ " schema using namespace as publicId and schemaLocation as systemId";
+ log.trace(msg);
+ }
+ }
+ catch (Exception e)
+ {
+ if (trace)
+ log.trace("Failed to use nsUri/schemaLocation", e);
+ }
+
+ // Next, try to use the baseURI to resolve the schema location
+ if(baseURI == null)
+ {
+ baseURI = this.baseURI;
+ }
+
+ if (is == null && baseURI != null && schemaLocation != null)
+ {
+ try
+ {
+ URL url = new URL(baseURI);
+ url = new URL(url, schemaLocation);
+ String resolvedSchemaLocation = url.toString();
+ // No point if the schema location was already absolute
+ if (schemaLocation.equals(resolvedSchemaLocation) == false)
+ {
+ is = resolver.resolveEntity(null, url.toString());
+ if( trace && is != null )
+ log.trace("Resolved schema location using baseURI");
+ }
+ }
+ catch (Exception e)
+ {
+ if (trace)
+ log.trace("Failed to use schema location with baseURI", e);
+ }
+ }
+
+ // Finally, just try the namespace as the system id
+ if (is == null && nsURI != null)
+ {
+ try
+ {
+ is = resolver.resolveEntity(null, nsURI);
+ if( trace && is != null )
+ log.trace("Resolved namespace as system id");
+ }
+ catch (Exception e)
+ {
+ if (trace)
+ log.trace("Failed to use namespace as system id", e);
+ }
+ }
+ if( trace )
+ {
+ log.trace("getInputSource, nsURI="+nsURI+", baseURI="
+ +baseURI+", schemaLocation="+schemaLocation+", is="+is);
+ }
+ return is;
+ }
+
+}
Deleted: jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java 2008-03-27 12:41:03 UTC (rev 2752)
+++ jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java 2008-03-28 13:19:42 UTC (rev 2774)
@@ -1,201 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.xb.binding.sunday.unmarshalling;
-
-import org.jboss.logging.Logger;
-
-/**
- * SingletonSchemaResolverFactory.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision$
- */
-public class SingletonSchemaResolverFactory implements SchemaResolverFactory
-{
- /** The log */
- private static final Logger log = Logger.getLogger(SingletonSchemaResolverFactory.class);
-
- /** The factory instance */
- private static final SingletonSchemaResolverFactory singleton = new SingletonSchemaResolverFactory();
-
- /** The resolver */
- private final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
-
- /**
- * Get the factory instance
- *
- * @return the instance
- */
- public static SingletonSchemaResolverFactory getInstance()
- {
- return singleton;
- }
-
- /**
- * Create a new SingletonSchemaResolverFactory.
- */
- private SingletonSchemaResolverFactory()
- {
- // old initializer
- addSchema("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.xml.AOPBeansSchemaInitializer", Boolean.FALSE);
- addSchema("urn:jboss:spring-beans:2.0", "org.jboss.spring.deployment.xml.SpringSchemaInitializer", Boolean.FALSE);
- addSchema("urn:jboss:osgi-beans:1.0", "org.jboss.osgi.deployment.xml.OSGiSchemaInitializer", Boolean.FALSE);
- addSchema("urn:jboss:seam-components:1.0", "org.jboss.seam.ioc.microcontainer.xml.SeamSchemaInitializer", Boolean.FALSE);
- // new jaxb
- //addJaxbSchema("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.metadata.AOPDeployment");
- addJaxbSchema("urn:jboss:bean-deployer", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment10");
- addJaxbSchema("urn:jboss:bean-deployer:2.0", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment");
- addJaxbSchema("urn:jboss:javabean:1.0", "org.jboss.javabean.plugins.jaxb.JavaBean10");
- addJaxbSchema("urn:jboss:javabean:2.0", "org.jboss.javabean.plugins.jaxb.JavaBean20");
- addJaxbSchema("urn:jboss:policy:1.0", "org.jboss.beans.metadata.plugins.policy.AbstractPolicyMetaData");
- addJaxbSchema("urn:jboss:classloading:1.0", "org.jboss.classloading.spi.metadata.ClassLoadingMetaData10");
- addJaxbSchema("urn:jboss:classloader:1.0", "org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10");
- addJaxbSchema("urn:jboss:deployers:2.0", "org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData");
- }
-
- public SchemaBindingResolver getSchemaBindingResolver()
- {
- return resolver;
- }
-
- /**
- * Add a schema
- *
- * @param namespace the namespace
- * @param initializer the initializer
- * @return true when added
- */
- protected boolean addSchema(String namespace, String initializer)
- {
- try
- {
- resolver.addSchemaInitializer(namespace, initializer);
- if (log.isTraceEnabled())
- log.trace("Mapped initializer '" + namespace + "' to '" + initializer + "'");
- return true;
- }
- catch (Exception ignored)
- {
- if (log.isTraceEnabled())
- log.trace("Ignored: ", ignored);
- return false;
- }
- }
-
- /**
- * Add a schema
- *
- * @param namespace the namespace
- * @param initializer the initializer
- * @param parseAnnotations whether to parse annotations
- * @return true when added
- */
- protected boolean addSchema(String namespace, String initializer, Boolean parseAnnotations)
- {
- if (addSchema(namespace, initializer) == false)
- return false;
- setParseAnnotations(namespace, parseAnnotations);
- return true;
- }
-
- /**
- * Add a schema
- *
- * @param namespace the namespace
- * @param initializer the initializer
- * @param location the location
- * @return true when added
- */
- protected boolean addSchema(String namespace, String initializer, String location)
- {
- if (addSchema(namespace, initializer) == false)
- return false;
- try
- {
- resolver.addSchemaLocation(namespace, location);
- if (log.isTraceEnabled())
- log.trace("Mapped location '" + namespace + "' to '" + location + "'");
- return true;
- }
- catch (Exception ignored)
- {
- if (log.isTraceEnabled())
- log.trace("Ignored: ", ignored);
- return false;
- }
- }
-
- /**
- * Add a schema
- *
- * @param namespace the namespace
- * @param initializer the initializer
- * @param location the location
- * @param parseAnnotations whether to parse annotations
- * @return true when added
- */
- protected boolean addSchema(String namespace, String initializer, String location, Boolean parseAnnotations)
- {
- if (addSchema(namespace, initializer, location) == false)
- return false;
- setParseAnnotations(namespace, parseAnnotations);
- return true;
- }
-
- /**
- * Set the parse annotations for a schema
- *
- * @param namespace the namespace
- * @param parseAnnotations whether to parse annotations
- */
- protected void setParseAnnotations(String namespace, Boolean parseAnnotations)
- {
- resolver.addSchemaParseAnnotations(namespace, parseAnnotations);
- if (log.isTraceEnabled())
- log.trace("Parse annotations '" + namespace + "' set to '" + parseAnnotations + "'");
- }
-
- /**
- * Add a schema.
- *
- * @param namespace the namespace
- * @param reference the schema reference class
- * @return true when added
- */
- public boolean addJaxbSchema(String namespace, String reference)
- {
- try
- {
- resolver.addClassBinding(namespace, reference);
- if (log.isTraceEnabled())
- log.trace("Mapped '" + namespace + "' to '" + reference + "'");
- return true;
- }
- catch (Exception ignored)
- {
- if (log.isTraceEnabled())
- log.trace("Ignored: ", ignored);
- return false;
- }
- }
-}
Copied: jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java (from rev 2762, jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java)
===================================================================
--- jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java (rev 0)
+++ jbossxb/tags/2.0.0.CR8/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java 2008-03-28 13:19:42 UTC (rev 2774)
@@ -0,0 +1,201 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.xb.binding.sunday.unmarshalling;
+
+import org.jboss.logging.Logger;
+
+/**
+ * SingletonSchemaResolverFactory.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision$
+ */
+public class SingletonSchemaResolverFactory implements SchemaResolverFactory
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(SingletonSchemaResolverFactory.class);
+
+ /** The factory instance */
+ private static final SingletonSchemaResolverFactory singleton = new SingletonSchemaResolverFactory();
+
+ /** The resolver */
+ private final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
+ /**
+ * Get the factory instance
+ *
+ * @return the instance
+ */
+ public static SingletonSchemaResolverFactory getInstance()
+ {
+ return singleton;
+ }
+
+ /**
+ * Create a new SingletonSchemaResolverFactory.
+ */
+ private SingletonSchemaResolverFactory()
+ {
+ // old initializer
+ //addSchema("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.xml.AOPBeansSchemaInitializer", Boolean.FALSE);
+ addSchema("urn:jboss:spring-beans:2.0", "org.jboss.spring.deployment.xml.SpringSchemaInitializer", Boolean.FALSE);
+ addSchema("urn:jboss:osgi-beans:1.0", "org.jboss.osgi.deployment.xml.OSGiSchemaInitializer", Boolean.FALSE);
+ addSchema("urn:jboss:seam-components:1.0", "org.jboss.seam.ioc.microcontainer.xml.SeamSchemaInitializer", Boolean.FALSE);
+ // new jaxb
+ addJaxbSchema("urn:jboss:aop-beans:1.0", "org.jboss.aop.microcontainer.beans.metadata.AOPDeployment");
+ addJaxbSchema("urn:jboss:bean-deployer", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment10");
+ addJaxbSchema("urn:jboss:bean-deployer:2.0", "org.jboss.kernel.plugins.deployment.AbstractKernelDeployment");
+ addJaxbSchema("urn:jboss:javabean:1.0", "org.jboss.javabean.plugins.jaxb.JavaBean10");
+ addJaxbSchema("urn:jboss:javabean:2.0", "org.jboss.javabean.plugins.jaxb.JavaBean20");
+ addJaxbSchema("urn:jboss:policy:1.0", "org.jboss.beans.metadata.plugins.policy.AbstractPolicyMetaData");
+ addJaxbSchema("urn:jboss:classloading:1.0", "org.jboss.classloading.spi.metadata.ClassLoadingMetaData10");
+ addJaxbSchema("urn:jboss:classloader:1.0", "org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10");
+ addJaxbSchema("urn:jboss:deployers:2.0", "org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData");
+ }
+
+ public SchemaBindingResolver getSchemaBindingResolver()
+ {
+ return resolver;
+ }
+
+ /**
+ * Add a schema
+ *
+ * @param namespace the namespace
+ * @param initializer the initializer
+ * @return true when added
+ */
+ protected boolean addSchema(String namespace, String initializer)
+ {
+ try
+ {
+ resolver.addSchemaInitializer(namespace, initializer);
+ if (log.isTraceEnabled())
+ log.trace("Mapped initializer '" + namespace + "' to '" + initializer + "'");
+ return true;
+ }
+ catch (Exception ignored)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Ignored: ", ignored);
+ return false;
+ }
+ }
+
+ /**
+ * Add a schema
+ *
+ * @param namespace the namespace
+ * @param initializer the initializer
+ * @param parseAnnotations whether to parse annotations
+ * @return true when added
+ */
+ protected boolean addSchema(String namespace, String initializer, Boolean parseAnnotations)
+ {
+ if (addSchema(namespace, initializer) == false)
+ return false;
+ setParseAnnotations(namespace, parseAnnotations);
+ return true;
+ }
+
+ /**
+ * Add a schema
+ *
+ * @param namespace the namespace
+ * @param initializer the initializer
+ * @param location the location
+ * @return true when added
+ */
+ protected boolean addSchema(String namespace, String initializer, String location)
+ {
+ if (addSchema(namespace, initializer) == false)
+ return false;
+ try
+ {
+ resolver.addSchemaLocation(namespace, location);
+ if (log.isTraceEnabled())
+ log.trace("Mapped location '" + namespace + "' to '" + location + "'");
+ return true;
+ }
+ catch (Exception ignored)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Ignored: ", ignored);
+ return false;
+ }
+ }
+
+ /**
+ * Add a schema
+ *
+ * @param namespace the namespace
+ * @param initializer the initializer
+ * @param location the location
+ * @param parseAnnotations whether to parse annotations
+ * @return true when added
+ */
+ protected boolean addSchema(String namespace, String initializer, String location, Boolean parseAnnotations)
+ {
+ if (addSchema(namespace, initializer, location) == false)
+ return false;
+ setParseAnnotations(namespace, parseAnnotations);
+ return true;
+ }
+
+ /**
+ * Set the parse annotations for a schema
+ *
+ * @param namespace the namespace
+ * @param parseAnnotations whether to parse annotations
+ */
+ protected void setParseAnnotations(String namespace, Boolean parseAnnotations)
+ {
+ resolver.addSchemaParseAnnotations(namespace, parseAnnotations);
+ if (log.isTraceEnabled())
+ log.trace("Parse annotations '" + namespace + "' set to '" + parseAnnotations + "'");
+ }
+
+ /**
+ * Add a schema.
+ *
+ * @param namespace the namespace
+ * @param reference the schema reference class
+ * @return true when added
+ */
+ public boolean addJaxbSchema(String namespace, String reference)
+ {
+ try
+ {
+ resolver.addClassBinding(namespace, reference);
+ if (log.isTraceEnabled())
+ log.trace("Mapped '" + namespace + "' to '" + reference + "'");
+ return true;
+ }
+ catch (Exception ignored)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Ignored: ", ignored);
+ return false;
+ }
+ }
+}
More information about the jboss-svn-commits
mailing list