com.tensegrity.graph.rule
Class RuleRegistry

java.lang.Object
  extended bycom.tensegrity.graph.rule.RuleRegistry
All Implemented Interfaces:
java.io.Serializable

public final class RuleRegistry
extends java.lang.Object
implements java.io.Serializable

Class RuleRegistry is primarily responsible for managing Rule instances. Rule registration and client lookup are also supported as well as the ability to define so-called default rules for visual objects (instances of classes VisualNode and VisualEdge).

Additionally, a RuleRegistry allows client code to register a RuleFeedback instance which gets notified whenever a Rule is triggered.

In order to manage Rule instances, a RuleRegistry behaves like a hash-map.
When inserting Rule instances into the RuleRegistry, the name of the Rule is used as the key value. A Rule registered in this way can be later accessed using this name. One can iterate over the key (the rule names) of the registered Rule instances as well as over the registered Rule objects themselves. It is even possible to remove registered Rule instances either by name or by providing a reference to the Rule. Finally, it is possible to ask a RuleRegistry if a certain Rule instance has been registered with it.
The container methods a RuleRegistry provides are given below:

A GraphRule is treated in a special way. The RuleRegistry supports registration of one GraphRule instance only. In the context of the GraphAPI, this single GraphRule object is used globally for each instance of a VisualGraph.
The GraphRule is defined through the normal put operation. Whenever an instance of a GraphRule is registered with a RuleRegistry, it is taken as the new global graph-rule.
The methods the RuleRegistry provides in order to support the graph-rule are given below:

The RuleRegistry supports the definition of a default EdgeRule for VisualEdges and a default NodeRule for VisualNodes. In the context of the GraphAPI these default rules are used to assign a rule to any VisualGraphObject that is added to a VisualGraph that hasn't assigned one. The methods the RuleRegistry provides in order to support the default rules are given below:

As mentioned beforehand the RuleRegistry allows to register an instance of a RuleFeedback in order to get notifications whenever a rule check has passed or was rejected.
The methods provided by the RuleRegistry in order to support it are listed below:

Version:
$Id: RuleRegistry.java,v 1.50 2006/03/02 10:43:58 BurkhardWick Exp $
Author:
Stepan Rutz
See Also:
GraphRule, EdgeRule, NodeRule, RuleFeedback, VisualGraph, VisualNode, VisualEdge, Serialized Form

Constructor Summary
RuleRegistry()
          Constructs a new empty RuleRegistry instance.
RuleRegistry(RuleRegistry ruleregistry)
          Copy constructor for a RuleRegistry.
 
Method Summary
 void addRuleRegistryListener(RuleRegistryListener listener)
          Adds a listener that will be notified of rule changes
static RuleRegistry addRulesFromResource(RuleRegistry ruleregistry, java.lang.String filename, java.lang.Class resourceclass)
          Method that adds rules from a given resource to a RuleRegistry.
 boolean contains(Rule rule)
          Checks whether a rule is already registered in the rule registry.
 boolean contains(java.lang.String name)
          Checks whether a rule is already registered in the rule registry.
 RuleRegistry deepCopy()
          Returns a deep copy of the RuleRegistry.
 boolean equals(java.lang.Object obj)
           
 Rule get(java.lang.String name)
          Looks up a rule in the map and returns it, null if none is found with the given name.
 java.lang.String getDefaultEdgeRule()
          Returns the name of the default EdgeRule or null if it is not set.
 java.lang.String getDefaultNodeRule()
          Returns the name of the default NodeRule or null if it is not set.
 GraphRule getGraphRule()
          Returns the current GraphRule of this RuleRegistry.
 RuleFeedback getRuleFeedback()
          Returns the RuleFeedback callback interface from this RuleRegistry.
 int hashCode()
           
 java.util.Iterator iterator()
          Returns an iterator for all registered rules.
 java.util.Iterator keysIterator()
          Returns an iterator for all registered rule names.
static RuleRegistry loadRulesFromResource(java.lang.String filename, java.lang.Class resourceclass)
          Method that loads the RuleRegistry for a given resource.
 Rule put(Rule rule)
          Registers a new rule in the registry with its name..
 Rule remove(Rule rule)
          Removes a rule from the RuleRegistry.
 Rule remove(java.lang.String name)
          Removes a rule by name from the RuleRegistry.
 void removeRuleRegistryListener(RuleRegistryListener listener)
          Removes a listener for rule change notifications
 void setDefaultEdgeRule(java.lang.String defaultedgerule)
          Sets the name of the default EdgeRule.
 void setDefaultNodeRule(java.lang.String defaultnoderule)
          Sets the name of the default NodeRule.
 void setRuleFeedback(RuleFeedback rulefeedback)
          Sets the RuleFeedback callback interface for this RuleRegistry.
 java.lang.String toString()
          Returns a string representation of this RuleRegistry.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RuleRegistry

public RuleRegistry()
Constructs a new empty RuleRegistry instance.


RuleRegistry

public RuleRegistry(RuleRegistry ruleregistry)
Copy constructor for a RuleRegistry. All the rules in the given source registry are recursively deepcopied.

The RuleFeedback reference that might be registered is not deep-copied and set to null in this instance.

Parameters:
ruleregistry - the RuleRegistry to copy from.
Method Detail

put

public Rule put(Rule rule)
Registers a new rule in the registry with its name..

