[jboss-cvs] JBossAS SVN: r57859 - in projects/microcontainer/trunk: aop-mc-int/src/tests/org/jboss/test/microcontainer/test kernel/src/main/org/jboss/beans/metadata/spi/annotations kernel/src/main/org/jboss/kernel/plugins/dependency kernel/src/main/org/jboss/test/kernel/junit kernel/src/resources/org/jboss/test/kernel/deployment/test kernel/src/tests/org/jboss/test/kernel/deployment/support kernel/src/tests/org/jboss/test/kernel/deployment/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 26 15:39:49 EDT 2006
Author: alesj
Date: 2006-10-26 15:39:29 -0400 (Thu, 26 Oct 2006)
New Revision: 57859
Added:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/CreateLifeCycle.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/DestroyLifeCycle.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StartLifeCycle.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StopLifeCycle.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/ManualMicrocontainerTestDelegate.java
projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.xml
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/AnnotatedLifecycleBean.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.java
Modified:
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedAnnotationDependencyTestCase.java
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedMethodAnnotationDependencyTestCase.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CreateDestroyLifecycleAction.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/LifecycleAction.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/StartStopLifecycleAction.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java
Log:
annotation lifecycle support
Modified: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedAnnotationDependencyTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedAnnotationDependencyTestCase.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedAnnotationDependencyTestCase.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -29,7 +29,6 @@
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.test.microcontainer.support.InterceptorWithAnnotationDependency;
import org.jboss.test.microcontainer.support.InterceptorWithNestedAnnotationDependency;
-import org.jboss.test.microcontainer.support.NestedAnnotatedSimpleBeanImpl;
import org.jboss.test.microcontainer.support.SimpleBean;
public class InterceptorWithNestedAnnotationDependencyTestCase extends AOPMicrocontainerTest
Modified: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedMethodAnnotationDependencyTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedMethodAnnotationDependencyTestCase.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/InterceptorWithNestedMethodAnnotationDependencyTestCase.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -29,7 +29,6 @@
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.test.microcontainer.support.InterceptorWithAnnotationDependency;
import org.jboss.test.microcontainer.support.InterceptorWithNestedAnnotationDependency;
-import org.jboss.test.microcontainer.support.NestedMethodAnnotatedSimpleBeanImpl;
import org.jboss.test.microcontainer.support.SimpleBean;
public class InterceptorWithNestedMethodAnnotationDependencyTestCase extends AOPMicrocontainerTest
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/CreateLifeCycle.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/CreateLifeCycle.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/CreateLifeCycle.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.beans.metadata.spi.annotations;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public @interface CreateLifecycle
+{
+}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/DestroyLifeCycle.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/DestroyLifeCycle.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/DestroyLifeCycle.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.beans.metadata.spi.annotations;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public @interface DestroyLifecycle
+{
+}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StartLifeCycle.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StartLifeCycle.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StartLifeCycle.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.beans.metadata.spi.annotations;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public @interface StartLifecycle
+{
+}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StopLifeCycle.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StopLifeCycle.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/annotations/StopLifeCycle.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.beans.metadata.spi.annotations;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public @interface StopLifecycle
+{
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CreateDestroyLifecycleAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CreateDestroyLifecycleAction.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/CreateDestroyLifecycleAction.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -26,7 +26,6 @@
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.LifecycleMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
/**
* CreateDestroyLifecycleAction.
@@ -36,37 +35,53 @@
*/
public class CreateDestroyLifecycleAction extends LifecycleAction
{
- public String getInstallMethod(KernelControllerContext context)
+ public String getInstallMethod(BeanMetaData beanMetaData)
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getCreate();
- if (lifecycle != null && lifecycle.getMethodName() != null)
+ LifecycleMetaData lifecycle = beanMetaData.getCreate();
+ if (lifecycle != null)
return lifecycle.getMethodName();
+ return null;
+ }
+
+ public String getDefaultInstallMethod()
+ {
return "create";
}
- public List<ParameterMetaData> getInstallParameters(KernelControllerContext context)
+ public String getInstallAnnotation()
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getCreate();
+ return CreateLifecycle.class.getName();
+ }
+
+ public List<ParameterMetaData> getInstallParameters(BeanMetaData beanMetaData)
+ {
+ LifecycleMetaData lifecycle = beanMetaData.getCreate();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
}
- public String getUninstallMethod(KernelControllerContext context)
+ public String getUninstallMethod(BeanMetaData beanMetaData)
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getDestroy();
- if (lifecycle != null && lifecycle.getMethodName() != null)
+ LifecycleMetaData lifecycle = beanMetaData.getDestroy();
+ if (lifecycle != null)
return lifecycle.getMethodName();
+ return null;
+ }
+
+ public String getDefaultUninstallMethod()
+ {
return "destroy";
}
- public List<ParameterMetaData> getUninstallParameters(KernelControllerContext context)
+ public String getUninstallAnnotation()
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getDestroy();
+ return DestroyLifecycle.class.getName();
+ }
+
+ public List<ParameterMetaData> getUninstallParameters(BeanMetaData beanMetaData)
+ {
+ LifecycleMetaData lifecycle = beanMetaData.getDestroy();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -42,7 +42,7 @@
/**
* DescribeAction.
- *
+ *
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision$
*/
@@ -53,7 +53,7 @@
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelConfigurator configurator = kernel.getConfigurator();
-
+
BeanMetaData metaData = context.getBeanMetaData();
if (metaData.getBean() != null)
{
@@ -81,7 +81,7 @@
context.setMetaDataContext(null);
context.setBeanInfo(null);
}
-
+
/**
* Adds annotations to the bean. If annotations are added, returns the bean info for the instance
* @return The class bean info if no annotations exist or the instance bean info if annotations exist
@@ -89,35 +89,32 @@
private BeanInfo addAnnotations(KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
{
MetaDataContext metaCtx = addClassAnnotations(context, beanMetaData, beanInfo);
- metaCtx = addPropertyAnnotations(metaCtx, context, beanMetaData, beanInfo);
+ addPropertyAnnotations(metaCtx, context, beanMetaData, beanInfo);
return context.getBeanInfo();
}
-
+
private MetaDataContext addClassAnnotations(KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
{
Set annotations = beanMetaData.getAnnotations();
MetaDataContext metaCtx = null;
-
+
if (annotations != null && annotations.size() > 0)
{
- if (metaCtx == null)
- {
- metaCtx = getMetaDataContext(context);
- }
+ metaCtx = getMetaDataContext(context);
if (metaCtx != null)
{
metaCtx.addAnnotations(annotations);
}
}
-
+
return metaCtx;
}
private MetaDataContext addPropertyAnnotations(MetaDataContext metaCtx, KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
{
Set properties = beanMetaData.getProperties();
-
+
if (properties != null && properties.size() > 0)
{
for (Iterator it = properties.iterator() ; it.hasNext() ; )
@@ -131,7 +128,7 @@
metaCtx = getMetaDataContext(context);
}
if (metaCtx != null)
- {
+ {
//metaCtx.addPropertyAnnotations(property.getName(), propertyAnnotations);
Set propertyInfos = beanInfo.getProperties();
if (propertyInfos != null && propertyInfos.size() > 0)
@@ -142,15 +139,15 @@
}
}
}
-
+
return metaCtx;
}
-
+
private MetaDataContext getMetaDataContext(KernelControllerContext context)
{
//TODO: Hardcoding this doesn't feel right...
ControllerContext repCtx = context.getController().getContext("Repository", ControllerState.INSTALLED);
-
+
if (repCtx == null)
{
log.warn("You have defined annotations for bean '" + context.getName() + "', but no KernelRepository has been installed under the name 'Repository'");
@@ -162,7 +159,7 @@
MetaDataContext metaCtx = metaFactory.getMetaDataContext(repository, context.getName());
context.setMetaDataContext(metaCtx);
-
+
return metaCtx;
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/LifecycleAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/LifecycleAction.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/LifecycleAction.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -22,6 +22,7 @@
package org.jboss.kernel.plugins.dependency;
import java.util.List;
+import java.util.Set;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.metadata.spi.BeanMetaData;
@@ -33,6 +34,9 @@
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.repository.spi.MetaDataContext;
+import org.jboss.reflect.spi.AnnotationValue;
+import org.jboss.reflect.spi.MethodInfo;
/**
* LifecycleAction.
@@ -52,35 +56,63 @@
/**
* Get the install method
*
- * @param context the context
+ * @param beanMetaData
* @return the method
*/
- public abstract String getInstallMethod(KernelControllerContext context);
+ public abstract String getInstallMethod(BeanMetaData beanMetaData);
/**
+ * Get install default method name
+ *
+ * @return install annotation name
+ */
+ public abstract String getDefaultInstallMethod();
+
+ /**
+ * Get install annotation class name
+ *
+ * @return install annotation name
+ */
+ public abstract String getInstallAnnotation();
+
+ /**
* Get the install parameters
*
- * @param context the context
+ * @param beanMetaData
* @return the parameters
*/
- public abstract List<ParameterMetaData> getInstallParameters(KernelControllerContext context);
+ public abstract List<ParameterMetaData> getInstallParameters(BeanMetaData beanMetaData);
/**
* Get the uninstall method
*
- * @param context the context
+ * @param beanMetaData
* @return the method
*/
- public abstract String getUninstallMethod(KernelControllerContext context);
+ public abstract String getUninstallMethod(BeanMetaData beanMetaData);
/**
+ * Get uninstall default method name
+ *
+ * @return install annotation name
+ */
+ public abstract String getDefaultUninstallMethod();
+
+ /**
+ * Get uninstall annotation class name
+ *
+ * @return uninstall annotation name
+ */
+ public abstract String getUninstallAnnotation();
+
+ /**
* Get the uninstall parameters
- *
- * @param context the context
+ *
+ * @param beanMetaData
* @return the parameters
*/
- public abstract List<ParameterMetaData> getUninstallParameters(KernelControllerContext context);
-
+ public abstract List<ParameterMetaData> getUninstallParameters(BeanMetaData beanMetaData);
+
public void installAction(KernelControllerContext context) throws Throwable
{
boolean trace = log.isTraceEnabled();
@@ -145,11 +177,91 @@
else
log.trace("No " + method + parameters + " method for " + context);
}
- return;
}
catch (Throwable throwable)
{
log.warn("Error during " + method, throwable);
}
}
+
+ /**
+ * Get the install method
+ *
+ * @param context
+ * @return the method
+ */
+ public String getInstallMethod(KernelControllerContext context)
+ {
+ String installMethod = getInstallMethod(context.getBeanMetaData());
+ if (installMethod != null)
+ {
+ return installMethod;
+ }
+ BeanInfo beanInfo = context.getBeanInfo();
+ Set<MethodInfo> methods = beanInfo.getMethods();
+ if (methods != null)
+ {
+ for (MethodInfo mi : methods)
+ {
+ if (mi.isAnnotationPresent(getInstallAnnotation()))
+ {
+ return mi.getName();
+ }
+ }
+ }
+ return getDefaultInstallMethod();
+ }
+
+ /**
+ * Get the install parameters
+ *
+ * @param context
+ * @return the parameters
+ */
+ public List<ParameterMetaData> getInstallParameters(KernelControllerContext context)
+ {
+ // todo some parameter support
+ return getInstallParameters(context.getBeanMetaData());
+ }
+
+ /**
+ * Get the uninstall method
+ *
+ * @param context
+ * @return the method
+ */
+ public String getUninstallMethod(KernelControllerContext context)
+ {
+ String uninstallMethod = getUninstallMethod(context.getBeanMetaData());
+ if (uninstallMethod != null)
+ {
+ return uninstallMethod;
+ }
+ BeanInfo beanInfo = context.getBeanInfo();
+ Set<MethodInfo> methods = beanInfo.getMethods();
+ if (methods != null)
+ {
+ for (MethodInfo mi : methods)
+ {
+ if (mi.isAnnotationPresent(getUninstallAnnotation()))
+ {
+ return mi.getName();
+ }
+ }
+ }
+ return getDefaultUninstallMethod();
+ }
+
+ /**
+ * Get the uninstall parameters
+ *
+ * @param context the context
+ * @return the parameters
+ */
+ public List<ParameterMetaData> getUninstallParameters(KernelControllerContext context)
+ {
+ // todo some parameter support
+ return getUninstallParameters(context.getBeanMetaData());
+ }
+
}
\ No newline at end of file
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/StartStopLifecycleAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/StartStopLifecycleAction.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/StartStopLifecycleAction.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -26,7 +26,6 @@
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.LifecycleMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
/**
* StartStopLifecycleAction.
@@ -36,37 +35,53 @@
*/
public class StartStopLifecycleAction extends LifecycleAction
{
- public String getInstallMethod(KernelControllerContext context)
+ public String getInstallMethod(BeanMetaData beanMetaData)
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStart();
- if (lifecycle != null && lifecycle.getMethodName() != null)
+ LifecycleMetaData lifecycle = beanMetaData.getStart();
+ if (lifecycle != null)
return lifecycle.getMethodName();
+ return null;
+ }
+
+ public String getDefaultInstallMethod()
+ {
return "start";
}
- public List<ParameterMetaData> getInstallParameters(KernelControllerContext context)
+ public String getInstallAnnotation()
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStart();
+ return StartLifecycle.class.getName();
+ }
+
+ public List<ParameterMetaData> getInstallParameters(BeanMetaData beanMetaData)
+ {
+ LifecycleMetaData lifecycle = beanMetaData.getStart();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
}
- public String getUninstallMethod(KernelControllerContext context)
+ public String getUninstallMethod(BeanMetaData beanMetaData)
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStop();
- if (lifecycle != null && lifecycle.getMethodName() != null)
+ LifecycleMetaData lifecycle = beanMetaData.getStop();
+ if (lifecycle != null)
return lifecycle.getMethodName();
+ return null;
+ }
+
+ public String getDefaultUninstallMethod()
+ {
return "stop";
}
- public List<ParameterMetaData> getUninstallParameters(KernelControllerContext context)
+ public String getUninstallAnnotation()
{
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStop();
+ return StopLifecycle.class.getName();
+ }
+
+ public List<ParameterMetaData> getUninstallParameters(BeanMetaData beanMetaData)
+ {
+ LifecycleMetaData lifecycle = beanMetaData.getStop();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/ManualMicrocontainerTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/ManualMicrocontainerTestDelegate.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/ManualMicrocontainerTestDelegate.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.junit;
+
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.Controller;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public class ManualMicrocontainerTestDelegate extends MicrocontainerTestDelegate
+{
+ public ManualMicrocontainerTestDelegate(Class clazz)
+ throws Exception
+ {
+ super(clazz);
+ }
+
+ public void change(KernelControllerContext context, ControllerState requied) throws Throwable
+ {
+ Controller controller = kernel.getController();
+ controller.change(context, requied);
+ }
+
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/test/kernel/junit/MicrocontainerTestDelegate.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -137,7 +137,7 @@
KernelController controller = kernel.getController();
KernelControllerContext context = (KernelControllerContext) controller.getContext(name, state);
if (context == null)
- throw new IllegalStateException("Bean not found " + name);
+ throw new IllegalStateException("Bean not found " + name + " at state " + state);
return context;
}
Added: projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.xml 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/resources/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.xml 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="LifecycleBean" class="org.jboss.test.kernel.deployment.support.AnnotatedLifecycleBean" mode="Manual" />
+
+</deployment>
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/AnnotatedLifecycleBean.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/AnnotatedLifecycleBean.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/support/AnnotatedLifecycleBean.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,81 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.deployment.support;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public class AnnotatedLifecycleBean
+{
+
+ private boolean m_create;
+ private boolean m_start;
+ private boolean m_stop;
+ private boolean m_destroy;
+
+ public boolean isCreate()
+ {
+ return m_create;
+ }
+
+ public boolean isStart()
+ {
+ return m_start;
+ }
+
+ public boolean isStop()
+ {
+ return m_stop;
+ }
+
+ public boolean isDestroy()
+ {
+ return m_destroy;
+ }
+
+ @org.jboss.beans.metadata.spi.annotations.CreateLifecycle
+ public void annotatedCreate()
+ {
+ m_create = true;
+ }
+
+ @org.jboss.beans.metadata.spi.annotations.StartLifecycle
+ public void annotatedStart()
+ {
+ m_start = true;
+ }
+
+ @org.jboss.beans.metadata.spi.annotations.StopLifecycle
+ public void annotatedStop()
+ {
+ m_start = false;
+ m_stop = true;
+ }
+
+ @org.jboss.beans.metadata.spi.annotations.DestroyLifecycle
+ public void annotatedDestroy()
+ {
+ m_create = false;
+ m_destroy = true;
+ }
+
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/AnnotatedLifecycleTestCase.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -0,0 +1,99 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.deployment.test;
+
+import junit.framework.Test;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.test.kernel.deployment.support.AnnotatedLifecycleBean;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.test.kernel.junit.ManualMicrocontainerTestDelegate;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * @author <a href="mailto:ales.justin at gmail.com">Ales Justin</a>
+ */
+public class AnnotatedLifecycleTestCase extends AbstractDeploymentTest
+{
+
+ private static final String BEAN_NAME = "LifecycleBean";
+
+ public AnnotatedLifecycleTestCase(String name) throws Throwable
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(AnnotatedLifecycleTestCase.class);
+ }
+
+ public void testAnnotetedLifecycle() throws Throwable
+ {
+ AnnotatedLifecycleBean target;
+
+ KernelControllerContext context = getControllerContext(BEAN_NAME, ControllerState.NOT_INSTALLED);
+
+ ManualMicrocontainerTestDelegate delegate = (ManualMicrocontainerTestDelegate) getMCDelegate();
+
+ delegate.change(context, ControllerState.DESCRIBED);
+ target = (AnnotatedLifecycleBean) context.getTarget();
+ assertNull(target);
+
+/*
+ delegate.change(context, ControllerState.CREATE);
+ target = (AnnotatedLifecycleBean) context.getTarget();
+ assertTrue(target.isCreate());
+ assertFalse(target.isStart());
+ assertFalse(target.isStop());
+ assertFalse(target.isDestroy());
+
+ delegate.change(context, ControllerState.START);
+ target = (AnnotatedLifecycleBean) context.getTarget();
+ assertTrue(target.isCreate());
+ assertTrue(target.isStart());
+ assertFalse(target.isStop());
+ assertFalse(target.isDestroy());
+
+ delegate.change(context, ControllerState.CREATE);
+ target = (AnnotatedLifecycleBean) context.getTarget();
+ assertTrue(target.isCreate());
+ assertFalse(target.isStart());
+ assertTrue(target.isStop());
+ assertFalse(target.isDestroy());
+
+ delegate.change(context, ControllerState.DESCRIBED);
+ target = (AnnotatedLifecycleBean) context.getTarget();
+ assertFalse(target.isCreate());
+ assertFalse(target.isStart());
+ assertTrue(target.isStop());
+ assertTrue(target.isDestroy());
+*/
+
+ }
+
+ public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+ {
+ return new ManualMicrocontainerTestDelegate(clazz);
+ }
+
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java 2006-10-26 19:20:36 UTC (rev 57858)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/test/DeploymentTestSuite.java 2006-10-26 19:39:29 UTC (rev 57859)
@@ -47,7 +47,8 @@
suite.addTest(GenericBeanFactoryLifecycleTestCase.suite());
suite.addTest(WildcardClassLoaderTestCase.suite());
suite.addTest(BeanMetaDataFactoryTestCase.suite());
-
+ suite.addTest(AnnotatedLifecycleTestCase.suite());
+
return suite;
}
}
More information about the jboss-cvs-commits
mailing list