org.jboss.xb.binding.sunday.unmarshalling
Class DefaultSchemaResolver

java.lang.Object
  extended by org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver
All Implemented Interfaces:
SchemaBindingResolver

public class DefaultSchemaResolver
extends Object
implements SchemaBindingResolver

A default SchemaBindingResolver that uses a JBossEntityResolver to locate the schema xsd.

Version:
$Revision: 2716 $
Author:
Scott.Stark@jboss.org

Constructor Summary
DefaultSchemaResolver()
           
DefaultSchemaResolver(org.jboss.util.xml.JBossEntityResolver resolver)
           
 
Method Summary
 void addClassBinding(String nsUri, Class clazz)
           
 void addClassBinding(String nsUri, String reference)
          Add an in-memory schema.
 void addClassBindingForLocation(String schemaLocation, Class clazz)
           
 void addSchemaInitializer(String nsUri, SchemaBindingInitializer sbi)
          Registers an instance of SchemaBindingInitializer for the namespace URI.
 void addSchemaInitializer(String nsUri, String sbiClassName)
          Registers a SchemaBindingInitializer for the namespace URI.
 void addSchemaLocation(String nsUri, String location)
          Registers a location for the namespace URI.
 void addSchemaParseAnnotations(String nsUri, Boolean value)
          Whether to parse annotations for this namespace.
 String getBaseURI()
           
 boolean isCacheResolvedSchemas()
           
 Class removeClassBinding(String nsUri)
           
 Class removeClassBindingForLocation(String schemaLocation)
           
 SchemaBindingInitializer removeSchemaInitializer(String nsUri)
          Unregisters and returns the SchemaBindingInitializer for the namespace URI.
 void removeSchemaLocation(String nsUri)
          Removes a location for the namespace URI.
 Boolean removeSchemaParseAnnotations(String nsUri)
          Removes the parse annotation configuration for this namespace
 SchemaBinding resolve(String nsURI, String baseURI, String schemaLocation)
          Uses the JBossEntityResolver.resolveEntity by: 1.
 LSInput resolveAsLSInput(String nsURI, String baseURI, String schemaLocation)
          This one is used to resolve imported schemas with
protected  Class resolveClassFromSchemaLocation(String schemaLocation, boolean trace)
          Lookup a binding class by schemaLocation.
 void setBaseURI(String baseURI)
           
 void setCacheResolvedSchemas(boolean 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSchemaResolver

public DefaultSchemaResolver()

DefaultSchemaResolver

public DefaultSchemaResolver(org.jboss.util.xml.JBossEntityResolver resolver)
Method Detail

isCacheResolvedSchemas

public boolean isCacheResolvedSchemas()
Returns:
true if resolved SchemaBinding's are cached, false otherwise

setCacheResolvedSchemas

public void setCacheResolvedSchemas(boolean 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.

Parameters:
cacheResolvedSchemas -

addSchemaLocation

public void addSchemaLocation(String nsUri,
                              String location)
Registers a location for the namespace URI.

This location is looked using the JBossEntityResolver, i.e. it is a classpath location

Parameters:
nsUri - the namespace location
location - the classpath location

removeSchemaLocation

public void removeSchemaLocation(String nsUri)
Removes a location for the namespace URI.

Parameters:
nsUri - the namespace location

addSchemaParseAnnotations

public void addSchemaParseAnnotations(String nsUri,
                                      Boolean value)
Whether to parse annotations for this namespace.

Parameters:
nsUri - the namespace
value - the value of the option

removeSchemaParseAnnotations

public Boolean removeSchemaParseAnnotations(String nsUri)
Removes the parse annotation configuration for this namespace

Parameters:
nsUri - the namespace
Returns:
the previous value

addSchemaInitializer

public void addSchemaInitializer(String nsUri,
                                 String sbiClassName)
                          throws Exception
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.

Parameters:
nsUri - the namespace URI to register the schema initializer for
sbiClassName - the class name SchemaBindingInitializer
Throws:
Exception - for any error

addSchemaInitializer

public void addSchemaInitializer(String nsUri,
                                 SchemaBindingInitializer 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.

Parameters:
nsUri - the namespace URI to register the schema initializer for
sbi - an instance of SchemaBindingInitializer

removeSchemaInitializer

public SchemaBindingInitializer removeSchemaInitializer(String nsUri)
Unregisters and returns the SchemaBindingInitializer for the namespace URI.

Parameters:
nsUri - the namespace URI to unregister SchemaBindingInitializer for
Returns:
unregistered SchemaBindingInitializer for the namespace URI or null if there was no SchemaBindingInitialzer registered for the namespace URI

addClassBinding

public void addClassBinding(String nsUri,
                            String reference)
                     throws Exception
Add an in-memory schema.

Parameters:
nsUri - schema namespace
reference - the schema reference class name
Throws:
Exception - for any error

addClassBinding

public void addClassBinding(String nsUri,
                            Class clazz)

removeClassBinding

public Class removeClassBinding(String nsUri)

addClassBindingForLocation

public void addClassBindingForLocation(String schemaLocation,
                                       Class clazz)

removeClassBindingForLocation

public Class removeClassBindingForLocation(String schemaLocation)

getBaseURI

public String getBaseURI()
Specified by:
getBaseURI in interface SchemaBindingResolver

setBaseURI

public void setBaseURI(String baseURI)
Specified by:
setBaseURI in interface SchemaBindingResolver

resolve

public SchemaBinding resolve(String nsURI,
                             String baseURI,
                             String schemaLocation)
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)

Specified by:
resolve in interface SchemaBindingResolver
Parameters:
nsURI - - namespace URI of the element with the schema reference
baseURI - - an optional baseURI for resolving the schemaLocation.
schemaLocation - - the option schema location uri that matches nsUri if one exists
Returns:
an instance of SchemaBinding correspnding to the namespace URI or null if the namespace URI is not recognized (though, in this case it could also throw an exception)

resolveClassFromSchemaLocation

protected Class resolveClassFromSchemaLocation(String schemaLocation,
                                               boolean trace)
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

Parameters:
schemaLocation - the schema location from the parser
trace - - logging trace flag
Returns:
the binding class if found.

resolveAsLSInput

public LSInput resolveAsLSInput(String nsURI,
                                String baseURI,
                                String schemaLocation)
Description copied from interface: SchemaBindingResolver
This one is used to resolve imported schemas with

Specified by:
resolveAsLSInput in interface SchemaBindingResolver
Returns:
LIInput for the resolved namespace schema if found, null otherwise


Copyright © 2008 JBoss Inc.. All Rights Reserved.