org.dhmp.util.xml
Class SchemaCollection

java.lang.Object
  extended byorg.dhmp.util.xml.SchemaCollection

public class SchemaCollection
extends java.lang.Object

Container for parsed schema. If the schema is not in the container, it looks for the, XSD document (XML Schema Document) from URL provided, parse and stock the result.

SchemaCollection is not fully compliant with W3C Recommendation. It only implements a subset required to validate HierarchicalMap. All XSD document must be a valid XML Schema Document. The result of passing malformed XSD document is unpredictable!

The interpretarion of HierarchicalMap node, like number and date are locale-sensitive. The interpretation of date anda datetime depends on TimeZone setting. Note that data is locale-sensitive though value space definition on XSD document is not. It means that HierarchicalMap can contain "12,789" as a value, using comma as decimal separator, but the value space, like minInclusive, must be defined as "12.5".

Since:
0.7
See Also:
Schema

Constructor Summary
SchemaCollection()
          Constructs a SchemaCollection with the default locale and time zone.
SchemaCollection(java.util.Locale locale)
          Constructs a SchemaCollection with the default locale and specified time zone.
SchemaCollection(java.util.TimeZone timezone)
          Constructs a SchemaCollection with the specified locale and default time zone.
SchemaCollection(java.util.TimeZone timezone, java.util.Locale locale)
          Constructs a SchemaCollection with the specified locale and time zone.
 
Method Summary
 Schema get(java.io.InputStream schemaIn)
           This will return the Schema instance for XML Schema read from InputStream.
 Schema get(java.io.InputStream schemaIn, java.io.InputStream messageIn)
           This will return the Schema instance for XML Schema read from InputStream.
 Schema get(java.lang.String schema)
           This will return the instance for the specific XML Schema URL.
 Schema get(java.net.URL schemaURL)
           This will return the instance for the specific XML Schema URL.
 Schema get(java.net.URL schemaURL, java.net.URL messageURL)
           This will return the Schema instance for the specific XML Schema URL.
 java.util.Locale getLocale()
          Returns the current locale used for parsing and validation.
 java.util.ResourceBundle getMessage()
          Gets the resource bundle containing default messages.
 java.util.Locale getMessageLocale()
          Returns the current locale used for loading ResourceBundle containing the default messages.
 Schema getUnsafe(java.io.InputStream schemaIn, java.io.InputStream messageIn)
           This is equivalent to get(InputStream, InputStream) except that the returned Schema is unsafe.
 Schema getUnsafe(java.lang.String schema)
           This will return the instance for the specific XML Schema URL.
 Schema getUnsafe(java.net.URL schemaURL)
           This will return the instance for the specific XML Schema URL.
 Schema getUnsafe(java.net.URL schemaURL, java.net.URL messageURL)
           This is equivalent to get(URL, URL) except that the Schema returned is unsafe.
 java.lang.Object parseData(java.lang.String dataType, java.lang.Object value)
          Parses the value to corresponding java object using the same rule used during schema parsing.
 void remove(java.lang.String schema)
          Removes the specified schema from cache.
 void removeAll()
          Removes all the schema from cache.
 void setLocale(java.util.Locale locale)
          Sets the locale used for validation.
 Schema Unsafe(java.io.InputStream schemaIn)
           This will return the unsafe Schema instance for XML Schema read from InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchemaCollection

public SchemaCollection()
Constructs a SchemaCollection with the default locale and time zone.


SchemaCollection

public SchemaCollection(java.util.Locale locale)
Constructs a SchemaCollection with the default locale and specified time zone.

Parameters:
locale - the locale for number and date parsing.

SchemaCollection

public SchemaCollection(java.util.TimeZone timezone)
Constructs a SchemaCollection with the specified locale and default time zone.

Parameters:
timezone - the time zone to use.

SchemaCollection

public SchemaCollection(java.util.TimeZone timezone,
                        java.util.Locale locale)
Constructs a SchemaCollection with the specified locale and time zone.

Parameters:
timezone - the time zone to use.
locale - the locale for number and date parsing.
Method Detail

get

public Schema get(java.lang.String schema)
           throws SchemaException

This will return the instance for the specific XML Schema URL. And try to load the ResourceBundle containing error message from the same location of the schema document.

Parameters:
schema - String with URL of schema.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.

getUnsafe

public Schema getUnsafe(java.lang.String schema)
                 throws SchemaException

This will return the instance for the specific XML Schema URL. And try to load the ResourceBundle containing error message from the same location of the schema document. This is unsafe because its restriction is exposed.