Parameters:
rule - the rule to register.
Returns:
previous rule associated with the name. or null if no value was associated previously.

Find more information in the class documentation


get

public Rule get(java.lang.String name)
Looks up a rule in the map and returns it, null if none is found with the given name.

Parameters:
name - unique identifier string for the rule.
Returns:
the rule associated with the given name, or null if no rule was found.

Find more information in the class documentation


remove

public Rule remove(Rule rule)
Removes a rule from the RuleRegistry.

Parameters:
rule - the rule to remove.
Returns:
the rule that was removed or null if the specified rule was not previously registered and thus not removed.

Find more information in the class documentation


remove

public Rule remove(java.lang.String name)
Removes a rule by name from the RuleRegistry.

Parameters:
name - unique identifier string for the rule.
Returns:
the rule that was removed or null if the specified rule was not previously registered and thus not removed.

Find more information in the class documentation


contains

public boolean contains(java.lang.String name)
Checks whether a rule is already registered in the rule registry.

Parameters:
name - unique identifier string for the rule.
Returns:
true if the rule is registered already, otherwise false.

Find more information in the class documentation


contains

public boolean contains(Rule rule)
Checks whether a rule is already registered in the rule registry.

Parameters:
rule - the rule to check for in the registry.
Returns:
true if the rule is registered already, otherwise false.

Find more information in the class documentation


iterator

public java.util.Iterator iterator()
Returns an iterator for all registered rules.

Returns:
iterator for all registered rules.

Find more information in the class documentation


keysIterator

public java.util.Iterator keysIterator()
Returns an iterator for all registered rule names.

Returns:
iterator for all registered rule names.

Find more information in the class documentation


getGraphRule

public GraphRule getGraphRule()
Returns the current GraphRule of this RuleRegistry. The returned value may be null.

Returns:
the GraphRule of this RuleRegistry or null.

Find more information in the class documentation


getDefaultNodeRule

public java.lang.String getDefaultNodeRule()
Returns the name of the default NodeRule or null if it is not set.

Returns:
the name of the default NodeRule or null.

Find more information in the class documentation


setDefaultNodeRule

public void setDefaultNodeRule(java.lang.String defaultnoderule)
Sets the name of the default NodeRule. The given name must not be null and a NodeRule with the given name must be registered at the RuleRegistry.

Parameters:
defaultnoderule - the name of the default NodeRule.

Find more information in the class documentation


getDefaultEdgeRule

public java.lang.String getDefaultEdgeRule()
Returns the name of the default EdgeRule or null if it is not set.

Returns:
the name of the default EdgeRule or null.

Find more information in the class documentation


setDefaultEdgeRule

public void setDefaultEdgeRule(java.lang.String defaultedgerule)
Sets the name of the default EdgeRule. The given name must not be null and an EdgeRule with the given name must be registered at the RuleRegistry.

Parameters:
defaultedgerule - the name of the default EdgeRule.

Find more information in the class documentation


toString

public java.lang.String toString()
Returns a string representation of this RuleRegistry. The returned string representation is in XML format and can be modified and then loaded again if desired.

Returns:
string representation of this RuleRegistry.

setRuleFeedback

public void setRuleFeedback(RuleFeedback rulefeedback)
Sets the RuleFeedback callback interface for this RuleRegistry.

Parameters:
rulefeedback - the RuleFeedback callback interface for this RuleRegistry. If the parameter is null then RuleFeedback is disabled.

Find more information in the class documentation


getRuleFeedback

public RuleFeedback getRuleFeedback()
Returns the RuleFeedback callback interface from this RuleRegistry.

Returns:
the feedback callback interface from this RuleRegistry, is null when no RuleFeedback interface was set previously.

Find more information in the class documentation


deepCopy

public RuleRegistry deepCopy()
Returns a deep copy of the RuleRegistry.

Returns:
a deep copy of the RuleRegistry.

addRulesFromResource

public static final RuleRegistry addRulesFromResource(RuleRegistry ruleregistry,
                                                      java.lang.String filename,
                                                      java.lang.Class resourceclass)
                                               throws ReadException
Method that adds rules from a given resource to a RuleRegistry.

Parameters:
ruleregistry - the original rule registry, may be null
filename - the filename of the resource.
resourceclass - the class that provides the classloader to load the resource, can be null.
Returns:
a new RuleRegistry containing the rules from the given registry and the rules that have been loaded from the resource.
Throws:
ReadException - thrown if reading fails or if filename is null.

loadRulesFromResource

public static final RuleRegistry loadRulesFromResource(java.lang.String filename,
                                                       java.lang.Class resourceclass)
                                                throws ReadException
Method that loads the RuleRegistry for a given resource.

Parameters:
filename - the filename of the resource.
resourceclass - the class that provides the classloader to load the resource, can be null.
Returns:
the RuleRegistry that was loaded from the resource.
Throws:
ReadException - thrown if reading fails or if filename is null.

equals

public boolean equals(java.lang.Object obj)

hashCode

public int hashCode()

addRuleRegistryListener

public void addRuleRegistryListener(RuleRegistryListener listener)
Adds a listener that will be notified of rule changes

Parameters:
listener - The listener to add

removeRuleRegistryListener

public void removeRuleRegistryListener(RuleRegistryListener listener)
Removes a listener for rule change notifications

Parameters:
listener - The listener to remove


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.