org.sapia.validator
Class Vlad

java.lang.Object
  extended by org.sapia.validator.Vlad
All Implemented Interfaces:
org.sapia.util.xml.confix.ObjectHandlerIF

public class Vlad
extends Object
implements org.sapia.util.xml.confix.ObjectHandlerIF

An instance of this class encapsulates rule sets and rules. An instance of this class is used as such:

 Vlad v = new Vlad()
  .loadDefs("someRuleDefs.xml")
  .loadDefs("someOtherRuleDefs.xml")
  .load("someRuleSets.xml")
  .load("someOtherRuleSets.xml");
 

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site
See Also:
RuleSet, Rule

Field Summary
static String VLAD_RULES_XML
           
 
Constructor Summary
Vlad()
          Constructor for RuleConfig.
 
Method Summary
 void add(Rule rule)
          Adds a rule to this instance.
 void addGlobal(String name, Object value)
          Adds a global object to this instance.
 void addGlobals(Map values)
           
 void addNamespace(Namespace ns)
          Adds the given namespace to this instance.
 void addRuleSet(RuleSet set)
          Adds a rule set to this instance.
 Object getGlobal(String name)
           
 Map getGlobals()
           
 Rule getRule(String id)
          Returns the rule corresponding to the given ID.
 RuleSet getRuleSet(String id)
          Returns the rule set corresponding to the given identifier.
 void handleObject(String name, Object ruleOrRuleSet)
           
 Vlad load(File f)
          Loads a ruleset definition corresponding to the given file.
 Vlad load(InputStream is)
          Loads a ruleset definition corresponding to the given stream.
 Vlad load(String resource)
          Loads a ruleset definition file as a resource.
 Vlad loadDefs(File f)
          Loads a rule definition corresponding to the given file.
 Vlad loadDefs(InputStream is)
          Loads a rule definition corresponding to the given stream.
 Vlad loadDefs(String resource)
          Loads a rule definition file as a resource.
 Status validate(String ruleSetId, Object obj, Locale locale)
          Validates the given object, using the ruleset whose identifier is given, for the given Locale.
 Status validate(String ruleSetId, Object obj, Locale locale, Map contextMap)
          Validates the given object, using the ruleset whose identifier is given, for the given Locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VLAD_RULES_XML

public static final String VLAD_RULES_XML
See Also:
Constant Field Values
Constructor Detail

Vlad

public Vlad()
Constructor for RuleConfig.

Method Detail

addGlobal

public void addGlobal(String name,
                      Object value)
Adds a global object to this instance. Global values are kept as part of this instance and passed to every validation context (created when the validate method of this instance is called).

Use of this method should be done prior to using this instance for validation, at initialization time.

Parameters:
name - the name under which the given value should be kept.
value - an Object.
See Also:
ValidationContext

addGlobals

public void addGlobals(Map values)
Parameters:
values - a Map of values to add to this instance's global values.

getGlobal

public Object getGlobal(String name)
Parameters:
name - the name of an expected global value.
Returns:
the Object corresponding to the given name.

getGlobals

public Map getGlobals()
Returns:
an unmodifiable Map corresponding to the global values that this instance holds.

addRuleSet

public void addRuleSet(RuleSet set)
Adds a rule set to this instance.

Parameters:
set - a RuleSet.

getRuleSet

public RuleSet getRuleSet(String id)
                   throws IllegalArgumentException
Returns the rule set corresponding to the given identifier.

Parameters:
id - the identifier of the desired RuleSet.
Returns:
a RuleSet.
Throws:
IllegalArgumentException - if no rule set was found for the given identifier.

add

public void add(Rule rule)
Adds a rule to this instance.

Parameters:
a - Rule.

addNamespace

public void addNamespace(Namespace ns)
Adds the given namespace to this instance.

Parameters:
ns - a Namespace.

getRule

public Rule getRule(String id)
             throws IllegalArgumentException
Returns the rule corresponding to the given ID.

Parameters:
id - the identifier of the desired Rule.
Returns:
a Rule.
Throws:
IllegalArgumentException - if no rule was found for the given identifier.

validate

public Status validate(String ruleSetId,
                       Object obj,
                       Locale locale)
Validates the given object, using the ruleset whose identifier is given, for the given Locale. The latter is used to select the proper error messages (in the language that closest match the given Locale).

Parameters:
ruleSetId - the identifier of a RuleSet.
obj - an object to validate.
locale - a Locale.
Returns:
a Status.

validate

public Status validate(String ruleSetId,
                       Object obj,
                       Locale locale,
                       Map contextMap)
Validates the given object, using the ruleset whose identifier is given, for the given Locale. The latter is used to select the proper error messages (in the language that closest matches the given Locale).

Parameters:
ruleSetId - the identifier of a RuleSet.
obj - an object to validate.
locale - a Locale.
contextMap - a Map with additional context objects which can be acquired from validation code.
Returns:
a Status.

load

public Vlad load(String resource)
          throws IOException,
                 ConfigException
Loads a ruleset definition file as a resource. The file must in this case be present in the classpath.

Parameters:
resource - the name of a resource.
Throws:
IOException - if an IO error occurs while loading the resource, or if no resource exists for the given name.
ConfigException - if a problem occurs while initializing this instance with the given resource's content.

load

public Vlad load(File f)
          throws IOException,
                 ConfigException
Loads a ruleset definition corresponding to the given file.

Parameters:
f - a File
Throws:
IOException - if an IO error occurs while loading the file.
ConfigException - if a problem occurs while initializing this instance with the given file's content.

load

public Vlad load(InputStream is)
          throws IOException,
                 ConfigException
Loads a ruleset definition corresponding to the given stream.

Parameters:
is - an InputStream
Throws:
IOException - if an IO error occurs while loading the configuration stream.
ConfigException - if a problem occurs while initializing this instance with the given stream's content.

loadDefs

public Vlad loadDefs(File f)
              throws IOException,
                     ConfigException
Loads a rule definition corresponding to the given file.

Parameters:
f - a File
Throws:
IOException - if an IO error occurs while loading the file.
ConfigException - if a problem occurs while initializing this instance with the given file's content.

loadDefs

public Vlad loadDefs(String resource)
              throws IOException,
                     ConfigException
Loads a rule definition file as a resource. The file must in this case be present in the classpath.

Parameters:
resource - the name of a resource.
Throws:
IOException - if an IO error occurs while loading the resource, or if no resource exists for the given name.
ConfigException - if a problem occurs while initializing this instance with the given resource's content.

loadDefs

public Vlad loadDefs(InputStream is)
              throws IOException,
                     ConfigException
Loads a rule definition corresponding to the given stream.

Parameters:
is - an InputStream
Throws:
IOException - if an IO error occurs while loading the configuration stream.
ConfigException - if a problem occurs while initializing this instance with the given stream's content.

handleObject

public void handleObject(String name,
                         Object ruleOrRuleSet)
                  throws org.sapia.util.xml.confix.ConfigurationException
Specified by:
handleObject in interface org.sapia.util.xml.confix.ObjectHandlerIF
Throws:
org.sapia.util.xml.confix.ConfigurationException
See Also:
ObjectHandlerIF.handleObject(String, Object)


Copyright © 2002 Sapia Open Community, Inc. All Rights Reserved.