com.vbs.spring.versioning
Class VersionedBean

java.lang.Object
  extended by com.vbs.spring.versioning.VersionedBean

public final class VersionedBean
extends java.lang.Object

Wrapper for each Spring bean annotated as a VersionedClass.

Author:
Mike Whitfield (mike@virtual-businesses.com)

Constructor Summary
VersionedBean(java.lang.String beanName, java.lang.Class<?> versionedClass, boolean uniqueForType)
          Creates a wrapper for a Spring bean annotated as a VersionDependentClass.
 
Method Summary
(package private)  boolean addIfDependent(VersionDependentBean versionDependentBean)
          Adds the VersionDependentBean if it belongs to this VersionedBean.
(package private)  boolean checkDuplicateBeanType(java.lang.Class<?> otherBeanType)
          Returns true if this bean is of the same underlying type as the given class.
 boolean equals(java.lang.Object obj)
           
(package private)  java.lang.Object getBeanForVersion(java.lang.String activeVersion)
          Returns the spring bean that implements the given version or null if no such bean is found.
(package private)  java.lang.String getBeanName()
          Returns the name of the bean within the application context.
(package private)  java.lang.Class<?> getVersionedClass()
          Returns the VersionedClass annotated class that this bean represents.
 int hashCode()
           
(package private)  boolean isUniqueForType()
          Returns true if this is the only bean configured for the bean's class.
 java.lang.String toString()
           
(package private)  void validate()
          Verifies that a VersionDependentBean instance is present for each dependent class defined by VersionedClass annotation on this bean's targert class and that all declared non-private, non-static methods are implemented on each VersionDependentBean annotated as @fullyImplemented.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VersionedBean

VersionedBean(java.lang.String beanName,
              java.lang.Class<?> versionedClass,
              boolean uniqueForType)
Creates a wrapper for a Spring bean annotated as a VersionDependentClass.

Parameters:
beanName - the name of the bean within the application context.
versionedClass - the underlying class annotated by VersionedClass.
uniqueForType - true if this is the only bean of the type defined by versionedClass.
Method Detail

checkDuplicateBeanType

boolean checkDuplicateBeanType(java.lang.Class<?> otherBeanType)
Returns true if this bean is of the same underlying type as the given class.

If the types are the same, then the isUniqueForType method will return false.

Parameters:
otherBeanType - the VersionedClass annotated class of another bean.
Returns:
true if this bean is of the same underlying type as otherBeanType.

addIfDependent

boolean addIfDependent(VersionDependentBean versionDependentBean)
Adds the VersionDependentBean if it belongs to this VersionedBean.

The bean will be added if both this bean and the VersionDependentBean are unique by target class or (if one or both are not unigue), the name of this bean matches that of the dependent bean suffixed by the active versions that the dependent bean implements.

A given version can only be implemented by one dependent bean attached to a given VersionedBean. An IllegalStateException will be thrown if multiple dependent beans implement the same version.

Parameters:
versionDependentBean - the dependent bean that may belong to this.
Returns:
true if the bean has been added to this.

validate

void validate()
Verifies that a VersionDependentBean instance is present for each dependent class defined by VersionedClass annotation on this bean's targert class and that all declared non-private, non-static methods are implemented on each VersionDependentBean annotated as @fullyImplemented.

An INFO level log will be written listing the missing dependentg classes.


isUniqueForType

boolean isUniqueForType()
Returns true if this is the only bean configured for the bean's class.

Returns:
true if this is the only bean configured for the bean's class.

getBeanName

java.lang.String getBeanName()
Returns the name of the bean within the application context.

Returns:
the name of the bean within the application context.

getVersionedClass

java.lang.Class<?> getVersionedClass()
Returns the VersionedClass annotated class that this bean represents.

Returns:
the VersionedClass annotated class that this bean represents.

getBeanForVersion

java.lang.Object getBeanForVersion(java.lang.String activeVersion)
Returns the spring bean that implements the given version or null if no such bean is found.

Parameters:
activeVersion - the non-default version.
Returns:
the spring bean that implements the given version or null if no such bean is found.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

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