org.eigenbase.jmi
Class JmiDependencyMappedTransform

java.lang.Object
  extended by org.eigenbase.jmi.JmiDependencyMappedTransform
All Implemented Interfaces:
JmiDependencyTransform

public class JmiDependencyMappedTransform
extends Object
implements JmiDependencyTransform

JmiDependencyMappedTransform implements JmiDependencyTransform by keeping a map from JmiAssocEdge to JmiAssocMapping.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/jmi/JmiDependencyMappedTransform.java#10 $
Author:
John Sichi

Nested Class Summary
private static class JmiDependencyMappedTransform.AssocRule
           
 
Field Summary
private  Map<JmiAssocEdge,List<JmiDependencyMappedTransform.AssocRule>> map
           
private  JmiModelView modelView
           
private  boolean produceSelfLoops
           
private  Comparator<RefBaseObject> tieBreaker
           
 
Constructor Summary
JmiDependencyMappedTransform(JmiModelView modelView, boolean produceSelfLoops)
          Creates a new mapped transform.
 
Method Summary
private  void applyRefinedRules(List<JmiDependencyMappedTransform.AssocRule> rules, RefObject source, RefObject target, Collection result, JmiAssocMapping mapping)
           
private  MofClass convertRefClassToMof(RefClass c)
           
 Collection<RefObject> getSourceNeighbors(RefObject target, Collection<RefObject> candidates, JmiAssocMapping mapping)
          Searches a collection of candidate objects, returning only those which are reachable via links corresponding to mapped incoming model edges to a target object.
 Comparator<RefBaseObject> getTieBreaker()
           
 void setAllByAggregation(AggregationKind requestedKind, JmiAssocMapping mapping)
          Sets mappings for all associations with a given aggregation kind, discarding any existing mappings for those associations.
 void setByRefAssoc(RefAssociation assoc, JmiAssocMapping mapping)
          Sets mapping for a specific association, discarding any existing mappings for that association.
 void setByRefAssocRefined(RefAssociation assoc, JmiAssocMapping mapping, RefClass sourceClass, RefClass targetClass)
          Sets mapping for a specific association, refining the rule to only apply in the context of specific end classes.
 void setTieBreaker(Comparator<RefBaseObject> tieBreaker)
          Sets a new tie-breaker.
 boolean shouldProduceSelfLoops()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private final Map<JmiAssocEdge,List<JmiDependencyMappedTransform.AssocRule>> map

modelView

private final JmiModelView modelView

produceSelfLoops

private final boolean produceSelfLoops

tieBreaker

private Comparator<RefBaseObject> tieBreaker
Constructor Detail

JmiDependencyMappedTransform

public JmiDependencyMappedTransform(JmiModelView modelView,
                                    boolean produceSelfLoops)
Creates a new mapped transform. Initially, all associations are mapped to JmiAssocMapping.REMOVAL. Callers should use setXXX methods to change mappings.

Parameters:
modelView - the model for which dependencies are being defined
produceSelfLoops - see JmiDependencyTransform.shouldProduceSelfLoops()
Method Detail

getTieBreaker

public Comparator<RefBaseObject> getTieBreaker()
Specified by:
getTieBreaker in interface JmiDependencyTransform
Returns:
a comparator which can be used for breaking ties in ordering, or null if no tie-breaking is desired (tie-breaking provides stability during diff-based testing, but adds processing overhead)

setTieBreaker

public void setTieBreaker(Comparator<RefBaseObject> tieBreaker)
Sets a new tie-breaker. (Default after construction is JmiMofIdComparator.instance.)

Parameters:
tieBreaker - new tie-breaker, or null to disable tie-breaking

getSourceNeighbors

public Collection<RefObject> getSourceNeighbors(RefObject target,
                                                Collection<RefObject> candidates,
                                                JmiAssocMapping mapping)
Description copied from interface: JmiDependencyTransform
Searches a collection of candidate objects, returning only those which are reachable via links corresponding to mapped incoming model edges to a target object.

Specified by:
getSourceNeighbors in interface JmiDependencyTransform
Parameters:
target - object to which incoming links are to be found
candidates - candidate source objects
mapping - mapping filter for links
Returns:
matching candidates

applyRefinedRules

private void applyRefinedRules(List<JmiDependencyMappedTransform.AssocRule> rules,
                               RefObject source,
                               RefObject target,
                               Collection result,
                               JmiAssocMapping mapping)

shouldProduceSelfLoops

public boolean shouldProduceSelfLoops()
Specified by:
shouldProduceSelfLoops in interface JmiDependencyTransform
Returns:
true if self-loops in the dependency graph should be allowed; false to automatically filter them out

setAllByAggregation

public void setAllByAggregation(AggregationKind requestedKind,
                                JmiAssocMapping mapping)
Sets mappings for all associations with a given aggregation kind, discarding any existing mappings for those associations.

Parameters:
requestedKind - association filter
mapping - mapping to use for matching associations

setByRefAssoc

public void setByRefAssoc(RefAssociation assoc,
                          JmiAssocMapping mapping)
Sets mapping for a specific association, discarding any existing mappings for that association.

Parameters:
assoc - association to map
mapping - mapping to use

setByRefAssocRefined

public void setByRefAssocRefined(RefAssociation assoc,
                                 JmiAssocMapping mapping,
                                 RefClass sourceClass,
                                 RefClass targetClass)
Sets mapping for a specific association, refining the rule to only apply in the context of specific end classes. Does not discard any existing mappings. Refined mappings are used in the reverse of the order in which they are defined (later definition overrides earlier).

Parameters:
assoc - association to map
mapping - mapping to use
sourceClass - source class required for match, or null for wildcard
targetClass - target class required for match, or null for wildcard

convertRefClassToMof

private MofClass convertRefClassToMof(RefClass c)