public class GraphMatcher extends GraphAnalyzer
CompositeEntity
.GraphAnalyzer.IndexedList, GraphAnalyzer.IndexedLists, GraphAnalyzer.Path
Modifier and Type | Field and Description |
---|---|
static MatchCallback |
DEFAULT_CALLBACK
The default callback that always returns true.
|
Constructor and Description |
---|
GraphMatcher() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
_isIgnored(java.lang.Object object)
Return whether the object in the pattern should be ignored in the
pattern matching.
|
protected boolean |
_isOpaque(CompositeEntity entity)
Test whether the composite entity is opaque or not.
|
protected boolean |
_relationCollapsing(NamedObj container)
Return whether the interconnected relations should be collapsed into one
in pattern matching.
|
MatchResult |
getMatchResult()
Return the most recent match result, which the user should not modify.
|
boolean |
isSuccessful()
Return whether the last matching was successful.
|
static void |
main(java.lang.String[] args)
Match a rule file to a model file.
|
boolean |
match(Pattern pattern,
CompositeEntity hostGraph)
Match a pattern specified in the patternGraph to a model in
hostGraph.
|
static GraphMatcher |
match(java.lang.String ruleXMLFile,
java.lang.String hostXMLFile)
Match the rule stored in the file with name ruleXMLFile to the
model stored in the file with name hostXMLFile, whose top-level
should be an instance of
CompositeEntity . |
static GraphMatcher |
match(java.lang.String ruleXMLFile,
java.lang.String hostXMLFile,
MatchCallback callback)
Match the rule stored in the file with name ruleXMLFile to the
model stored in the file with name hostXMLFile, whose top-level
should be an instance of
CompositeEntity , and invoke
callback's MatchCallback.foundMatch(GraphMatcher)
method whenever a match is found. |
void |
setMatchCallback(MatchCallback callback)
Set the callback to be invoked by future calls to
match(Pattern, CompositeEntity) . |
findFirstChild, findFirstPath, findNextChild, findNextPath
public static final MatchCallback DEFAULT_CALLBACK
getMatchResult()
.public MatchResult getMatchResult()
MatchCallback
) is invoked (see setMatchCallback(MatchCallback)
), that callback routine can call this
method to retrieve the match result that has just been found.
Note that the returned match result object may be changed by future
matching. To maintain a copy, MatchResult.clone()
may be called
that returns a clone of it.
public boolean isSuccessful()
public static void main(java.lang.String[] args) throws java.lang.Exception
args
- The parameter array.java.lang.Exception
- If the rule file or the model file cannot be read.public boolean match(Pattern pattern, CompositeEntity hostGraph)
getMatchResult()
. A matching was successful if
at least one match result was found, and the callback (an instance
implementing MatchCallback
) returned true when it was
invoked.pattern
- The pattern.hostGraph
- The host graph.public static GraphMatcher match(java.lang.String ruleXMLFile, java.lang.String hostXMLFile) throws java.lang.Exception
CompositeEntity
. The first match result
(which is arbitrarily decided by the recursive algorithm) is recorded in
the returned matcher object. This result can be obtained with getMatchResult()
. If the match is unsuccessful, the match result is
empty, and isSuccessful()
of the returned matcher object
returns false.ruleXMLFile
- The name of the file in which the rule is stored.hostXMLFile
- The name of the file in which the model to be matched
is stored.isSuccessful()
of the matcher object returns
false, and getMatchResult()
returns an empty match.java.lang.Exception
- If the rule file or the model file cannot be read.match(String, String, MatchCallback)
public static GraphMatcher match(java.lang.String ruleXMLFile, java.lang.String hostXMLFile, MatchCallback callback) throws java.lang.Exception
CompositeEntity
, and invoke
callback's MatchCallback.foundMatch(GraphMatcher)
method whenever a match is found. If the callback returns true,
the match will terminate and no more matches will be reported;
otherwise, the match process continues, and the callback may be invoked
again. If callback is null, the behavior is the same
as match(String, String)
.ruleXMLFile
- The name of the file in which the rule is stored.hostXMLFile
- The name of the file in which the model to be matched
is stored.callback
- The callback to be invoked when matches are found.isSuccessful()
of the
matcher object returns false, and getMatchResult()
returns an empty match.java.lang.Exception
- If the rule file or the model file cannot be read.match(String, String)
public void setMatchCallback(MatchCallback callback)
match(Pattern, CompositeEntity)
.callback
- The callback. If it is null, the callback is
set to DEFAULT_CALLBACK
.match(Pattern, CompositeEntity)
protected boolean _isIgnored(java.lang.Object object)
_isIgnored
in class GraphAnalyzer
object
- The object to be tested.protected boolean _isOpaque(CompositeEntity entity)
CompositeActor
and it
is opaque. A composite actor is opaque if it has a director inside,
which means the new level of hierarchy that it creates cannot be
flattened, or it has a HierarchyFlatteningAttribute
attribute
inside with value true._isOpaque
in class GraphAnalyzer
entity
- The composite entity to be tested.CompositeActor
and it is opaque.protected boolean _relationCollapsing(NamedObj container)
_relationCollapsing
in class GraphAnalyzer
container
- The container of the relations.