com.bea.p13n.rules.model
Class RuleModelInfoSvc

java.lang.Object
  extended by com.bea.p13n.rules.model.RuleModelInfoSvc

public class RuleModelInfoSvc
extends Object

A singelton service to provide information to help with rules models.

The available ClauseModelInfo and RuleTypeInfo set can externally configured. The RuleModelInfoSvc singelton will configure itself by finding all the META-INF/rules-model-info.xml resources available to its ClassLoader. Each file resource will be parsed according to the XML schema for the http://www.bea.com/servers/p13n/xsd/rule-model-info namespace. This structure looks like:

<?xml version="1.0" encoding="ASCII"?>
 <rule-model-info
     xmlns="http://www.bea.com/servers/p13n/xsd/rule-model-info">
 
   <clause-model-info>
     <clause-type>clauseType1</clause-type>
     <clause-type>clauseType2</clause-type>
     <usage>condition|action</usage>
     <clause-model-class>ClauseModel implementation class name</clause-model-class>
     <recognizer>ClauseModelRecognizer implementation class name</recognizer>
     [<recognizer-priority>100</recognizer-priority>]
   </clause-model-info>

   <rule-type-info [allow-multiple-actions="true|false"]>
     <rule-type>ruleType1</rule-type>
     <rule-type>ruleType2</rule-type>
     [<recognizer>RuleTypeRecognizer implementation class name</recognizer>]
     [<recognizer-priority>100</recognizer-priority>]
     <clause-type>*</clause-type>
     <clause-type>available clauseType1</clause-type>
     <excluded-clause-type>available clauseType2</excluded-clause-type>
   </rule-type-info>
 
 </rule-model-info>
