[jboss-cvs] JBossAS SVN: r62478 - in projects/microcontainer/trunk: dependency/src/main/org/jboss/dependency/spi and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Apr 22 16:05:57 EDT 2007
Author: alesj
Date: 2007-04-22 16:05:56 -0400 (Sun, 22 Apr 2007)
New Revision: 62478
Added:
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/OwnerCallbackItem.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassAttributeCallbackItem.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassSingleCallbackItem.java
Removed:
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/NamedCallbackItem.java
Modified:
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractCallbackItem.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AttributeCallbackItem.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SingleCallbackItem.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/CallbackItem.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DependencyItem.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractCallbackMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CallbackDependencyItem.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassDependencyItem.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CollectionCallbackItem.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/CardinalityCallbackTestCase.java
Log:
Dependency item on context change and cardinality.
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractCallbackItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -22,7 +22,6 @@
package org.jboss.dependency.plugins;
import org.jboss.dependency.spi.CallbackItem;
-import org.jboss.dependency.spi.Cardinality;
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
@@ -39,21 +38,19 @@
protected T name;
protected ControllerState whenRequired = ControllerState.CONFIGURED;
protected ControllerState dependentState = ControllerState.INSTALLED;
- protected Cardinality cardinality;
protected AbstractCallbackItem(T name)
{
this.name = name;
}
- protected AbstractCallbackItem(T name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality)
+ protected AbstractCallbackItem(T name, ControllerState whenRequired, ControllerState dependentState)
{
this.name = name;
if (whenRequired != null)
this.whenRequired = whenRequired;
if (dependentState != null)
this.dependentState = dependentState;
- this.cardinality = cardinality;
}
public void ownerCallback(Controller controller) throws Throwable
@@ -63,16 +60,16 @@
/**
* Helper method.
*
- * @param context new installed context
+ * @param context changed context
* @throws Throwable for any error
*/
- protected void additionCallback(ControllerContext context) throws Throwable
+ protected void changeCallback(ControllerContext context) throws Throwable
{
}
- public void additionCallback(Controller controller, ControllerContext context) throws Throwable
+ public void changeCallback(Controller controller, ControllerContext context) throws Throwable
{
- additionCallback(context);
+ changeCallback(context);
}
public T getIDependOn()
@@ -90,11 +87,6 @@
return dependentState;
}
- public Cardinality getCardinality()
- {
- return cardinality;
- }
-
public void toShortString(JBossStringBuilder buffer)
{
buffer.append("name=").append(name);
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -783,17 +783,19 @@
ControllerState dependentState = item.getDependentState();
if (dependentState == null || dependentState.equals(fromState))
{
- item.unresolved(this);
- ControllerContext dependent = getContext(item.getName(), null);
- if (dependent != null)
+ if (item.unresolved(this))
{
- ControllerState whenRequired = item.getWhenRequired();
- if (whenRequired == null)
- whenRequired = ControllerState.NOT_INSTALLED;
- int proposed = states.indexOf(whenRequired);
- int actual = states.indexOf(dependent.getState());
- if (proposed <= actual)
- uninstallContext(dependent, whenRequired, trace);
+ ControllerContext dependent = getContext(item.getName(), null);
+ if (dependent != null)
+ {
+ ControllerState whenRequired = item.getWhenRequired();
+ if (whenRequired == null)
+ whenRequired = ControllerState.NOT_INSTALLED;
+ int proposed = states.indexOf(whenRequired);
+ int actual = states.indexOf(dependent.getState());
+ if (proposed <= actual)
+ uninstallContext(dependent, whenRequired, trace);
+ }
}
}
}
@@ -990,7 +992,7 @@
for(CallbackItem callback : existingCallbacks)
{
if (state.equals(callback.getDependentState()))
- callback.additionCallback(this, context);
+ callback.changeCallback(this, context);
}
}
}
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractDependencyItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -159,7 +159,7 @@
return resolved;
}
- public void unresolved(Controller controller)
+ public boolean unresolved(Controller controller)
{
if (resolved)
{
@@ -167,6 +167,7 @@
flushJBossObjectCache();
log.trace("Forced unresolved " + this);
}
+ return true;
}
public void toString(JBossStringBuilder buffer)
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AttributeCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AttributeCallbackItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AttributeCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -21,7 +21,6 @@
*/
package org.jboss.dependency.plugins;
-import org.jboss.dependency.spi.Cardinality;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.dispatch.AttributeDispatchContext;
@@ -32,30 +31,20 @@
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public abstract class AttributeCallbackItem<T> extends AbstractCallbackItem<T>
+public class AttributeCallbackItem<T> extends OwnerCallbackItem<T, AttributeDispatchContext>
{
- protected AttributeDispatchContext owner;
protected String attribute;
public AttributeCallbackItem(T name, AttributeDispatchContext owner, String attribute)
{
- this(name, null, null, null, owner, attribute);
+ this(name, null, null, owner, attribute);
}
- public AttributeCallbackItem(T name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality, AttributeDispatchContext owner, String attribute)
+ public AttributeCallbackItem(T name, ControllerState whenRequired, ControllerState dependentState, AttributeDispatchContext owner, String attribute)
{
- super(name, whenRequired, dependentState, cardinality);
- init(owner, attribute);
- }
-
- protected void init(AttributeDispatchContext owner, String attribute)
- {
- if (owner == null)
- throw new IllegalArgumentException("Null owner!");
+ super(name, whenRequired, dependentState, owner);
if (attribute == null)
throw new IllegalArgumentException("Null attribute!");
-
- this.owner = owner;
this.attribute = attribute;
}
@@ -64,7 +53,7 @@
owner.set(attribute, target);
}
- protected void additionCallback(ControllerContext context) throws Throwable
+ protected void changeCallback(ControllerContext context) throws Throwable
{
execute(context.getTarget());
}
@@ -72,7 +61,6 @@
protected void toString(JBossStringBuilder buffer)
{
super.toString(buffer);
- buffer.append(" owner=").append(owner);
buffer.append(" attribute=").append(attribute);
}
}
Deleted: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/NamedCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/NamedCallbackItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/NamedCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -1,44 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.dependency.plugins;
-
-import org.jboss.dependency.spi.Cardinality;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.spi.dispatch.AttributeDispatchContext;
-
-/**
- * Named callback item.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class NamedCallbackItem extends AttributeCallbackItem<Object>
-{
- public NamedCallbackItem(Object name, AttributeDispatchContext owner, String attribute)
- {
- super(name, owner, attribute);
- }
-
- public NamedCallbackItem(Object name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality, AttributeDispatchContext context, String attribute)
- {
- super(name, whenRequired, dependentState, cardinality, context, attribute);
- }
-}
Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/OwnerCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/OwnerCallbackItem.java (rev 0)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/OwnerCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -0,0 +1,89 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.plugins;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Owner callback item.
+ *
+ * @param <C> owner type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class OwnerCallbackItem<T, C> extends AbstractCallbackItem<T>
+{
+ protected C owner;
+
+ protected OwnerCallbackItem(T name, C owner)
+ {
+ this(name, null, null, owner);
+ }
+
+ protected OwnerCallbackItem(T name, ControllerState whenRequired, ControllerState dependentState, C owner)
+ {
+ super(name, whenRequired, dependentState);
+ if (owner == null)
+ throw new IllegalArgumentException("Null owner!");
+ this.owner = owner;
+ }
+
+ protected void addDependency(Controller controller, ControllerContext context)
+ {
+ if (owner instanceof ControllerContext)
+ {
+ ControllerContext co = (ControllerContext)owner;
+ DependencyItem dependency = createDependencyItem(co);
+ if (dependency != null && dependency.resolve(controller))
+ {
+ context.getDependencyInfo().addDependsOnMe(dependency);
+ co.getDependencyInfo().addIDependOn(dependency);
+ }
+ }
+ }
+
+ /**
+ * Create dependency - if it exists.
+ *
+ * @param owner if owner is controller context
+ * @return dependency or null if no such dependency exists
+ */
+ protected DependencyItem createDependencyItem(ControllerContext owner)
+ {
+ return null;
+ }
+
+ public void changeCallback(Controller controller, ControllerContext context) throws Throwable
+ {
+ super.changeCallback(controller, context);
+ addDependency(controller, context);
+ }
+
+ protected void toString(JBossStringBuilder buffer)
+ {
+ super.toString(buffer);
+ buffer.append(" owner=").append(owner);
+ }
+}
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SingleCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SingleCallbackItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/SingleCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -21,7 +21,6 @@
*/
package org.jboss.dependency.plugins;
-import org.jboss.dependency.spi.Cardinality;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
@@ -32,37 +31,29 @@
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class SingleCallbackItem extends AbstractCallbackItem<Object>
+public class SingleCallbackItem<T> extends OwnerCallbackItem<T, InvokeDispatchContext>
{
- protected InvokeDispatchContext owner;
protected String method;
protected String signature;
- public SingleCallbackItem(Object name, InvokeDispatchContext owner, String method)
+ public SingleCallbackItem(T name, InvokeDispatchContext owner, String method)
{
this(name, owner, method, null);
}
- public SingleCallbackItem(Object name, InvokeDispatchContext owner, String method, String signature)
+ public SingleCallbackItem(T name, InvokeDispatchContext owner, String method, String signature)
{
- this(name, null, null, null, owner, method, signature);
+ this(name, null, null, owner, method, signature);
}
- public SingleCallbackItem(Object name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality, InvokeDispatchContext owner, String method)
+ public SingleCallbackItem(T name, ControllerState whenRequired, ControllerState dependentState, InvokeDispatchContext owner, String method)
{
- this(name, whenRequired, dependentState, cardinality, owner, method, null);
+ this(name, whenRequired, dependentState, owner, method, null);
}
- public SingleCallbackItem(Object name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality, InvokeDispatchContext owner, String method, String signature)
+ public SingleCallbackItem(T name, ControllerState whenRequired, ControllerState dependentState, InvokeDispatchContext owner, String method, String signature)
{
- super(name, whenRequired, dependentState, cardinality);
- init(owner, method, signature);
- }
-
- protected void init(InvokeDispatchContext owner, String method, String signature)
- {
- if (owner == null)
- throw new IllegalArgumentException("Null owner!");
+ super(name, whenRequired, dependentState, owner);
if (method == null)
throw new IllegalArgumentException("Null method!");
@@ -71,7 +62,7 @@
this.signature = signature;
}
- protected void additionCallback(ControllerContext context) throws Throwable
+ protected void changeCallback(ControllerContext context) throws Throwable
{
Object target = context.getTarget();
if (target != null)
@@ -85,7 +76,6 @@
protected void toString(JBossStringBuilder buffer)
{
super.toString(buffer);
- buffer.append(" owner=").append(owner);
buffer.append(" method=").append(method);
buffer.append(" signature=").append(signature);
}
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/CallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/CallbackItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/CallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -54,13 +54,6 @@
ControllerState getDependentState();
/**
- * Get the cardinality.
- *
- * @return cardinality
- */
- Cardinality getCardinality();
-
- /**
* Execute callback when item added to controller.
*
* @param controller the controller
@@ -69,11 +62,11 @@
void ownerCallback(Controller controller) throws Throwable;
/**
- * Execute callback with current new installed context.
+ * Execute callback with current changed context.
*
* @param controller the controller
* @param context the new context
* @throws Throwable for any error
*/
- void additionCallback(Controller controller, ControllerContext context) throws Throwable;
+ void changeCallback(Controller controller, ControllerContext context) throws Throwable;
}
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DependencyItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DependencyItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DependencyItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -76,6 +76,7 @@
* Mark the dependency as unresolved
*
* @param controller the controller
+ * @return true if proceed with unresolving, false otherwise
*/
- void unresolved(Controller controller);
+ boolean unresolved(Controller controller);
}
\ No newline at end of file
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractCallbackMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractCallbackMetaData.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractCallbackMetaData.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -26,13 +26,13 @@
import org.jboss.beans.info.spi.PropertyInfo;
import org.jboss.beans.metadata.spi.CallbackMetaData;
import org.jboss.beans.metadata.spi.MetaDataVisitor;
-import org.jboss.dependency.plugins.NamedCallbackItem;
-import org.jboss.dependency.plugins.SingleCallbackItem;
import org.jboss.dependency.spi.CallbackItem;
import org.jboss.dependency.spi.Cardinality;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.kernel.plugins.config.Configurator;
import org.jboss.kernel.plugins.dependency.CallbackDependencyItem;
+import org.jboss.kernel.plugins.dependency.ClassAttributeCallbackItem;
+import org.jboss.kernel.plugins.dependency.ClassSingleCallbackItem;
import org.jboss.kernel.plugins.dependency.CollectionCallbackItemFactory;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.reflect.spi.ClassInfo;
@@ -194,7 +194,7 @@
if (info.isCollection())
callback = createCollectionCallback(info, context, property);
else
- callback = new NamedCallbackItem(info.getType(), whenRequired, dependentState, cardinality, context, property);
+ callback = new ClassAttributeCallbackItem(info.getType(), whenRequired, dependentState, cardinality, context, property);
}
else if (methodName != null)
{
@@ -208,7 +208,7 @@
else
{
Class clazz = info.getType();
- callback = new SingleCallbackItem(clazz, whenRequired, dependentState, cardinality, context, methodName, clazz.getName());
+ callback = new ClassSingleCallbackItem(clazz, whenRequired, dependentState, cardinality, context, methodName, clazz.getName());
}
}
else
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractInjectionValueMetaData.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -23,7 +23,7 @@
import org.jboss.beans.metadata.spi.MetaDataVisitor;
import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
-import org.jboss.dependency.plugins.NamedCallbackItem;
+import org.jboss.dependency.plugins.AttributeCallbackItem;
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
@@ -112,7 +112,7 @@
{
if (propertyMetaData == null)
throw new IllegalArgumentException("Illegal usage of option Callback - injection not used with property = " + this);
- context.getDependencyInfo().addInstallItem(new NamedCallbackItem(name, whenRequiredState, dependentState, null, context, propertyMetaData.getName()));
+ context.getDependencyInfo().addInstallItem(new AttributeCallbackItem<Object>(name, whenRequiredState, dependentState, context, propertyMetaData.getName()));
}
protected boolean isLookupValid(ControllerContext lookup)
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CallbackDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CallbackDependencyItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CallbackDependencyItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -28,6 +28,8 @@
import org.jboss.dependency.spi.ControllerState;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.util.HashCode;
+import org.jboss.util.JBossStringBuilder;
/**
* A Callback dependencyItem.
@@ -46,13 +48,23 @@
this.cardinality = cardinality;
}
- public boolean resolve(Controller controller)
+ public Cardinality getCardinality()
{
+ return cardinality;
+ }
+
+ protected Set<KernelControllerContext> getContexts(Controller controller)
+ {
if (controller instanceof KernelController == false)
throw new IllegalArgumentException("Controller not KernelController!");
KernelController kernelController = (KernelController)controller;
- Set<KernelControllerContext> contexts = kernelController.getInstantiatedContexts(getDemandClass());
+ return kernelController.getContexts(getDemandClass(), getDependentState());
+ }
+
+ public boolean resolve(Controller controller)
+ {
+ Set<KernelControllerContext> contexts = getContexts(controller);
int size = contexts != null ? contexts.size() : 0;
if (cardinality.isInRange(size))
{
@@ -71,4 +83,59 @@
return isResolved();
}
+ public boolean checkUnresolved(Controller controller, boolean previous)
+ {
+ if (previous == false)
+ return false;
+ if (getIDependOn() == null)
+ return true;
+
+ Set<KernelControllerContext> contexts = getContexts(controller);
+ // minus one, since this is called when unistalling dependent context
+ int size = contexts != null ? contexts.size() - 1 : 0;
+ return cardinality.isInRange(size) == false;
+ }
+
+ protected int getHashCode()
+ {
+ int result = HashCode.generate(getName());
+ result += 3 * HashCode.generate(getIDependOn());
+ result += 7 * HashCode.generate(getWhenRequired());
+ result += 11 * HashCode.generate(getDependentState());
+ result += 19 * HashCode.generate(getCardinality());
+ return result;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof CallbackDependencyItem == false)
+ return false;
+
+ CallbackDependencyItem cdi = (CallbackDependencyItem)obj;
+ if (isDifferent(getName(), cdi.getName()))
+ return false;
+ if (isDifferent(getIDependOn(), cdi.getIDependOn()))
+ return false;
+ if (isDifferent(getWhenRequired(), cdi.getWhenRequired()))
+ return false;
+ if (isDifferent(getDependentState(), cdi.getDependentState()))
+ return false;
+ if (isDifferent(getCardinality(), cdi.getCardinality()))
+ return false;
+ return true;
+ }
+
+ protected static boolean isDifferent(Object first, Object second)
+ {
+ if (first == null)
+ return second != null;
+ else
+ return first.equals(second) == false;
+ }
+
+ public void toString(JBossStringBuilder buffer)
+ {
+ super.toString(buffer);
+ buffer.append(" cardinality=" + cardinality);
+ }
}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassAttributeCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassAttributeCallbackItem.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassAttributeCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -0,0 +1,58 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.kernel.plugins.dependency;
+
+import org.jboss.dependency.plugins.AttributeCallbackItem;
+import org.jboss.dependency.spi.Cardinality;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.dispatch.AttributeDispatchContext;
+
+/**
+ * Class callback item - class dependency.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ClassAttributeCallbackItem extends AttributeCallbackItem<Class>
+{
+ protected Cardinality cardinality;
+
+ public ClassAttributeCallbackItem(Class name, AttributeDispatchContext owner, String attribute)
+ {
+ super(name, owner, attribute);
+ }
+
+ public ClassAttributeCallbackItem(Class name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality, AttributeDispatchContext owner, String attribute)
+ {
+ super(name, whenRequired, dependentState, owner, attribute);
+ this.cardinality = cardinality;
+ }
+
+ protected DependencyItem createDependencyItem(ControllerContext owner)
+ {
+ if (cardinality != null)
+ return new CallbackDependencyItem(owner.getName(), getIDependOn(), whenRequired, dependentState, cardinality);
+ else
+ return null;
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassDependencyItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassDependencyItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -43,12 +43,25 @@
return (Class)getIDependOn();
}
- public void unresolved(Controller controller)
+ public boolean unresolved(Controller controller)
{
+ boolean result = checkUnresolved(controller, super.unresolved(controller));
setIDependOn(null);
- super.unresolved(controller);
+ return result;
}
+ /**
+ * Check some additionl dependency.
+ *
+ * @param controller the controller
+ * @param previous previous result
+ * @return see unresolved method
+ */
+ protected boolean checkUnresolved(Controller controller, boolean previous)
+ {
+ return previous;
+ }
+
public void toString(JBossStringBuilder buffer)
{
super.toString(buffer);
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassSingleCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassSingleCallbackItem.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ClassSingleCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -0,0 +1,68 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.kernel.plugins.dependency;
+
+import org.jboss.dependency.plugins.SingleCallbackItem;
+import org.jboss.dependency.spi.Cardinality;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
+
+/**
+ * Class single dependency item - class dependency.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ClassSingleCallbackItem extends SingleCallbackItem<Class>
+{
+ protected Cardinality cardinality;
+
+ public ClassSingleCallbackItem(Class name, InvokeDispatchContext owner, String method)
+ {
+ super(name, owner, method);
+ }
+
+ public ClassSingleCallbackItem(Class name, InvokeDispatchContext owner, String method, String signature)
+ {
+ super(name, owner, method, signature);
+ }
+
+ public ClassSingleCallbackItem(Class name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality, InvokeDispatchContext owner, String method)
+ {
+ super(name, whenRequired, dependentState, owner, method);
+ }
+
+ public ClassSingleCallbackItem(Class name, ControllerState whenRequired, ControllerState dependentState, Cardinality cardinality, InvokeDispatchContext owner, String method, String signature)
+ {
+ super(name, whenRequired, dependentState, owner, method, signature);
+ this.cardinality = cardinality;
+ }
+
+ protected DependencyItem createDependencyItem(ControllerContext owner)
+ {
+ if (cardinality != null)
+ return new CallbackDependencyItem(owner.getName(), getIDependOn(), whenRequired, dependentState, cardinality);
+ else
+ return null;
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CollectionCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CollectionCallbackItem.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CollectionCallbackItem.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -24,7 +24,6 @@
import java.util.Collection;
import java.util.Set;
-import org.jboss.dependency.plugins.AttributeCallbackItem;
import org.jboss.dependency.spi.Cardinality;
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
@@ -39,7 +38,7 @@
* @param <T> expected collection type
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public abstract class CollectionCallbackItem<T extends Collection<Object>> extends AttributeCallbackItem<Class>
+public abstract class CollectionCallbackItem<T extends Collection<Object>> extends ClassAttributeCallbackItem
{
public CollectionCallbackItem(Class name, InvokeDispatchContext owner, String attribute)
{
@@ -80,8 +79,9 @@
}
}
- public void additionCallback(Controller controller, ControllerContext context) throws Throwable
+ public void changeCallback(Controller controller, ControllerContext context) throws Throwable
{
ownerCallback(controller);
+ addDependency(controller, context);
}
}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/CardinalityCallbackTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/CardinalityCallbackTestCase.java 2007-04-22 13:24:46 UTC (rev 62477)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/inject/test/CardinalityCallbackTestCase.java 2007-04-22 20:05:56 UTC (rev 62478)
@@ -48,7 +48,7 @@
{
KernelControllerContext context = getControllerContext("testObject", ControllerState.NOT_INSTALLED);
assertNull(context.getTarget());
- assertEquals(context.getState(), ControllerState.NOT_INSTALLED);
+ assertEquals(ControllerState.NOT_INSTALLED, context.getState());
change(context, ControllerState.CREATE);
CallbackTestObject injectee = (CallbackTestObject)context.getTarget();
@@ -77,12 +77,12 @@
assertNotNull(injectee.getTesterInterfaces());
assertEquals(3, injectee.getTesterInterfaces().size());
- change(tester3, ControllerState.NOT_INSTALLED);
+ change(tester1, ControllerState.NOT_INSTALLED);
assertEquals(2, injectee.getTesterInterfaces().size());
- assertEquals(context.getState(), ControllerState.INSTALLED);
+ assertEquals(ControllerState.INSTALLED, context.getState());
- change(tester2, ControllerState.NOT_INSTALLED);
- assertEquals(context.getState(), ControllerState.CONFIGURED);
+ change(tester3, ControllerState.NOT_INSTALLED);
+ assertEquals(ControllerState.CONFIGURED, context.getState());
}
}
More information about the jboss-cvs-commits
mailing list