org.wicketstuff.springreference
Class AbstractSpringReference<T>

java.lang.Object
  extended by org.wicketstuff.springreference.AbstractSpringReference<T>
Type Parameters:
T - type of the wrapped spring bean
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
SpringReference

public abstract class AbstractSpringReference<T>
extends Object
implements Serializable, Cloneable

An abstract base class for referring spring beans.

This class supports serialization. The referred spring bean does not get serialized, after deserialization it is looked up again on the first access.

Subclasses must implement the getSupporter() method used to locate the AbstractSpringReferenceSupporter object. This class does not depend on wicket or spring-web. So in theory subclasses can be used in non-wicket, non-web spring applications too.

Author:
akiraly
See Also:
Serialized Form

Constructor Summary
protected AbstractSpringReference(Class<T> clazz, String name)
          Constructor.
 
Method Summary
 AbstractSpringReference<T> clone()
           
 boolean equals(Object obj)
           
 T get()
          Returns the referred spring bean.
protected  Class<T> getClazz()
           
protected  String getName()
          Can change during lookup if it was not set originally.
protected abstract  AbstractSpringReferenceSupporter getSupporter()
           
 int hashCode()
           
protected  boolean isClazzBasedOnlyLookup()
           
protected  void setInstanceRef(WeakReference<T> instanceRef)
           
protected  void setName(String name)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSpringReference

protected AbstractSpringReference(Class<T> clazz,
                                  String name)
Constructor.

Parameters:
clazz - class of the wrapped spring bean, not null
name - beanName of the wrapped spring bean, can be null
Method Detail

get

public T get()
Returns the referred spring bean. Lookup is made lazily on the first call.

Returns:
referred spring bean or throws a RuntimeException if the bean could not be found.

clone

public AbstractSpringReference<T> clone()
Overrides:
clone in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

getSupporter

protected abstract AbstractSpringReferenceSupporter getSupporter()
Returns:
object used to find the wrapped spring bean, not null

setInstanceRef

protected void setInstanceRef(WeakReference<T> instanceRef)
Parameters:
instanceRef - weak reference to the spring bean

getName

protected String getName()
Can change during lookup if it was not set originally.

Returns:
name of the spring bean, can be null

setName

protected void setName(String name)
Parameters:
name - name of the spring bean

getClazz

protected Class<T> getClazz()
Returns:
class of the spring bean

isClazzBasedOnlyLookup

protected boolean isClazzBasedOnlyLookup()
Returns:
true if the spring bean name was not given at construction time


Copyright © 2012. All Rights Reserved.