net.sf.xolite.utils
Class SchemaLocation

java.lang.Object
  extended by net.sf.xolite.utils.SchemaLocation

public class SchemaLocation
extends Object

Helper to build the the schema location expressed as in the standard 'xsi:schemaLocation' xml attributes.
Such a string can be set on the SaxXMLEventParser to enable validation.

Caution: This schemaLocation attribute setup works with Sun JRE default parser (Xerces) but is not guaranteed to work if you (or a library you're using) have changed the default XML parser implementation.
In this case, you have to setup a validating parser yourself (following your parser documentation) and pass it to the SaxXMLEventParser(XMLReader) constructor.

Author:
Olivier Berlanger

Constructor Summary
SchemaLocation()
           
 
Method Summary
static String getResourceLocation(String schemaUri, Class<?> referenceClass, String resourcePath)
          Get a schemaLocation string for a schema packaged as an application resource.
static String getResourceURL(Class<?> referenceClass, String resourcePath)
          Return the URL to a resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchemaLocation

public SchemaLocation()
Method Detail

getResourceLocation

public static String getResourceLocation(String schemaUri,
                                         Class<?> referenceClass,
                                         String resourcePath)
Get a schemaLocation string for a schema packaged as an application resource.

Parameters:
schemaUri - URI of the schema
referenceClass - the reference class providing the class loader.
resourcePath - Path to the resource, it can be absolute (i.e. starting with '/') or relative to the package of this reference class.
Returns:
the schemaLocation string for the specified schema.

getResourceURL

public static String getResourceURL(Class<?> referenceClass,
                                    String resourcePath)
Return the URL to a resource.
This method verifies the existence of the requested resource and throw a IllegalArgumentException if the ressource is not found.

Parameters:
referenceClass - the reference class providing the class loader.
resourcePath - Path to the resource, it can be absolute (i.e. starting with '/') or relative to the package of this reference class.
Returns:
the URL to the specified resource.
Throws:
IllegalArgumentException - if the specified resource is not found.


Copyright © 2012. All Rights Reserved.