|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.tensegrity.graph.rule.RuleRegistry
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:
void put(Rule)Rule get(String)Rule remove(String)Rule remove(Rule)boolean contains(String)boolean contains(Rule)Iterator iterator()Iterator keysIterator()
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:
String getGraphRule()
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:
String getDefaultEdgeRule()void setDefaultEdgeRule(String)String getDefaultNodeRule()void setDefaultNodeRule(String)
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:
RuleFeedback getRuleFeedback()void setRuleFeedback(RuleFeedback)
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 |
public RuleRegistry()
RuleRegistry instance.
public RuleRegistry(RuleRegistry ruleregistry)
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.
ruleregistry - the RuleRegistry to copy from.| Method Detail |
public Rule put(Rule rule)
rule - the rule to register.
public Rule get(java.lang.String name)
name - unique identifier string for the rule.
public Rule remove(Rule rule)
RuleRegistry.
rule - the rule to remove.
public Rule remove(java.lang.String name)
RuleRegistry.
name - unique identifier string for the rule.
public boolean contains(java.lang.String name)
name - unique identifier string for the rule.
public boolean contains(Rule rule)
rule - the rule to check for in the registry.
public java.util.Iterator iterator()
public java.util.Iterator keysIterator()
public GraphRule getGraphRule()
GraphRule of this
RuleRegistry. The returned value may be null.
GraphRule of this RuleRegistry or
null.public java.lang.String getDefaultNodeRule()
NodeRule or
null if it is not set.
NodeRule or
null.public void setDefaultNodeRule(java.lang.String defaultnoderule)
NodeRule. The given name must
not be null and a NodeRule with the given name
must be registered at the RuleRegistry.
defaultnoderule - the name of the default NodeRule.public java.lang.String getDefaultEdgeRule()
EdgeRule or
null if it is not set.
EdgeRule or
null.public void setDefaultEdgeRule(java.lang.String defaultedgerule)
EdgeRule. The given name must
not be null and an EdgeRule with the given name
must be registered at the RuleRegistry.
defaultedgerule - the name of the default EdgeRule.public java.lang.String toString()
RuleRegistry.
The returned string representation is in XML format and
can be modified and then loaded again if desired.
RuleRegistry.public void setRuleFeedback(RuleFeedback rulefeedback)
RuleFeedback callback interface for this
RuleRegistry.
rulefeedback - the RuleFeedback callback interface for this
RuleRegistry. If the parameter is null then RuleFeedback
is disabled.public RuleFeedback getRuleFeedback()
RuleFeedback callback interface from this
RuleRegistry.
RuleRegistry, is null
when no RuleFeedback interface was set previously.public RuleRegistry deepCopy()
RuleRegistry.
RuleRegistry.
public static final RuleRegistry addRulesFromResource(RuleRegistry ruleregistry,
java.lang.String filename,
java.lang.Class resourceclass)
throws ReadException
RuleRegistry.
ruleregistry - the original rule registry, may be nullfilename - the filename of the resource.resourceclass - the class that provides the classloader to load
the resource, can be null.
RuleRegistry containing the rules from the given
registry and the rules that have been loaded from the resource.
ReadException - thrown if reading fails or if
filename is null.
public static final RuleRegistry loadRulesFromResource(java.lang.String filename,
java.lang.Class resourceclass)
throws ReadException
RuleRegistry for a given resource.
filename - the filename of the resource.resourceclass - the class that provides the classloader to load
the resource, can be null.
RuleRegistry that was loaded from the resource.
ReadException - thrown if reading fails or if
filename is null.public boolean equals(java.lang.Object obj)
public int hashCode()
public void addRuleRegistryListener(RuleRegistryListener listener)
listener - The listener to addpublic void removeRuleRegistryListener(RuleRegistryListener listener)
listener - The listener to remove
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||