rafa.dep
Class SimpleDependency

java.lang.Object
  extended by rafa.dep.SimpleDependency
All Implemented Interfaces:
Dependency
Direct Known Subclasses:
GeneratorDependency

public class SimpleDependency
extends java.lang.Object
implements Dependency

Class describing a very simple dependency on another object.

Author:
rafa

Field Summary
protected  java.util.List<Dependent> path
          Dependency path, i.e.
protected  java.util.Map<java.lang.Object,java.lang.Object> properties
          Any properties with details on the dependency.
protected  java.lang.Object target
          The needed dependency itself.
 
Constructor Summary
SimpleDependency(java.lang.Object target)
           
SimpleDependency(java.lang.Object target, java.util.Map<java.lang.Object,java.lang.Object> properties)
           
 
Method Summary
 void addProperty(java.lang.Object key, java.lang.Object value)
          Adds a property to describe this dependency, overwriting it in case it already exists.
 java.util.List<Dependent> getPath()
           
 java.util.Map<java.lang.Object,java.lang.Object> getProperties()
           
 java.lang.Object getTarget()
           
protected  SimpleDependency mergeWith(Dependency subDep)
          Merges this dependency with another one.
 java.util.Collection<Dependency> search(java.lang.Object subTarget)
          Searches a sub-dependency within this object's target.
 java.lang.String toString()
           
 void validateCircularDependency()
          Checks that a dependency held by an object on itself is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

target

protected java.lang.Object target
The needed dependency itself.


path

protected java.util.List<Dependent> path
Dependency path, i.e. the list of objects between the dependent object - holder of this dependency - and the final target (both excluded).


properties

protected java.util.Map<java.lang.Object,java.lang.Object> properties
Any properties with details on the dependency.

Constructor Detail

SimpleDependency

public SimpleDependency(java.lang.Object target)

SimpleDependency

public SimpleDependency(java.lang.Object target,
                        java.util.Map<java.lang.Object,java.lang.Object> properties)
Method Detail

getTarget

public java.lang.Object getTarget()
Specified by:
getTarget in interface Dependency
Returns:

getPath

public java.util.List<Dependent> getPath()
Specified by:
getPath in interface Dependency
Returns:
The dependency path, i.e. the list of objects between the dependent object - holder of this dependency - and the final target (both excluded), or null if this is a direct dependency.

mergeWith

protected SimpleDependency mergeWith(Dependency subDep)
Merges this dependency with another one. This simple implementation concatenates the paths of this dependency and the subdependency, and combines any existing properties (prevailing this one's in case of conflict).

Parameters:
subDep - a subdependency from this one's target (which must necessarily be a Dependent instance).
Returns:
a merged dependency.

addProperty

public void addProperty(java.lang.Object key,
                        java.lang.Object value)
Adds a property to describe this dependency, overwriting it in case it already exists.

Specified by:
addProperty in interface Dependency
Parameters:
key -
value -

getProperties

public java.util.Map<java.lang.Object,java.lang.Object> getProperties()
Specified by:
getProperties in interface Dependency
Returns:

search

public java.util.Collection<Dependency> search(java.lang.Object subTarget)
Description copied from interface: Dependency
Searches a sub-dependency within this object's target.

Specified by:
search in interface Dependency
Parameters:
subTarget - the searched object.
Returns:
a number of dependencies on the passed object, whose path includes the target of this dependency as first item, or null if none found.

validateCircularDependency

public void validateCircularDependency()
                                throws CircularDependencyException
Checks that a dependency held by an object on itself is valid. This implementation does not allow any circular dependencies, but subclasses can override this method and check the dependency properties.

Specified by:
validateCircularDependency in interface Dependency
Throws:
CircularDependencyException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2008-2009. All Rights Reserved.