[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Install Items
adrian@jboss.org
do-not-reply at jboss.com
Wed Apr 18 07:54:22 EDT 2007
You still don't understand.
The callback is a generic thing.
It's also an implementation detail handled internally by the controller,
so you don't need anything on the controller itself.
e.g. something like
| public interface InstallItem<T>
| {
| ControllerState whenRequired();
| ControllerState requiredState();
| int getCardinality();
| Class<T> getItemType();
| }
|
| public interface SingleInstallItem<T> extends InstallItem<T>
| {
| add(T item);
| remove(T item);
| }
|
|
| public interface CollectionInstallItem<T> extends InstallItem<T>
| {
| set(Collection<? extends T> items);
| }
|
And then in the controller (pseudo code):
| protected void install(ControllerContext context, ControllerState toState)
| {
| // do it (what it does now)
|
| Collection<InstallItem> installs = context.getDependencyInfo().getInstallItems();
| if (installs != null && installs.isEmpty() == false)
| {
| for (InstallItem install : installs)
| {
| if (install.getWhenRequired().equals(toState)
| {
| addToIndex(install.getItemItype(), install);
| // also install what already exists
| }
| }
| }
|
| Collection<Class<?> implements = getClassesImplemented(context.getTarget());
| if (implements != null && implements.isEmpty() == false)
| {
| for (Class implement : implements)
| {
| Set<InstallItem> installs = getFromIndex(implement);
| // Do the installs if we are at the required state
| {
| // eventually leading to something like
| InstallItem install = // from installs
| if (toState.equals(install.getRequiredState))
| install.add(context.getTarget());
| }
| }
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4038323#4038323
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4038323
More information about the jboss-dev-forums
mailing list