JBoss XML Binding 2.0.3.GA-redhat-2

org.jboss.xb.binding.resolver
Class AbstractMutableSchemaResolver

java.lang.Object
  extended by org.jboss.xb.binding.resolver.AbstractMutableSchemaResolver
All Implemented Interfaces:
MutableSchemaResolver, MutableSchemaResolverWithQNameMapping, SchemaBindingResolver
Direct Known Subclasses:
DefaultSchemaResolver, MultiClassSchemaResolver

public abstract class AbstractMutableSchemaResolver
extends Object
implements MutableSchemaResolverWithQNameMapping

A AbstractMutableSchemaResolver.

Version:
$Revision: 1.1 $
Author:
Alexey Loubyansky

Constructor Summary
protected AbstractMutableSchemaResolver(org.jboss.logging.Logger log)
           
protected AbstractMutableSchemaResolver(org.jboss.logging.Logger log, org.jboss.util.xml.JBossEntityResolver resolver)
           
 
Method Summary
 String getBaseURI()
           
 SchemaBindingValidator getBindingValidator()
          Returns the validator which is used to validate SchemaBinding instances if validation is enabled.
protected abstract  Class<?>[] getClassesForQName(QName elementName)
           
protected abstract  Class<?>[] getClassesForSchemaLocation(String uri)
           
protected abstract  Class<?>[] getClassesForURI(String uri)
           
 boolean isCacheResolvedSchemas()
           
 boolean isValidateBinding()
          Checks whether SchemaBinding instances built from JAXB/JBossXB annotations should be validated for structural consistency with the corresponding XSD.
