|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.dhmp.util.xml.Schema
Schema represents the XML Schema document and can be used to validate the
syntax and several other constraints for HierarchicalMap. Use
SchemaCollection to get the Schema class. For example:
The
validation for numbers are locale dependent. The locale is obtained from
SchemaCollection's locale. Note that Schema always uses the locale assigned
for parsing but the ResourceBundle's locale depends on availability of
suitable resource. There are thee main methods: validate, replace and
transform validate returns true or false depending on the content of
HierarchicalMap passed to it. If this content obeys the structure defined by
xml schema document passed the result will be true. replace also returns true
or false checking against xsd, but it also substitutes the content of
HierarchicalMap into corresponding data type defined in xsd. That is, if the
xsd data type is long, the corresponding leaf will be converted to
java.util.Long and so on. transform tries to fit the HierarchicalMap into
valid structure as of xsd definition. the error message will be appended to
HierarchicalMap at nearest node. If the element does not satisfies the xsd
definition, the error message will be added under "_error" node.
SchemaCollection schemas = new SchemaCollection();
Schema schema = schemas.get("file:/temp/test.xsd");
SchemaCollection
Field Summary | |
protected boolean |
addErrorMessage
If true, add error message during map transformation |
protected HierarchicalMap |
constraints
The constraints for this XML Schema |
protected java.util.ResourceBundle |
defaultmessages
ResourceBundle containing messages used for default message. |
static int |
DO_NOT_REPLACE_VALUE
|
protected boolean |
fixedConstraints
control if constraints can be changed externally |
static int |
FORMAT_VALUE
|
protected java.util.Locale |
locale
locale used for messages |
protected java.util.ResourceBundle |
messages
Optional ResourceBundle containing error messages for this XML Schema |
static int |
REPLACE_VALUE
|
static int |
REPLACEUSINGFORMAT_VALUE
|
protected java.lang.String |
resourceLocation
ResourceBundle location. |
protected java.lang.String |
schemaLocation
The URL of the XML Schema for this SchemaCollection |
static int |
TRANSFORM_VALUE
|
Method Summary | |
boolean |
addErrorMessage()
return the current value of addErrorMessage. |
HierarchicalMap |
getConstraint(java.lang.Object key)
Returns a HierarchicalMap containing constraint for specific node. |
HierarchicalMap |
getConstraints()
Returns a HierarchicalMap that represents the parsed schema. |
java.lang.String |
getDefaultMessage(java.lang.String key)
Gets the corresponding default error message from ResourceBundle. |
java.util.Locale |
getLocale()
Returns the locale used when parsing number or date values. |
java.lang.String |
getMessage(java.lang.String key)
Gets the corresponding schema specific error message from ResourceBundle. |
java.util.Locale |
getMessageLocale()
Returns the locale used when retrieving error message from ResourceBundle. |
protected java.lang.Object |
getNewValue(Validator val,
java.lang.String name,
java.lang.Object value,
HierarchicalMap constraints,
Schema schema,
HierarchicalMap messages,
int replace)
|
java.lang.String |
getResourceLocation()
Returns the location of ResourceBundle containing the error messages for this schema. |
java.lang.String |
getSchemaLocation()
Returns the location of schema document containing the valid XML Schema Document. |
protected void |
handleElement(HierarchicalMap result,
HierarchicalMap root,
Validator val,
java.lang.String name,
java.lang.Object value,
HierarchicalMap constraints,
Schema schema,
boolean addMessage)
|
boolean |
hasFixedConstraints()
Returs if this Schema's constraints is fixed or can be changed. |
boolean |
hasMessage()
Returns true if the ResourceBundle containing the error message has successfully loaded. |
void |
init(HierarchicalMap paramMap)
Initializes this class using the configuration passed. |
void |
init(java.lang.String config)
Initializes this class using the configuration passed. |
boolean |
isUseDefaultMessage()
Returs if this Schema is using default message. |
boolean |
replace(HierarchicalMap hmap)
Validate the HierarchicalMap against current schema. |
boolean |
replace(HierarchicalMap hmap,
java.lang.StringBuffer messages)
Validate the HierarchicalMap against current schema and also returns the error message. |
boolean |
replace(java.lang.Object key,
HierarchicalMap hmap)
Validate the HierarchicalMap against subset of the current schema.. |
boolean |
replace(java.lang.Object key,
HierarchicalMap hmap,
java.lang.StringBuffer messages)
Validate the HierarchicalMap against subset of the current schema and also returns the error message. |
void |
setAddErrorMessage(boolean newvalue)
If true, error messages are added as "_error" node during transform. |
void |
setFixedConstraints(boolean fixedConstraints)
Sets if this Schema's constraints can be changed or fixed. |
void |
setUseDefaultMessage(boolean useDefaultMessage)
Sets if default message should be appended when there is no error message defined. |
HierarchicalMap |
transform(HierarchicalMap original)
|
HierarchicalMap |
transform(HierarchicalMap original,
HierarchicalMap constraints)
|
HierarchicalMap |
transform(HierarchicalMap root,
HierarchicalMap original,
HierarchicalMap constraints)
Transform original map into structure define by constraints. |
protected HierarchicalMap |
transform(HierarchicalMap root,
HierarchicalMap original,
HierarchicalMap constraints,
boolean addMessage)
|
HierarchicalMap |
transform(java.lang.String key,
HierarchicalMap original)
|
boolean |
validate(HierarchicalMap hmap)
Validate the HierarchicalMap against current schema. |
boolean |
validate(HierarchicalMap hmap,
java.lang.StringBuffer messages)
Validate the HierarchicalMap against current schema and also returns the error message. |
boolean |
validate(java.lang.Object key,
java.lang.Object value)
Validate the HierarchicalMap against subset of the current schema. |
boolean |
validate(java.lang.Object key,
java.lang.Object value,
java.lang.StringBuffer messages)
Validate the HierarchicalMap against subset of the current schema and also returns the error message. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String schemaLocation
SchemaCollection
protected java.util.Locale locale
protected HierarchicalMap constraints
protected boolean fixedConstraints
protected java.util.ResourceBundle messages
protected java.util.ResourceBundle defaultmessages
protected boolean addErrorMessage
protected java.lang.String resourceLocation
public static final int DO_NOT_REPLACE_VALUE
public static final int REPLACE_VALUE
public static final int FORMAT_VALUE
public static final int REPLACEUSINGFORMAT_VALUE
public static final int TRANSFORM_VALUE
Method Detail |
public void init(java.lang.String config)
Valid configurations are (bold for default value) :
config
- configuration used by this class.public void init(HierarchicalMap paramMap)
paramMap
- HierarchicalMap containing the configuration used by this
class.public boolean validate(HierarchicalMap hmap)
hmap
- HierarchicalMap beeing validated.
public boolean validate(HierarchicalMap hmap, java.lang.StringBuffer messages)
hmap
- HierarchicalMap beeing validated.messages
- error message during validation are appended.
public boolean validate(java.lang.Object key, java.lang.Object value)
key
- specify which subset of current schema should be used.value
- Object beeing validated.
public boolean validate(java.lang.Object key, java.lang.Object value, java.lang.StringBuffer messages)
key
- specify which subset of current schema should be used.value
- Object beeing validated.messages
- error message during validation are appended.
public boolean replace(HierarchicalMap hmap)
hmap
- HierarchicalMap beeing validated.
public boolean replace(HierarchicalMap hmap, java.lang.StringBuffer messages)
hmap
- HierarchicalMap beeing validated.messages
- error message during validation are appended.
public boolean replace(java.lang.Object key, HierarchicalMap hmap)
key
- specify which subset of current schema should be used.hmap
- HierarchicalMap beeing validated.
public boolean replace(java.lang.Object key, HierarchicalMap hmap, java.lang.StringBuffer messages)
key
- specify which subset of current schema should be used.hmap
- HierarchicalMap beeing validated.messages
- error message during validation are appended.
public HierarchicalMap transform(HierarchicalMap original)
public HierarchicalMap transform(java.lang.String key, HierarchicalMap original)
public HierarchicalMap transform(HierarchicalMap original, HierarchicalMap constraints)
public HierarchicalMap transform(HierarchicalMap root, HierarchicalMap original, HierarchicalMap constraints)
root
- used internally to keep the root node of iteration.original
- map containing the values to be mapped to.constraints
- map containing the schema.
protected HierarchicalMap transform(HierarchicalMap root, HierarchicalMap original, HierarchicalMap constraints, boolean addMessage)
protected void handleElement(HierarchicalMap result, HierarchicalMap root, Validator val, java.lang.String name, java.lang.Object value, HierarchicalMap constraints, Schema schema, boolean addMessage)
protected java.lang.Object getNewValue(Validator val, java.lang.String name, java.lang.Object value, HierarchicalMap constraints, Schema schema, HierarchicalMap messages, int replace)
public java.lang.String getResourceLocation()
SchemaCollection.get(URL, URL)
public java.lang.String getSchemaLocation()
public HierarchicalMap getConstraints()
public HierarchicalMap getConstraint(java.lang.Object key)
key
- the key for the desired node.
public void setUseDefaultMessage(boolean useDefaultMessage)
useDefaultMessage
- true if default message should be used when there is no error
message defined.public boolean isUseDefaultMessage()
public void setFixedConstraints(boolean fixedConstraints)
fixedConstraints
- true if constraint is fixed (default).public boolean hasFixedConstraints()
public java.util.Locale getLocale()
public java.util.Locale getMessageLocale()
public java.lang.String getMessage(java.lang.String key)
key
- the key for the desired message.
public java.lang.String getDefaultMessage(java.lang.String key)
key
- the key for the desired message.
public boolean hasMessage()
public void setAddErrorMessage(boolean newvalue)
newvalue
- boolean value to be set.public boolean addErrorMessage()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |