org.apache.commons.betwixt.strategy
Class ListedClassNormalizer

java.lang.Object
  extended by org.apache.commons.betwixt.strategy.ClassNormalizer
      extended by org.apache.commons.betwixt.strategy.ListedClassNormalizer

public class ListedClassNormalizer
extends ClassNormalizer

ClassNormalizer that uses a list of substitutions.

This ClassNormalizer checks a list (in order) to find a matching Class. This match can be performed either strictly (using equality) or taking into account inheritance and implementation. If a match is found then the first substituted class is returned as the normalization.

Since:
0.5
Author:
Robert Burrell Donkin

Constructor Summary
ListedClassNormalizer()
           
 
Method Summary
 void addSubstitution(java.lang.Class substitute)
          Adds the given substitute to the list.
 void addSubstitution(java.lang.Class match, java.lang.Class substitute)
          Adds this given substitution to the list.
 boolean isStrickCheck()
          Is strict checking of substitutions on?
 java.lang.Class normalize(java.lang.Class clazz)
          Normalize given class.
 void setStrickCheck(boolean strickCheck)
          Sets strict checking of substitutions?
 
Methods inherited from class org.apache.commons.betwixt.strategy.ClassNormalizer
getNormalizedClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListedClassNormalizer

public ListedClassNormalizer()
Method Detail

isStrickCheck

public boolean isStrickCheck()
Is strict checking of substitutions on?

Returns:
true is equality is used to compare classes when considering substition, otherwise isAssignableFrom will be used so that super classes and super interfaces will be matched.

setStrickCheck

public void setStrickCheck(boolean strickCheck)
Sets strict checking of substitutions?

Parameters:
strickCheck - if true then equality will be used to compare classes when considering substition, otherwise isAssignableFrom will be used so that super classes and super interfaces will be matched.

addSubstitution

public void addSubstitution(java.lang.Class match,
                            java.lang.Class substitute)
Adds this given substitution to the list. No warning is given if the match has already been added to the list.

Parameters:
match - if any classes matching this then the normal class will be substituted
substitute - the normalized Class if the primary class is matched

addSubstitution

public void addSubstitution(java.lang.Class substitute)
Adds the given substitute to the list. This is a convenience method useful when isStrickCheck() is false. In this case, any subclasses (if this is a class) or implementating classes if this is an interface) will be subsituted with this value.

Parameters:
substitute - sustitude this Class

normalize

public java.lang.Class normalize(java.lang.Class clazz)
Normalize given class. The normalized Class is the Class that Betwixt should introspect. This strategy class allows the introspected Class to be varied.

Overrides:
normalize in class ClassNormalizer
Parameters:
clazz - the class to normalize, not null
Returns:
this implementation check it's list of substitutations in order and returns the first that matchs. If isStrickCheck() then equality is used otherwise isAssignableFrom is used (so that super class and interfaces are matched).


Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.