[jboss-cvs] JBossAS SVN: r68123 - in projects/microcontainer/trunk: container/src/tests/org/jboss/test/beaninfo/support and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 10 18:37:59 EST 2007
Author: alesj
Date: 2007-12-10 18:37:59 -0500 (Mon, 10 Dec 2007)
New Revision: 68123
Added:
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractConfigureAction.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/OldConfigureAction.java
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject0.xml
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject1.xml
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedSet0.xml
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/support/NestedBean.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyXMLTestCase.java
Modified:
projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java
projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/BeanInfoUtil.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/support/NestedBean.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/test/BeanInfoUtilTestCase.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java
Log:
JBMICROCONT-220.
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java 2007-12-10 22:44:29 UTC (rev 68122)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/AbstractBeanInfo.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -234,14 +234,12 @@
public Object getProperty(Object bean, String name) throws Throwable
{
- PropertyInfo property = getProperty(name);
- return property.get(bean);
+ return BeanInfoUtil.get(this, bean, name);
}
public void setProperty(Object bean, String name, Object value) throws Throwable
{
- PropertyInfo property = getProperty(name);
- property.set(bean, value);
+ BeanInfoUtil.set(this, bean, name, value);
}
public Object invoke(Object bean, String name) throws Throwable
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/BeanInfoUtil.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/BeanInfoUtil.java 2007-12-10 22:44:29 UTC (rev 68122)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/beans/info/plugins/BeanInfoUtil.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -29,6 +29,7 @@
import org.jboss.config.plugins.property.PropertyConfiguration;
import org.jboss.util.propertyeditor.PropertyEditors;
import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
/**
* Bean info helper.
@@ -65,12 +66,16 @@
protected static Object getNestedTarget(BeanInfo beanInfo, Object target, String[] propertys)
throws Throwable
{
+ if (propertys == null)
+ throw new IllegalArgumentException("Null propertys.");
+
for(int i = 0; i < propertys.length; i++)
{
if (beanInfo == null)
throw new IllegalArgumentException("Null bean info");
- Object result = beanInfo.getProperty(target, propertys[i]);
+ PropertyInfo propertyInfo = beanInfo.getProperty(propertys[i]);
+ Object result = propertyInfo.get(target);
if (i < propertys.length - 1)
{
if (result == null)
@@ -83,6 +88,41 @@
}
/**
+ * Get the nested property info from target.
+ *
+ * @param beanInfo the bean info
+ * @param target the target
+ * @param propertys the property names
+ * @return nested property info
+ * @throws Throwable for any error
+ */
+ protected static PropertyInfo getNestedPropertyInfo(BeanInfo beanInfo, Object target, String[] propertys)
+ throws Throwable
+ {
+ if (propertys == null || propertys.length == 0)
+ throw new IllegalArgumentException("Illegal propertys: " + Arrays.asList(propertys) + ", " + target);
+
+ PropertyInfo propertyInfo = null;
+ for(int i = 0; i < propertys.length; i++)
+ {
+ if (beanInfo == null)
+ throw new IllegalArgumentException("Null bean info");
+
+ propertyInfo = beanInfo.getProperty(propertys[i]);
+ // we're not done yet
+ if (i < propertys.length - 1)
+ {
+ Object result = propertyInfo.get(target);
+ if (result == null)
+ throw new IllegalArgumentException("Null target in nested property (" + Arrays.asList(propertys) + "): " + target + "." + propertys[i]);
+ beanInfo = configuration.getBeanInfo(result.getClass());
+ target = result;
+ }
+ }
+ return propertyInfo;
+ }
+
+ /**
* Get the value from target.
*
* @param beanInfo the bean info
@@ -132,7 +172,28 @@
}
else if (beanInfo == null)
throw new IllegalArgumentException("Null bean info.");
-
- beanInfo.setProperty(target, propertys[size], value);
+
+ PropertyInfo propertyInfo = beanInfo.getProperty(propertys[size]);
+ propertyInfo.set(target, value);
}
+
+ /**
+ * Get nested property info.
+ *
+ * @param beanInfo the bean info
+ * @param target the target
+ * @param name the nested property name
+ * @return nested property
+ * @throws Throwable for any error
+ */
+ public static PropertyInfo getPropertyInfo(BeanInfo beanInfo, Object target, String name) throws Throwable
+ {
+ if (target == null)
+ throw new IllegalArgumentException("Null target");
+ if (name == null)
+ throw new IllegalArgumentException("Null property name");
+
+ String[] propertys = name.split("\\.");
+ return getNestedPropertyInfo(beanInfo, target, propertys);
+ }
}
\ No newline at end of file
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/support/NestedBean.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/support/NestedBean.java 2007-12-10 22:44:29 UTC (rev 68122)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/support/NestedBean.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -27,6 +27,7 @@
public class NestedBean
{
private NestedBean bean;
+ private String string;
public NestedBean()
{
@@ -51,4 +52,21 @@
{
return null;
}
+
+ public NestedBean getOtherBean()
+ {
+ NestedBean other = new NestedBean();
+ other.setString(string);
+ return other;
+ }
+
+ public String getString()
+ {
+ return string;
+ }
+
+ public void setString(String string)
+ {
+ this.string = string;
+ }
}
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/test/BeanInfoUtilTestCase.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/test/BeanInfoUtilTestCase.java 2007-12-10 22:44:29 UTC (rev 68122)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/beaninfo/test/BeanInfoUtilTestCase.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -25,6 +25,7 @@
import org.jboss.test.beaninfo.support.NestedBean;
import org.jboss.beans.info.plugins.BeanInfoUtil;
import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
/**
* BeanInfoUtil Test Case.
@@ -114,4 +115,31 @@
assertInstanceOf(t, IllegalArgumentException.class);
}
}
+
+ public void testNestedPropertyInfo() throws Throwable
+ {
+ NestedBean grandchild = new NestedBean();
+ NestedBean child = new NestedBean(grandchild);
+ NestedBean parent = new NestedBean(child);
+ BeanInfo beanInfo = getBeanInfo();
+ PropertyInfo propertyInfo = beanInfo.getProperty("string");
+ PropertyInfo nestedPropertyInfo = BeanInfoUtil.getPropertyInfo(beanInfo, parent, "nestedBean.otherBean.string");
+ assertEquals(propertyInfo, nestedPropertyInfo);
+ }
+
+ public void testNestedPropertyInfoFail() throws Throwable
+ {
+ try
+ {
+ NestedBean child = new NestedBean();
+ NestedBean parent = new NestedBean(child);
+ BeanInfo beanInfo = getBeanInfo();
+ BeanInfoUtil.getPropertyInfo(beanInfo, parent, "nestedBean.differentGetter.string");
+ fail("Should not be here.");
+ }
+ catch (Throwable t)
+ {
+ assertInstanceOf(t, IllegalArgumentException.class);
+ }
+ }
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java 2007-12-10 22:44:29 UTC (rev 68122)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/AbstractBeanAnnotationAdapter.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -62,15 +62,31 @@
protected Set<AnnotationPlugin> methodAnnotationPlugins = new HashSet<AnnotationPlugin>();
protected Set<AnnotationPlugin> fieldAnnotationPlugins = new HashSet<AnnotationPlugin>();
+ /**
+ * Add the annotation plugin.
+ * Breaks down the plugin usage into
+ * different ElementType support collections.
+ *
+ * @param plugin the annotation plugin
+ */
protected void addAnnotationPlugin(AnnotationPlugin plugin)
{
+ if (plugin == null)
+ throw new IllegalArgumentException("Null plugin.");
+
Class<? extends Annotation> annotation = plugin.getAnnotation();
+ if (annotation == null)
+ throw new IllegalArgumentException("Null annotation class: " + plugin);
+
if (annotation.getAnnotation(Target.class) == null)
log.warn("Annotation " + annotation + " missing @Target annotation!");
if (annotation.getAnnotation(Retention.class) == null)
log.warn("Annotation " + annotation + " missing @Retention annotation!");
Set supported = plugin.getSupportedTypes();
+ if (supported == null || supported.isEmpty())
+ throw new IllegalArgumentException("Null or empty support types: " + plugin);
+
if (supported.contains(ElementType.TYPE))
{
classAnnotationPlugins.add(plugin);
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractConfigureAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractConfigureAction.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractConfigureAction.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -0,0 +1,100 @@
+/*
+* 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.kernel.spi.dependency.ConfigureKernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.CreateKernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.DescribeKernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.InstallKernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.InstantiateKernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.StartKernelControllerContextAware;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+
+/**
+ * AbstractConfigureAction.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractConfigureAction extends KernelControllerContextAction
+{
+ protected Class<? extends KernelControllerContextAware> getActionAwareInterface()
+ {
+ return ConfigureKernelControllerContextAware.class;
+ }
+
+ //TODO remove this?
+ //In case the class is EXACTLY KernelControllerContextAware, we call it from here,
+ //required for KernelControllerContextAwareTestCase and KernelControllerContextAwareXMLTestCase
+
+ /**
+ * Execute KCCA install.
+ * @param context the controller context
+ * @throws Throwable for any erroor
+ */
+ protected void installKernelControllerContextAware(KernelControllerContext context) throws Throwable
+ {
+ Object target = context.getTarget();
+ if (target != null && isExactlyKernelControllerContextAware(target))
+ {
+ ((KernelControllerContextAware)target).setKernelControllerContext(context);
+ }
+ }
+
+ /**
+ * Execute KCCA uninstall.
+ *
+ * @param context the controller context
+ */
+ protected void uninstallKernelControllerContextAware(KernelControllerContext context)
+ {
+ Object target = context.getTarget();
+ if (target != null && isExactlyKernelControllerContextAware(target))
+ {
+ try
+ {
+ ((KernelControllerContextAware)target).unsetKernelControllerContext(context);
+ }
+ catch (Throwable t)
+ {
+ log.debug("Ignored error unsetting context ", t);
+ }
+ }
+ }
+
+ /**
+ * Is exactly KCCA instance.
+ * @param o the target to test
+ * @return true if exact match
+ */
+ protected boolean isExactlyKernelControllerContextAware(Object o)
+ {
+ Class clazz = o.getClass();
+ return KernelControllerContextAware.class.isAssignableFrom(clazz) &&
+ (!ConfigureKernelControllerContextAware.class.isAssignableFrom(clazz) &&
+ !CreateKernelControllerContextAware.class.isAssignableFrom(clazz) &&
+ !DescribeKernelControllerContextAware.class.isAssignableFrom(clazz) &&
+ !InstallKernelControllerContextAware.class.isAssignableFrom(clazz) &&
+ !InstantiateKernelControllerContextAware.class.isAssignableFrom(clazz) &&
+ !StartKernelControllerContextAware.class.isAssignableFrom(clazz));
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java 2007-12-10 22:44:29 UTC (rev 68122)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -21,90 +21,45 @@
*/
package org.jboss.kernel.plugins.dependency;
-import java.util.Iterator;
import java.util.Set;
import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.beans.info.plugins.BeanInfoUtil;
import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.joinpoint.spi.TargettedJoinpoint;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.config.KernelConfigurator;
-import org.jboss.kernel.spi.dependency.CreateKernelControllerContextAware;
-import org.jboss.kernel.spi.dependency.DescribeKernelControllerContextAware;
-import org.jboss.kernel.spi.dependency.InstallKernelControllerContextAware;
-import org.jboss.kernel.spi.dependency.InstantiateKernelControllerContextAware;
-import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.kernel.plugins.config.Configurator;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
-import org.jboss.kernel.spi.dependency.ConfigureKernelControllerContextAware;
-import org.jboss.kernel.spi.dependency.StartKernelControllerContextAware;
/**
- * ConfigureAction.
+ * New ConfigureAction.
+ * @see org.jboss.kernel.plugins.dependency.OldConfigureAction
*
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision$
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
*/
-public class ConfigureAction extends KernelControllerContextAction
+public class ConfigureAction extends AbstractConfigureAction
{
protected void installActionInternal(KernelControllerContext context) throws Throwable
{
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
-
Object object = context.getTarget();
BeanInfo info = context.getBeanInfo();
BeanMetaData metaData = context.getBeanMetaData();
- Set joinPoints = configurator.getPropertySetterJoinPoints(info, metaData);
- setAttributes(context, object, joinPoints, false);
+ setAttributes(object, info, metaData, false);
- //TODO remove this?
- //In case the class is EXACTLY KernelControllerContextAware, we call it from here,
- //required for KernelControllerContextAwareTestCase and KernelControllerContextAwareXMLTestCase
- if (isExactlyKernelControllerContextAware(object))
- {
- ((KernelControllerContextAware) object).setKernelControllerContext(context);
- }
+ installKernelControllerContextAware(context);
}
- protected Class<? extends KernelControllerContextAware> getActionAwareInterface()
- {
- return ConfigureKernelControllerContextAware.class;
- }
-
protected void uninstallActionInternal(KernelControllerContext context)
{
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
+ uninstallKernelControllerContextAware(context);
Object object = context.getTarget();
-
- try
- {
- if (object != null)
- {
- //TODO remove this?
- //In case the class is EXACTLY KernelControllerContextAware, we call it from here,
- //required for KernelControllerContextAwareTestCase and KernelControllerContextAwareXMLTestCase
- if (isExactlyKernelControllerContextAware(object))
- {
- ((KernelControllerContextAware) object).unsetKernelControllerContext(context);
- }
- }
- }
- catch (Throwable ignored)
- {
- log.debug("Ignored error unsetting context ", ignored);
- }
-
BeanInfo info = context.getBeanInfo();
BeanMetaData metaData = context.getBeanMetaData();
try
{
- Set joinPoints = configurator.getPropertyNullerJoinPoints(info, metaData);
- setAttributes(context, object, joinPoints, true);
+ setAttributes(object, info, metaData, true);
}
catch (Throwable t)
{
@@ -113,53 +68,55 @@
}
/**
- * Set the attributes
+ * Set attributes/properties.
*
- * @param context the context
- * @param target the target
- * @param joinPoints the attribute setter joinpoints
- * @param ignoreErrors whether to ignore errors
- * @throws Throwable for any unignored error
+ * @param target the target
+ * @param info the bean info
+ * @param metaData the bean metadata
+ * @param nullyfy should we nullyfy attributes/properties
+ * @throws Throwable for any error
*/
- protected void setAttributes(KernelControllerContext context, Object target, Set joinPoints, boolean ignoreErrors) throws Throwable
+ protected void setAttributes(Object target, BeanInfo info, BeanMetaData metaData, boolean nullyfy) throws Throwable
{
- if (joinPoints.isEmpty() == false)
+ Set<PropertyMetaData> propertys = metaData.getProperties();
+ if (propertys != null && propertys.isEmpty() == false)
{
- boolean trace = log.isTraceEnabled();
+ ClassLoader cl = null;
+ if (nullyfy == false)
+ cl = Configurator.getClassLoader(metaData);
- for (Iterator i = joinPoints.iterator(); i.hasNext();)
+ for(PropertyMetaData property : propertys)
{
- TargettedJoinpoint joinPoint = (TargettedJoinpoint) i.next();
- joinPoint.setTarget(target);
- try
- {
- dispatchJoinPoint(context, joinPoint);
- }
- catch (Throwable t)
- {
- if (ignoreErrors)
- {
- if (trace)
- log.trace("Ignored for " + joinPoint, t);
- }
- else
- {
- throw t;
- }
- }
+ dispatchSetProperty(property, nullyfy, info, target, cl);
}
}
}
- private boolean isExactlyKernelControllerContextAware(Object o)
+ /**
+ * Dispatch property set
+ *
+ * @param property the property
+ * @param nullyfy should we nullyfy
+ * @param info the bean info
+ * @param target the target
+ * @param cl classloader
+ * @throws Throwable for any error
+ */
+ // TODO - wrap with MetaDataStack push and ContextCL change?
+ protected void dispatchSetProperty(PropertyMetaData property, boolean nullyfy, BeanInfo info, Object target, ClassLoader cl)
+ throws Throwable
{
- Class clazz = o.getClass();
- return KernelControllerContextAware.class.isAssignableFrom(clazz) &&
- (!ConfigureKernelControllerContextAware.class.isAssignableFrom(clazz) &&
- !CreateKernelControllerContextAware.class.isAssignableFrom(clazz) &&
- !DescribeKernelControllerContextAware.class.isAssignableFrom(clazz) &&
- !InstallKernelControllerContextAware.class.isAssignableFrom(clazz) &&
- !InstantiateKernelControllerContextAware.class.isAssignableFrom(clazz) &&
- !StartKernelControllerContextAware.class.isAssignableFrom(clazz));
+ String name = property.getName();
+ if (nullyfy)
+ {
+ info.setProperty(target, name, null);
+ }
+ else
+ {
+ PropertyInfo propertyInfo = BeanInfoUtil.getPropertyInfo(info, target, name);
+ ValueMetaData valueMetaData = property.getValue();
+ Object value = valueMetaData.getValue(propertyInfo.getType(), cl);
+ info.setProperty(target, name, value);
+ }
}
}
\ No newline at end of file
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/OldConfigureAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/OldConfigureAction.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/OldConfigureAction.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -0,0 +1,116 @@
+/*
+* 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 java.util.Set;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.joinpoint.spi.TargettedJoinpoint;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+
+/**
+ * OldConfigureAction.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 64100 $
+ */
+public class OldConfigureAction extends AbstractConfigureAction
+{
+ protected void installActionInternal(KernelControllerContext context) throws Throwable
+ {
+ KernelController controller = (KernelController) context.getController();
+ Kernel kernel = controller.getKernel();
+ KernelConfigurator configurator = kernel.getConfigurator();
+
+ Object object = context.getTarget();
+ BeanInfo info = context.getBeanInfo();
+ BeanMetaData metaData = context.getBeanMetaData();
+ Set<TargettedJoinpoint> joinPoints = configurator.getPropertySetterJoinPoints(info, metaData);
+ setAttributes(context, object, joinPoints, false);
+
+ installKernelControllerContextAware(context);
+ }
+
+ protected void uninstallActionInternal(KernelControllerContext context)
+ {
+ uninstallKernelControllerContextAware(context);
+
+ KernelController controller = (KernelController) context.getController();
+ Kernel kernel = controller.getKernel();
+ KernelConfigurator configurator = kernel.getConfigurator();
+
+ Object object = context.getTarget();
+ BeanInfo info = context.getBeanInfo();
+ BeanMetaData metaData = context.getBeanMetaData();
+ try
+ {
+ Set<TargettedJoinpoint> joinPoints = configurator.getPropertyNullerJoinPoints(info, metaData);
+ setAttributes(context, object, joinPoints, true);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error unconfiguring bean " + context, t);
+ }
+ }
+
+ /**
+ * Set the attributes
+ *
+ * @param context the context
+ * @param target the target
+ * @param joinPoints the attribute setter joinpoints
+ * @param ignoreErrors whether to ignore errors
+ * @throws Throwable for any unignored error
+ */
+ protected void setAttributes(KernelControllerContext context, Object target, Set<TargettedJoinpoint> joinPoints, boolean ignoreErrors) throws Throwable
+ {
+ if (joinPoints.isEmpty() == false)
+ {
+ boolean trace = log.isTraceEnabled();
+
+ for (TargettedJoinpoint joinPoint : joinPoints)
+ {
+ joinPoint.setTarget(target);
+ try
+ {
+ dispatchJoinPoint(context, joinPoint);
+ }
+ catch (Throwable t)
+ {
+ if (ignoreErrors)
+ {
+ if (trace)
+ log.trace("Ignored for " + joinPoint, t);
+ }
+ else
+ {
+ throw t;
+ }
+ }
+ }
+ }
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject0.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject0.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject0.xml 2007-12-10 23:37:59 UTC (rev 68123)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="InjecteeBean" class="org.jboss.test.kernel.dependency.support.NestedBean">
+ <constructor>
+ <parameter class="int">5</parameter>
+ </constructor>
+ <property name="string"><inject bean="NestedBean" property="bean.bean.string"/></property>
+ </bean>
+</deployment>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject1.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject1.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedInject1.xml 2007-12-10 23:37:59 UTC (rev 68123)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="NestedBean" class="org.jboss.test.kernel.dependency.support.NestedBean">
+ <constructor>
+ <parameter class="int">5</parameter>
+ </constructor>
+ <property name="bean.bean.string">String1234</property>
+ </bean>
+</deployment>
Copied: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedSet0.xml (from rev 68094, projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testCallbackWrongOrder0.xml)
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedSet0.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/dependency/test/testNestedSet0.xml 2007-12-10 23:37:59 UTC (rev 68123)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="NestedBean" class="org.jboss.test.kernel.dependency.support.NestedBean">
+ <constructor>
+ <parameter class="int">5</parameter>
+ </constructor>
+ <property name="bean.bean.string">String12</property>
+ </bean>
+</deployment>
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/support/NestedBean.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/support/NestedBean.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/support/NestedBean.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -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.test.kernel.dependency.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NestedBean
+{
+ private int limit;
+ private NestedBean bean;
+ private String string;
+
+ public NestedBean(int limit)
+ {
+ if (limit > 0)
+ bean = new NestedBean(limit - 1);
+ }
+
+ public NestedBean getBean()
+ {
+ return bean;
+ }
+
+ public void setBean(NestedBean bean)
+ {
+ this.bean = bean;
+ }
+
+ public String getString()
+ {
+ return string;
+ }
+
+ public void setString(String string)
+ {
+ this.string = string;
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java 2007-12-10 22:44:29 UTC (rev 68122)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -100,6 +100,8 @@
suite.addTest(MatcherDemandSupplyTestCase.suite());
suite.addTest(MatcherDemandSupplyXMLTestCase.suite());
suite.addTest(MatcherDemandSupplyAnnotationTestCase.suite());
+ suite.addTest(NestedPropertyTestCase.suite());
+ suite.addTest(NestedPropertyXMLTestCase.suite());
return suite;
}
}
Copied: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyTestCase.java (from rev 68094, projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/PlainAliasTestCase.java)
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyTestCase.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -0,0 +1,142 @@
+/*
+* 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.test.kernel.dependency.test;
+
+import java.util.HashSet;
+import java.util.Collections;
+
+import junit.framework.Test;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.test.kernel.dependency.support.SimpleBean;
+import org.jboss.test.kernel.dependency.support.SimpleBeanImpl;
+import org.jboss.test.kernel.dependency.support.NestedBean;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractConstructorMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+
+/**
+ * Nested property tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NestedPropertyTestCase extends OldAbstractKernelDependencyTest
+{
+ public NestedPropertyTestCase(String name) throws Throwable
+ {
+ super(name);
+ }
+
+ public NestedPropertyTestCase(String name, boolean xmltest) throws Throwable
+ {
+ super(name, xmltest);
+ }
+
+ public static Test suite()
+ {
+ return suite(NestedPropertyTestCase.class);
+ }
+
+ public void testNestedSet() throws Throwable
+ {
+ buildSetMetaData();
+
+ ControllerContext context = assertInstall(0, "NestedBean");
+ Object target = context.getTarget();
+ assertNotNull(target);
+ assertInstanceOf(target, NestedBean.class);
+ NestedBean root = (NestedBean)target;
+ NestedBean lev1 = root.getBean();
+ assertNotNull(lev1);
+ NestedBean lev2 = lev1.getBean();
+ assertNotNull(lev2);
+ assertEquals("String12", lev2.getString());
+ }
+
+ public void testNestedInject() throws Throwable
+ {
+ buildInjectMetaData();
+
+ ControllerContext context = assertInstall(1, "NestedBean");
+ Object target = context.getTarget();
+ assertNotNull(target);
+ assertInstanceOf(target, NestedBean.class);
+ NestedBean root = (NestedBean)target;
+ NestedBean lev1 = root.getBean();
+ assertNotNull(lev1);
+ NestedBean lev2 = lev1.getBean();
+ assertNotNull(lev2);
+ assertEquals("String1234", lev2.getString());
+
+ ControllerContext injecteeCC = assertInstall(0, "InjecteeBean");
+ Object injectee = injecteeCC.getTarget();
+ assertNotNull(injectee);
+ assertInstanceOf(injectee, NestedBean.class);
+ NestedBean injecteeBean = (NestedBean)injectee;
+ assertEquals("String1234", injecteeBean.getString());
+ }
+
+ protected void buildSetMetaData() throws Throwable
+ {
+ AbstractBeanMetaData metaData1 = new AbstractBeanMetaData("NestedBean", NestedBean.class.getName());
+ AbstractConstructorMetaData constructor1 = new AbstractConstructorMetaData();
+ ParameterMetaData parameter1 = new AbstractParameterMetaData(int.class.getName(), 5);
+ constructor1.setParameters(Collections.singletonList(parameter1));
+ metaData1.setConstructor(constructor1);
+ HashSet<PropertyMetaData> attributes1 = new HashSet<PropertyMetaData>();
+ attributes1.add(new AbstractPropertyMetaData("bean.bean.string", "String12"));
+ metaData1.setProperties(attributes1);
+
+ setBeanMetaDatas(new BeanMetaData[]{metaData1});
+ }
+
+ protected void buildInjectMetaData() throws Throwable
+ {
+ AbstractBeanMetaData metaData1 = new AbstractBeanMetaData("InjecteeBean", NestedBean.class.getName());
+ AbstractConstructorMetaData constructor1 = new AbstractConstructorMetaData();
+ ParameterMetaData parameter1 = new AbstractParameterMetaData(int.class.getName(), 5);
+ constructor1.setParameters(Collections.singletonList(parameter1));
+ metaData1.setConstructor(constructor1);
+ HashSet<PropertyMetaData> attributes1 = new HashSet<PropertyMetaData>();
+ AbstractDependencyValueMetaData injectedValue = new AbstractDependencyValueMetaData("NestedBean", "bean.bean.string");
+ AbstractPropertyMetaData propertyMetaData = new AbstractPropertyMetaData("string", injectedValue);
+ attributes1.add(propertyMetaData);
+ metaData1.setProperties(attributes1);
+
+ AbstractBeanMetaData metaData2 = new AbstractBeanMetaData("NestedBean", NestedBean.class.getName());
+ AbstractConstructorMetaData constructor2 = new AbstractConstructorMetaData();
+ ParameterMetaData parameter2 = new AbstractParameterMetaData(int.class.getName(), 5);
+ constructor2.setParameters(Collections.singletonList(parameter2));
+ metaData2.setConstructor(constructor1);
+ HashSet<PropertyMetaData> attributes2 = new HashSet<PropertyMetaData>();
+ attributes2.add(new AbstractPropertyMetaData("bean.bean.string", "String1234"));
+ metaData2.setProperties(attributes2);
+
+ setBeanMetaDatas(new BeanMetaData[]{metaData1, metaData2});
+ }
+}
\ No newline at end of file
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyXMLTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyXMLTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/dependency/test/NestedPropertyXMLTestCase.java 2007-12-10 23:37:59 UTC (rev 68123)
@@ -0,0 +1,53 @@
+/*
+* 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.test.kernel.dependency.test;
+
+import java.util.HashSet;
+
+import junit.framework.Test;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.test.kernel.dependency.support.SimpleBean;
+import org.jboss.test.kernel.dependency.support.SimpleBeanImpl;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+
+/**
+ * Nested property xml tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NestedPropertyXMLTestCase extends NestedPropertyTestCase
+{
+ public NestedPropertyXMLTestCase(String name) throws Throwable
+ {
+ super(name, true);
+ }
+
+ public static Test suite()
+ {
+ return suite(NestedPropertyXMLTestCase.class);
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list