Each <clause-model-info> configures a ClauseModelInfo mapped to each contained <clause-type>. <usage> must be either condition (to signify a condition clause), action (for an action clause), or either (if it's available as either action or condition usage). <clause-model-class> is the fully qualified class name of the ClauseModel subclass that should be used. <recognizer> is the fully qualified class name of the ClauseModelRecognizer that should be used to recognize the <clause-type>. <recognizer-priority> is the priority of the recognizer as a positive integer (0 or greater), which controls the order in which recognizers execute. A higher numbers means it runs earlier and can recognize a clause before other recognizers.

Each <rule-type-info> configures a RuleTypeInfo mapped to each contained <rule-type>. The optional allow-multiple-actions attribute specifies whether the rule can have multiple actions; it defaults to true. <recognizer> is the fully qualified class name of the RuleTypeRecognizer that should be used to recognize the <rule-type>. <recognizer-priority> is the priority of the recognizer as a positive integer (0 or greater), which controls the order in which recognizers execute. A higher numbers means it runs earlier and can recognize a clause before other recognizers. Each <clause-type> specified is an available clause type for the rule-type; each should have a corresponding <clause-model-info> entry in one of the META-INF/rule-model-info.xml resources. * can be used to signify that any clause type is available for this rule type. <excluded-clause-type> will exclude a clause type from this rule-type; similarly, * will exclude all clause types not specified listed in a <clause-type> element.

Mulitple registrations of the same <clause-type> or <rule-type> are non-deterministic. Additionally, a ClauseModelRecognizer or RuleTypeRecognizer that recognizes outside of its <clause-model> or <rule-type-info> are non-deterministic.

Note: turning on debug for this class (via a com.bea.p13n.util.debug.Debug style debug.properties) will show the load sequencing, including any errors in the META-INF/rule-model-info.xml files.


Nested Class Summary
static class RuleModelInfoSvc.ClauseModelInfo
          Base information about clause models.
static class RuleModelInfoSvc.RuleTypeInfo
          Information about rule-types.
 
Field Summary
static int DEF_RECOGNIZER_PRIORITY
           
 
Method Summary
 void addClauseModelInfo(RuleModelInfoSvc.ClauseModelInfo info)
          Add a clause model configuration to this instance.
 void addRuleTypeInfo(RuleModelInfoSvc.RuleTypeInfo info)
          Add a rule type configuration to this instance.
 boolean allowsMultipleActions(String ruleType)
          Tell if the specified rule type allows multiple actions.
 boolean areEquivalentTypeAliases(String type1, String type2)
          Tell if 2 typeAliases are equivalent.
static ClauseModel createClauseModel(String clauseType, Class<? extends ClauseModel> clauseClass, org.apache.xmlbeans.XmlObject clause)
          Helper method to construct an initialized ClauseModel.
 ClauseModel createNewClauseModel(String clauseType)
          Get a new, uninitialized clause model for the specified clause type.
static RuleModelInfoSvc get()
          Get the singleton instance of this.
 String[] getActionClauseTypes(String ruleType)
          Get the supported condition clause types for the specified rule type.
 String[] getAvailableClauseTypes(String ruleType)
          Get the supported clause types for the specified rule type.
 ClauseModel getClauseModel(String clauseType, org.apache.xmlbeans.XmlObject clause)
          Get a clause model instance initialized against the specified clause structure.
 ClauseModel getClauseModel(org.apache.xmlbeans.XmlObject clause)
          Get a clause model instance initialized against the specified clause structure.
 Map<String,RuleModelInfoSvc.ClauseModelInfo> getClauseModelInfos()
          Get the map of clauseType to ClauseModelInfo objects.
 String getClauseType(org.apache.xmlbeans.XmlObject clause)
          Get the clause type for the specified clause structure.
 String[] getConditionClauseTypes(String ruleType)
          Get the supported condition clause types for the specified rule type.
 RuleModel getRuleModel(String ruleType)
          Create a new, empty RuleModel of the specified ruleType.
 String getRuleType(RuleModel rule)
          Get the String for the specified rule.
 Map<String,RuleModelInfoSvc.RuleTypeInfo> getRuleTypeInfos()
          Get the map of ruleType to RuleTypeInfo objects.
 Map<String,String> getTypeAliasMap()
          Get the map of type-alias short-name to fully-qualified java class name for type-aliases.
 boolean isActionClause(String clauseType)
          Determine if a clause type is available as an action.
 boolean isConditionClause(String clauseType)
          Determine if a clause type is available as a condition.
 boolean isKnownClauseType(String clauseType)
          Tell if the specified clause type is registered.
static void loadConfiguration(RuleModelInfoSvc svc, URL file, ClassLoader cl)
          Load the configuration in the specified file conforming to the http://www.bea.com/servers/p13n/xsd/rule-model-info schema.
static void loadDefaultConfiguration(RuleModelInfoSvc svc)
          Load the default ClauseModelInfo and RuleTypeInfo configuration into the specified service instance.
static void loadDefaultConfiguration(RuleModelInfoSvc svc, ClassLoader cl)
          Load the default ClauseModelInfo and RuleTypeInfo configuration into the specified service instance.
 boolean removeClauseModelInfo(String clauseType)
          Remove a clause model configuration to this instance.
 boolean removeRuleTypeInfo(String ruleType)
          Remove a rule type configuration to this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEF_RECOGNIZER_PRIORITY

public static final int DEF_RECOGNIZER_PRIORITY
See Also
Constants Summary
Method Detail

get

public static RuleModelInfoSvc get()
Get the singleton instance of this.

See Also
loadDefaultConfiguration(RuleModelInfoSvc)

loadDefaultConfiguration

public static void loadDefaultConfiguration(RuleModelInfoSvc svc)
                                     throws IOException
Load the default ClauseModelInfo and RuleTypeInfo configuration into the specified service instance. This will find all META-INF/rule-model-info.xml files in the classpath at svc's ClassLoader or higher, parse them with the http://www.bea.com/servers/p13n/xsd/rule-model-info XML schema, and load the clause model and rule type info.

Throws
IOException - on error loading default rule model info configuration.

loadDefaultConfiguration

public static void loadDefaultConfiguration(RuleModelInfoSvc svc,
                                            ClassLoader cl)
                                     throws IOException
Load the default ClauseModelInfo and RuleTypeInfo configuration into the specified service instance. This will find all META-INF/rule-model-info.xml files in the classpath at the ClassLoader or higher, parse them with the http://www.bea.com/servers/p13n/xsd/rule-model-info XML schema, and load the clause model and rule type info.

Parameters
svc - the instance to load.
cl - the ClassLoader to load from.
Throws
IOException - on error loading default rule model info configuration.
See Also
loadConfiguration(RuleModelInfoSvc, URL, ClassLoader)

loadConfiguration

public static void loadConfiguration(RuleModelInfoSvc svc,
                                     URL file,
                                     ClassLoader cl)
Load the configuration in the specified file conforming to the http://www.bea.com/servers/p13n/xsd/rule-model-info schema.

Parameters
svc - the instance to load
file - the URL to the configuration file.
cl - the ClassLoader to use to load objects.

createClauseModel

public static ClauseModel createClauseModel(String clauseType,
                                            Class<? extends ClauseModel> clauseClass,
                                            org.apache.xmlbeans.XmlObject clause)
                                     throws IllegalArgumentException
Helper method to construct an initialized ClauseModel.

Parameters
clause - the xml structure of the clause or null for a new, empty instance.
Returns
an appropriately-typed initialized ClauseModel instance.
Throws
IllegalArgumentException - if clause can't be instantied or isn't the correct structure for the clause class.

getTypeAliasMap

public Map<String,String> getTypeAliasMap()
Get the map of type-alias short-name to fully-qualified java class name for type-aliases.

Returns
an unmodifiable map.

areEquivalentTypeAliases

public boolean areEquivalentTypeAliases(String type1,
                                        String type2)
Tell if 2 typeAliases are equivalent. This will check against the fully-qualified type names for short typeAliases.


getClauseModelInfos

public Map<String,RuleModelInfoSvc.ClauseModelInfo> getClauseModelInfos()
Get the map of clauseType to ClauseModelInfo objects.

Returns
an unmodifiable map.

addClauseModelInfo

public void addClauseModelInfo(RuleModelInfoSvc.ClauseModelInfo info)
Add a clause model configuration to this instance.


removeClauseModelInfo

public boolean removeClauseModelInfo(String clauseType)
Remove a clause model configuration to this instance.


getRuleTypeInfos

public Map<String,RuleModelInfoSvc.RuleTypeInfo> getRuleTypeInfos()
Get the map of ruleType to RuleTypeInfo objects.

Returns
an unmodifiable map.

addRuleTypeInfo

public void addRuleTypeInfo(RuleModelInfoSvc.RuleTypeInfo info)
Add a rule type configuration to this instance.


removeRuleTypeInfo

public boolean removeRuleTypeInfo(String ruleType)
Remove a rule type configuration to this instance.


getRuleType

public String getRuleType(RuleModel rule)
Get the String for the specified rule.


allowsMultipleActions

public boolean allowsMultipleActions(String ruleType)
Tell if the specified rule type allows multiple actions.


getRuleModel

public RuleModel getRuleModel(String ruleType)
Create a new, empty RuleModel of the specified ruleType.


isKnownClauseType

public boolean isKnownClauseType(String clauseType)
Tell if the specified clause type is registered.


getClauseType

public String getClauseType(org.apache.xmlbeans.XmlObject clause)
Get the clause type for the specified clause structure.


isConditionClause

public boolean isConditionClause(String clauseType)
Determine if a clause type is available as a condition.


isActionClause

public boolean isActionClause(String clauseType)
Determine if a clause type is available as an action.


getClauseModel

public ClauseModel getClauseModel(String clauseType,
                                  org.apache.xmlbeans.XmlObject clause)
Get a clause model instance initialized against the specified clause structure.


getClauseModel

public ClauseModel getClauseModel(org.apache.xmlbeans.XmlObject clause)
Get a clause model instance initialized against the specified clause structure.


createNewClauseModel

public ClauseModel createNewClauseModel(String clauseType)
Get a new, uninitialized clause model for the specified clause type.


getAvailableClauseTypes

public String[] getAvailableClauseTypes(String ruleType)
Get the supported clause types for the specified rule type.


getConditionClauseTypes

public String[] getConditionClauseTypes(String ruleType)
Get the supported condition clause types for the specified rule type.


getActionClauseTypes

public String[] getActionClauseTypes(String ruleType)
Get the supported condition clause types for the specified rule type.



Copyright © 2011, Oracle. All rights reserved.