Parameters:
schema - String with URL of schema.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.
Since:
0.8.0

get

public Schema get(java.net.URL schemaURL)
           throws SchemaException

This will return the instance for the specific XML Schema URL. And try to load the ResourceBundle containing error message from the same location of the schema document.

Parameters:
schemaURL - URL of schema.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.

getUnsafe

public Schema getUnsafe(java.net.URL schemaURL)
                 throws SchemaException

This will return the instance for the specific XML Schema URL. And try to load the ResourceBundle containing error message from the same location of the schema document. This is unsafe because its restriction is exposed.

Parameters:
schemaURL - URL of schema.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.
Since:
0.8.0

get

public Schema get(java.net.URL schemaURL,
                  java.net.URL messageURL)
           throws SchemaException

This will return the Schema instance for the specific XML Schema URL. If the schema has already parsed, it is returned from cache, otherwise a new instance is created, and then returned.

ResourceBundle can be associated to the schema for error messages. The name of ResourceBundle must be the same as name of schema document, replacing all dots ('.') by underscore ('_') including the file extension.

SchemaCollection will try to load the ResourceBundle according to locale passed to it. If there is no corresponding ResourceBundle, it will try to load from default locale but the data interpretation will keep using the original locale. Therefore, depending on the choosen locale, data interpretation can occur in one locale and error messges in another locale.

Parameters:
schemaURL - URL of schema.
messageURL - URL of ResourceBundle containing error messages.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.

getUnsafe

public Schema getUnsafe(java.net.URL schemaURL,
                        java.net.URL messageURL)
                 throws SchemaException

This is equivalent to get(URL, URL) except that the Schema returned is unsafe.

Parameters:
schemaURL - URL of schema.
messageURL - URL of ResourceBundle containing error messages.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.
Since:
0.8.0

get

public Schema get(java.io.InputStream schemaIn)
           throws SchemaException

This will return the Schema instance for XML Schema read from InputStream.

Parameters:
schemaIn - InputStream from where the schema is read.
Returns:
Schema - the instance of Schema, ready to use.
Throws:
SchemaException - when errors in parsing occur.
Since:
0.7.1

Unsafe

public Schema Unsafe(java.io.InputStream schemaIn)
              throws SchemaException

This will return the unsafe Schema instance for XML Schema read from InputStream.

Parameters:
schemaIn - InputStream from where the schema is read.
Returns:
Schema - the instance of Schema, ready to use.
Throws:
SchemaException - when errors in parsing occur.
Since:
0.8.0

get

public Schema get(java.io.InputStream schemaIn,
                  java.io.InputStream messageIn)
           throws SchemaException

This will return the Schema instance for XML Schema read from InputStream. If the schema has already parsed, it is returned from cache, otherwise a new instance is created, and then returned.

ResourceBundle can also be loaded from another InputStream.

Parameters:
schemaIn - InputStream from where the schema is read.
messageIn - InputStream from where the PropertyResourceBundle is read.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.
See Also:
get(URL schemaURL, URL messageURL)

getUnsafe

public Schema getUnsafe(java.io.InputStream schemaIn,
                        java.io.InputStream messageIn)
                 throws SchemaException

This is equivalent to get(InputStream, InputStream) except that the returned Schema is unsafe.

Parameters:
schemaIn - InputStream from where the schema is read.
messageIn - InputStream from where the PropertyResourceBundle is read.
Returns:
Schema - the instance, ready to use.
Throws:
SchemaException - when errors in parsing occur.
Since:
0.8.0
See Also:
get(URL schemaURL, URL messageURL)

remove

public void remove(java.lang.String schema)
Removes the specified schema from cache.

Parameters:
schema - String with URL of schema.

removeAll

public void removeAll()
Removes all the schema from cache.


parseData

public java.lang.Object parseData(java.lang.String dataType,
                                  java.lang.Object value)
Parses the value to corresponding java object using the same rule used during schema parsing. Only following datatypes are allowed: decimal, double, float, int, integer, long, date, time, dateTime and string.

Parameters:
dataType - target type.
value - value to be converted.
Returns:
converted value.
Since:
0.7.1

getLocale

public java.util.Locale getLocale()
Returns the current locale used for parsing and validation.

Returns:
current locale.

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale used for validation.

Parameters:
locale - used for validation.

getMessage

public java.util.ResourceBundle getMessage()
Gets the resource bundle containing default messages.

Returns:
the resource bundle containing default messages.

getMessageLocale

public java.util.Locale getMessageLocale()
Returns the current locale used for loading ResourceBundle containing the default messages.

Returns:
current locale for default messages.