protected  Class<?> loadReference(String sbiClassName)
           
 void mapLocationToClass(String schemaLocation, String reference)
          Maps schema location to a class which should be used as the base for the SchemaBinding.
 void mapLocationToClasses(String schemaLocation, String... reference)
          Maps schema location to an array of classes that should be used as the base for the SchemaBinding.
 void mapSchemaInitializer(String nsUri, SchemaBindingInitializer sbi)
          Registers an instance of SchemaBindingInitializer for the namespace URI.
 void mapSchemaInitializer(String nsUri, String sbiClassName)
          Registers a SchemaBindingInitializer for the namespace URI.
 void mapSchemaLocation(String nsUri, String location)
          Registers a location for the namespace URI.
 void mapURIToClass(String nsUri, String reference)
          Maps a namespace URI to a class which will be used as the base for the SchemaBinding.
 void mapURIToClasses(String nsUri, String... reference)
          Maps a namespace URI to an array of classes that will be used as the base for the SchemaBinding.
 SchemaBindingInitializer removeSchemaInitializer(String nsUri)
          Unregisters and returns the SchemaBindingInitializer for the namespace URI.
 void removeSchemaLocation(String nsUri)
          Removes a location for the namespace URI.
 SchemaBinding resolve(String nsURI, String localName, 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 setBindingValidator(SchemaBindingValidator validator)
          Sets the validator which should be used to validate SchemaBinding instances built from JAXB/JBossXB annotations if validation is enabled.
 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.
 void setParseXSDAnnotations(String nsUri, boolean value)
          Whether to parse annotations for this namespace.
 void setValidateBinding(boolean validateBinding)
          Enables/disables validation of SchemaBinding instances built from JAXB/JBossXB annotations against the corresponding XSD schemas.
 Boolean unsetParseXSDAnnotations(String nsURI)
          Clears the flag to parse XSD annotations for the namespace URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.xb.binding.resolver.MutableSchemaResolverWithQNameMapping
mapQNameToClasses, removeQNameToClassMapping
 
Methods inherited from interface org.jboss.xb.binding.resolver.MutableSchemaResolver
mapLocationToClass, mapLocationToClasses, mapURIToClass, mapURIToClasses, removeLocationToClassMapping, removeURIToClassMapping
 

Constructor Detail

AbstractMutableSchemaResolver

protected AbstractMutableSchemaResolver(org.jboss.logging.Logger log)

AbstractMutableSchemaResolver

protected AbstractMutableSchemaResolver(org.jboss.logging.Logger log,
                                        org.jboss.util.xml.JBossEntityResolver resolver)
Method Detail

isValidateBinding

public boolean isValidateBinding()
Checks whether SchemaBinding instances built from JAXB/JBossXB annotations should be validated for structural consistency with the corresponding XSD. By default the validation is turned off for performance reasons.

Returns:
true is validation is on.

setValidateBinding

public void setValidateBinding(boolean validateBinding)
Enables/disables validation of SchemaBinding instances built from JAXB/JBossXB annotations against the corresponding XSD schemas.

Parameters:
validateBinding - validate binding flag

getBindingValidator

public SchemaBindingValidator getBindingValidator()
Returns the validator which is used to validate SchemaBinding instances if validation is enabled. By default validator is not initialized. And if validation is enabled a new instance of SchemaBindingValidator will be created and used for validation for every new SchemaBinding.

Returns:
user provided instance of SchemaBindingValidator or null if the user chose not too provide one

setBindingValidator

public void setBindingValidator(SchemaBindingValidator validator)
Sets the validator which should be used to validate SchemaBinding instances built from JAXB/JBossXB annotations if validation is enabled. By default validator is not initialized. And if validation is enabled a new instance of DefaultSchemaBindingValidator will be created and used for validation for every new SchemaBinding.

Parameters:
validator - the schema binding validator

isCacheResolvedSchemas

public boolean isCacheResolvedSchemas()
Specified by:
isCacheResolvedSchemas in interface MutableSchemaResolver
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.

Specified by:
setCacheResolvedSchemas in interface MutableSchemaResolver
Parameters:
cacheResolvedSchemas - do we cache resolved schemas

mapSchemaLocation

public void mapSchemaLocation(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

Specified by:
mapSchemaLocation in interface MutableSchemaResolver
Parameters:
nsUri - the namespace location
location - the classpath location

removeSchemaLocation

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

Specified by:
removeSchemaLocation in interface MutableSchemaResolver
Parameters:
nsUri - the namespace location

setParseXSDAnnotations

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

Specified by:
setParseXSDAnnotations in interface MutableSchemaResolver
Parameters:
nsUri - the namespace
value - the value of the option

unsetParseXSDAnnotations

public Boolean unsetParseXSDAnnotations(String nsURI)
Description copied from interface: MutableSchemaResolver
Clears the flag to parse XSD annotations for the namespace URI. The default setting for parsing XSD annotations will be applied to this namespace URI after this method is called.

Specified by:
unsetParseXSDAnnotations in interface MutableSchemaResolver
Parameters:
nsURI - the namespace URI
Returns:
the value previously set or null, if no value was set for this namespace URI

mapSchemaInitializer

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

Specified by:
mapSchemaInitializer in interface MutableSchemaResolver
Parameters:
nsUri - the namespace URI to register the schema initializer for
sbiClassName - the class name SchemaBindingInitializer
Throws:
Exception - for any error

mapSchemaInitializer

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

Specified by:
mapSchemaInitializer in interface MutableSchemaResolver
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.

Specified by:
removeSchemaInitializer in interface MutableSchemaResolver
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

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 localName,
                             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
localName - - optional root element name
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)

mapURIToClass

public void mapURIToClass(String nsUri,
                          String reference)
                   throws ClassNotFoundException
Description copied from interface: MutableSchemaResolver
Maps a namespace URI to a class which will be used as the base for the SchemaBinding.

Specified by:
mapURIToClass in interface MutableSchemaResolver
Parameters:
nsUri - the namespace URI
reference - fully qualified class name to build the SchemaBinding from
Throws:
ClassNotFoundException - if the reference cannot be loaded

mapURIToClasses

public void mapURIToClasses(String nsUri,
                            String... reference)
                     throws ClassNotFoundException
Description copied from interface: MutableSchemaResolver
Maps a namespace URI to an array of classes that will be used as the base for the SchemaBinding.

Specified by:
mapURIToClasses in interface MutableSchemaResolver
Parameters:
nsUri - the namespace URI
reference - array of fully qualified class names to build the SchemaBinding from
Throws:
ClassNotFoundException - if at least one of the references cannot be loaded

mapLocationToClass

public void mapLocationToClass(String schemaLocation,
                               String reference)
                        throws ClassNotFoundException
Description copied from interface: MutableSchemaResolver
Maps schema location to a class which should be used as the base for the SchemaBinding.

Specified by:
mapLocationToClass in interface MutableSchemaResolver
Parameters:
schemaLocation - the location of the schema
reference - the fully qualified class name to build the SchemaBinding from
Throws:
ClassNotFoundException - if the reference cannot be loaded

mapLocationToClasses

public void mapLocationToClasses(String schemaLocation,
                                 String... reference)
                          throws ClassNotFoundException
Description copied from interface: MutableSchemaResolver
Maps schema location to an array of classes that should be used as the base for the SchemaBinding.

Specified by:
mapLocationToClasses in interface MutableSchemaResolver
Parameters:
schemaLocation - the location of the schema
reference - the array of fully qualified class names to build the SchemaBinding from
Throws:
ClassNotFoundException - if at least one of the references cannot be loaded

loadReference

protected Class<?> loadReference(String sbiClassName)
                          throws ClassNotFoundException
Throws:
ClassNotFoundException

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

getClassesForURI

protected abstract Class<?>[] getClassesForURI(String uri)

getClassesForSchemaLocation

protected abstract Class<?>[] getClassesForSchemaLocation(String uri)

getClassesForQName

protected abstract Class<?>[] getClassesForQName(QName elementName)

JBoss XML Binding 2.0.3.GA-redhat-2

Copyright © 2012 JBoss by Red Hat. All Rights Reserved.