public abstract class AbstractSwitchingInvocationAdaptor<T> extends AbstractComponentAdaptor<T>
interfaceClass
Modifier | Constructor and Description |
---|---|
protected |
AbstractSwitchingInvocationAdaptor(Class<T> interfaceClass,
Class<? extends T> enabledClass,
Class<? extends T> disabledClass) |
Modifier and Type | Method and Description |
---|---|
Class<? extends T> |
getComponentImplementation()
Returns the interface class that this adaptor was registered with.
|
T |
getComponentInstance(org.picocontainer.PicoContainer container) |
protected InvocationHandler |
getHandler(org.picocontainer.PicoContainer container) |
protected abstract InvocationSwitcher |
getInvocationSwitcher() |
protected boolean |
isEnabled() |
accept, findAdapterOfType, getComponentInstance, getComponentKey, getDelegate, getDescriptor, verify
protected boolean isEnabled()
public Class<? extends T> getComponentImplementation()
WARNING: This should NOT return either concrete implementation class!
When Pico needs to satisfy a dependency but the class it is asked for is not registered, it reacts by asking every component adaptor that is registered what its concrete implementation class is. The thinking is that maybe, just maybe, it can find something registered under a different key that can satisfy this dependency.
This is the method that Pico uses to do that, and what it's trying to figure out is "When I ask you for your component instance, of what class will it be?" Previously, this method returned the specific implementation class that it would delegate to right now, but there are two major problems with doing that:
getComponentInstance(PicoContainer)
to yield an object of
that class. However, what we actually return is a dynamic proxy for our own registration interface,
not either of the concrete implementations. Our own registration interface cannot be the desired one
or Pico would have resolved it to us without asking this question in the first place, so this would
NEVER work.StackOverflowError
instead of gracefully
reporting the unsatisfiable dependency. This makes the problem harder to diagnose and fix, so let's not do
that.The most accurate answer here would be to return the actual dynamic proxy class we will use, but returning the interface we registered under is simpler, still honest, and should be good enough.
protected InvocationHandler getHandler(org.picocontainer.PicoContainer container)
public T getComponentInstance(org.picocontainer.PicoContainer container) throws org.picocontainer.PicoCompositionException
org.picocontainer.PicoCompositionException
protected abstract InvocationSwitcher getInvocationSwitcher()
Copyright © 2002-2017 Atlassian. All Rights Reserved.