[jboss-cvs] JBossAS SVN: r58260 - in projects/microcontainer/trunk/aop-mc-int/src: main/org/jboss/aop/microcontainer/beans main/org/jboss/aop/microcontainer/beans/xml resources/schema resources/tests/org/jboss/test/microcontainer/test tests/org/jboss/test/microcontainer/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Nov 11 10:42:29 EST 2006
Author: kabir.khan at jboss.com
Date: 2006-11-11 10:42:20 -0500 (Sat, 11 Nov 2006)
New Revision: 58260
Added:
projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/LifecycleBeanMetaDataFactory.java
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.properties
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java
Modified:
projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/AspectBeanMetaDataFactory.java
projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/xml/AOPBeansSchemaInitializer.java
projects/microcontainer/trunk/aop-mc-int/src/resources/schema/aop-beans_1_0.xsd
Log:
[JBMICROCONT-108] Add support for <aop:lifecycle/>. This works similar to <aop:aspect> but in addition adds the interface introduction to handle the install/uninstall of the bean
Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/AspectBeanMetaDataFactory.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/AspectBeanMetaDataFactory.java 2006-11-11 14:54:55 UTC (rev 58259)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/AspectBeanMetaDataFactory.java 2006-11-11 15:42:20 UTC (rev 58260)
@@ -37,6 +37,7 @@
import org.jboss.beans.metadata.spi.InstallMetaData;
import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
/**
* AspectBeanMetaDataFactory.
@@ -110,7 +111,7 @@
AbstractBeanMetaData aspect = new AbstractBeanMetaData();
aspect.setName(aspectName);
aspect.setBean("org.jboss.aop.microcontainer.beans.Aspect");
- aspect.addProperty(new AbstractPropertyMetaData("manager", new AbstractDependencyValueMetaData(managerBean, managerProperty)));
+ aspect.addProperty(getAspectManagerPropertyMetaData("manager"));
result.add(aspect);
String aspectBindingName = name + "$AspectBinding";
@@ -119,7 +120,7 @@
aspectBinding.setBean("org.jboss.aop.microcontainer.beans.AspectBinding");
aspectBinding.addProperty(new AbstractPropertyMetaData("pointcut", pointcut));
aspectBinding.addProperty(new AbstractPropertyMetaData("aspect", new AbstractDependencyValueMetaData(aspectName, "definition")));
- aspectBinding.addProperty(new AbstractPropertyMetaData("manager", new AbstractDependencyValueMetaData(managerBean, managerProperty)));
+ aspectBinding.addProperty(getAspectManagerPropertyMetaData("manager"));
result.add(aspectBinding);
if (hasInjectedBeans())
@@ -135,6 +136,11 @@
return result;
}
+ protected PropertyMetaData getAspectManagerPropertyMetaData(String name)
+ {
+ return new AbstractPropertyMetaData(name, new AbstractDependencyValueMetaData(managerBean, managerProperty));
+ }
+
private void configureWithDependencies(AbstractBeanMetaData aspect, AbstractBeanMetaData aspectBinding)
{
aspect.addProperty(new AbstractPropertyMetaData("adviceBean", name));
Added: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/LifecycleBeanMetaDataFactory.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/LifecycleBeanMetaDataFactory.java 2006-11-11 14:54:55 UTC (rev 58259)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/LifecycleBeanMetaDataFactory.java 2006-11-11 15:42:20 UTC (rev 58260)
@@ -0,0 +1,76 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.aop.microcontainer.beans;
+
+import java.util.List;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractListMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.plugins.StringValueMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LifecycleBeanMetaDataFactory extends AspectBeanMetaDataFactory implements BeanMetaDataFactory
+{
+ String classes;
+
+ public String getClasses()
+ {
+ return classes;
+ }
+
+ public void setClasses(String classes)
+ {
+ this.classes = classes;
+ }
+
+ public List<BeanMetaData> getBeans()
+ {
+ List<BeanMetaData> beans = super.getBeans();
+
+ String aspectBindingName = name + "$IntroductionBinding";
+ AbstractBeanMetaData introductionBinding = new AbstractBeanMetaData();
+ introductionBinding.setName(aspectBindingName);
+ introductionBinding.setBean("org.jboss.aop.microcontainer.beans.IntroductionBinding");
+ introductionBinding.addProperty(getAspectManagerPropertyMetaData("manager"));
+ introductionBinding.addProperty(new AbstractPropertyMetaData("interfaces", getInterfaces()));
+ introductionBinding.addProperty(new AbstractPropertyMetaData("classes", getClasses()));
+ beans.add(introductionBinding);
+
+ return beans;
+ }
+
+ private ValueMetaData getInterfaces()
+ {
+ AbstractListMetaData interfaces = new AbstractListMetaData();
+ interfaces.setElementType("java.lang.String");
+ interfaces.add(new StringValueMetaData("org.jboss.kernel.spi.dependency.KernelControllerContextAware"));
+ return interfaces;
+ }
+}
Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/xml/AOPBeansSchemaInitializer.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/xml/AOPBeansSchemaInitializer.java 2006-11-11 14:54:55 UTC (rev 58259)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/xml/AOPBeansSchemaInitializer.java 2006-11-11 15:42:20 UTC (rev 58260)
@@ -25,6 +25,7 @@
import javax.xml.namespace.QName;
import org.jboss.aop.microcontainer.beans.AspectBeanMetaDataFactory;
+import org.jboss.aop.microcontainer.beans.LifecycleBeanMetaDataFactory;
import org.jboss.kernel.plugins.deployment.xml.BeanFactoryHandler;
import org.jboss.kernel.plugins.deployment.xml.BeanSchemaBinding20;
import org.jboss.kernel.plugins.deployment.xml.BeanSchemaBindingHelper;
@@ -48,6 +49,9 @@
/** The aspect binding */
private static final QName aspectTypeQName = new QName(AOP_BEANS_NS, "aspectType");
+ /** The lifecycle aspect binding */
+ private static final QName lifecycleTypeQName = new QName(AOP_BEANS_NS, "lifecycleType");
+
public SchemaBinding init(SchemaBinding schema)
{
// aspect binding
@@ -78,6 +82,36 @@
}
});
+ //lifecycle binding
+ TypeBinding lifecycleType = schema.getType(lifecycleTypeQName);
+ BeanSchemaBindingHelper.initBeanFactoryHandlers(lifecycleType);
+ lifecycleType.setHandler(new BeanFactoryHandler()
+ {
+ public Object startElement(Object parent, QName name, ElementBinding element)
+ {
+ return new LifecycleBeanMetaDataFactory();
+ }
+
+ public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
+ {
+ super.attributes(o, elementName, element, attrs, nsCtx);
+
+ LifecycleBeanMetaDataFactory factory = (LifecycleBeanMetaDataFactory) o;
+ for (int i = 0; i < attrs.getLength(); ++i)
+ {
+ String localName = attrs.getLocalName(i);
+ if ("pointcut".equals(localName))
+ factory.setPointcut(attrs.getValue(i));
+ else if ("manager-bean".equals(localName))
+ factory.setManagerBean(attrs.getValue(i));
+ else if ("manager-property".equals(localName))
+ factory.setManagerProperty(attrs.getValue(i));
+ else if ("classes".equals(localName))
+ factory.setClasses(attrs.getValue(i));
+ }
+ }
+ });
+
// TODO FIXME???
BeanSchemaBinding20.initArtifacts(schema);
Modified: projects/microcontainer/trunk/aop-mc-int/src/resources/schema/aop-beans_1_0.xsd
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/schema/aop-beans_1_0.xsd 2006-11-11 14:54:55 UTC (rev 58259)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/schema/aop-beans_1_0.xsd 2006-11-11 15:42:20 UTC (rev 58260)
@@ -47,5 +47,30 @@
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
+
+ <xsd:element name="lifecycle" type="lifecycleType">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[
+ An aspect intercepting when a bean is installed/uninstalled
+ ]]>
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <xsd:complexType name="lifecycleType">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[
+ An aspect
+ ]]>
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexContent>
+ <xsd:extension base="aspectType">
+ <xsd:attribute name="classes" type="xsd:string" use="required"/>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
</xsd:schema>
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.properties
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.properties 2006-11-11 14:54:55 UTC (rev 58259)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.properties 2006-11-11 15:42:20 UTC (rev 58260)
@@ -0,0 +1 @@
+test.Permission.1=javax.management.MBeanPermission, *#*, getMBeanInfo,invoke,registerMBean
\ No newline at end of file
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml 2006-11-11 14:54:55 UTC (rev 58259)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml 2006-11-11 15:42:20 UTC (rev 58260)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="MBeanServer" class="java.lang.Object">
+ <constructor factoryClass="javax.management.MBeanServerFactory" factoryMethod="createMBeanServer"/>
+ </bean>
+
+ <bean name="Repository" class="org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository"/>
+
+ <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+ <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+ </bean>
+
+ <aop:lifecycle xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="DependencyAdvice"
+ class="org.jboss.aop.microcontainer.aspects.jmx.JMXIntroduction"
+ classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX"
+ pointcut="execution(* @org.jboss.aop.microcontainer.aspects.jmx.JMX->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))">
+ <property name="mbeanServer"><inject bean="MBeanServer"/></property>
+ </aop:lifecycle>
+
+ <bean name="Bean" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="", exposedInterface=org.jboss.test.microcontainer.support.SimpleBean.class)</annotation>
+ </bean>
+</deployment>
Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java 2006-11-11 14:54:55 UTC (rev 58259)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java 2006-11-11 15:42:20 UTC (rev 58260)
@@ -0,0 +1,58 @@
+/*
+ * 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.microcontainer.test;
+
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.aop.microcontainer.junit.AOPMicrocontainerTest;
+
+public class JMXLifecycleTestCase extends AOPMicrocontainerTest
+{
+ public static Test suite()
+ {
+ return suite(JMXLifecycleTestCase.class);
+ }
+
+ public JMXLifecycleTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ public void testJMX() throws Exception
+ {
+ MBeanServer server = (MBeanServer) getBean("MBeanServer");
+ assertNotNull(server);
+
+ ObjectName name = new ObjectName("test:name='Bean'");
+ MBeanInfo info = server.getMBeanInfo(name);
+ assertNotNull(info);
+ MBeanOperationInfo[] ops = info.getOperations();
+ assertEquals(1, ops.length);
+ assertEquals("someMethod", ops[0].getName());
+ }
+}
More information about the jboss-cvs-commits
mailing list