RB
- The type class which extends RegistryBean
public interface ProxyAware<RB extends RegistryBean>
This interface is implemented by beans with more complex internal details. A little bit more background is required to understand the details:
CSAF beans are implementing an interface. Lets assume that we have
an interface IA
(extending RegistryBean
) and an
implementation class A
(extending DynamicRegistryBean
).
There is a reason for this separation: The objects returned by
BeanPool.create(Class)
, or BeanPool.read(Class, String)
are implementations of IA
, but not instances of A
.
In fact, these objects are instances of Proxy
. They have,
however, an internal instance of A
. Most of the proxies work
is done by simply delegating method calls to the internal instance.
Now lets furthermore assume, that the interface A contains the following methods:
@Slot(name="{MyNamespace}name") String getName(); void setName(String pName); @Slot(name="{MyNamespace}fullyQualifiedName") String getFulllyQualifiedName(); void setFullyQualifiedName(String pName);
In the example, the name would be a suffix of the fully
qualified name. Sooner or later, we'd like to have the fully
qualified name changed, if the name gets changed. This would
typically be done by code like the following in the implementation
class A
:
public void setName(String pName) { name = pName; String newFqn = getPrefix(getFullyQualifiedName()) + name; setFullyQualifiedName(newFqn); }
Surprisingly, this wouldn't work. Ok, the fully qualified name
gets set in the A
instance. However, the CSAF is not aware
of the change. Therefore, changes will possibly never be written
back to the registry!
Why is this? The reason is, that the proxy object wasn't called.
Normally, the method setFullyQualifiedName(String)
would
be invoked on the proxy object, not on the actual data bean. At
this point, the proxy would detect the change. In other words, a
working example would look like this:
public void setName(String pName) { name = pName; String newFqn = getPrefix(getFullyQualifiedName()) + name; getProxy().setFullyQualifiedName(newFqn); }
Of course, you'd need to implement the method getProxy()
in the bean. And here's where the ProxyAware
interface
comes into play: If your bean is implementing it, then it has a
method setProxy(RegistryBean)
, which gets invoked by the
CSAF. In other words, your bean would typically look like this:
public class A implements IA, ProxyAware{ private IA proxy; public void setProxy(IA pProxy) { proxy = pProxy; } public IA getProxy() { return proxy; } }
void setProxy(RB pBean)
pBean
- The bean to set the proxy for