[jboss-dev-forums] [Design of JBossXB] - DefaultSchemaResolver logic is wrong
adrian@jboss.org
do-not-reply at jboss.com
Thu Oct 5 07:34:17 EDT 2006
As per the previous thread earlier this year, it is not possible
to compose schemas using imports with JBossXB.
I've fixed this, with the new implemetation, I can now get an
XSModel for the JavaEE schemas (which previously failed due
to confusion of imports).
The new implementation looks like this:
|
| 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 (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;
| }
|
Previously, the last step was first, making it impossible
to compose a namespaces from different schema files.
Also, it didn't use the schemaLocation properly so it always
failed for simple imports like:
| <xsd:include schemaLocation="javaee_web_services_client_1_2.xsd"/>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976281#3976281
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976281
More information about the jboss-dev-forums
mailing list