[jboss-cvs] JBossAS SVN: r64149 - in trunk/system-jmx/src: resources/tests/org/jboss/test/system/metadata and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 19 23:50:32 EDT 2007
Author: scott.stark at jboss.org
Date: 2007-07-19 23:50:32 -0400 (Thu, 19 Jul 2007)
New Revision: 64149
Added:
trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceAnnotationMetaData.java
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/annotation/
trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/annotation/CompTypeAnno.xml
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/AnnotationUnitTestCase.java
trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/CompType.java
Modified:
trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaData.java
trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java
Log:
JBAS-4570, add annotations to service mbean metadata
Added: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceAnnotationMetaData.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceAnnotationMetaData.java (rev 0)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceAnnotationMetaData.java 2007-07-20 03:50:32 UTC (rev 64149)
@@ -0,0 +1,134 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.system.metadata;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+import org.jboss.annotation.factory.AnnotationCreator;
+import org.jboss.annotation.factory.ast.TokenMgrError;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.util.StringPropertyReplacer;
+
+/**
+ * Service annotation metadata
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class ServiceAnnotationMetaData extends JBossObject
+ implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ public String annotation;
+
+ protected Annotation ann;
+
+ protected boolean replace = true;
+
+ /**
+ * Create a new annotation meta data
+ */
+ public ServiceAnnotationMetaData()
+ {
+ super();
+ }
+ /**
+ * Create a new annotation meta data
+ * @param ann - the annotation declaration
+ */
+ public ServiceAnnotationMetaData(String ann)
+ {
+ super();
+ setAnnotation(ann);
+ }
+
+ public String getAnnotation()
+ {
+ return annotation;
+ }
+
+ public void setAnnotation(String annotation)
+ {
+ this.annotation = annotation;
+ }
+
+ public boolean isReplace()
+ {
+ return replace;
+ }
+
+ public void setReplace(boolean replace)
+ {
+ this.replace = replace;
+ }
+
+ public Annotation getAnnotationInstance()
+ {
+ try
+ {
+ String annString = annotation;
+ if (replace)
+ {
+ annString = StringPropertyReplacer.replaceProperties(annString);
+ }
+ ann = (Annotation)AnnotationCreator.createAnnotation(annString, Thread.currentThread().getContextClassLoader());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error creating annotation for " + annotation, e);
+ }
+ catch(TokenMgrError e)
+ {
+ throw new RuntimeException("Error creating annotation for " + annotation, e);
+ }
+
+ return ann;
+ }
+
+ public void toString(JBossStringBuilder buffer)
+ {
+ buffer.append("expr=").append(ann);
+ }
+
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ buffer.append(ann);
+ }
+
+ protected int getHashCode()
+ {
+ return annotation.hashCode();
+ }
+
+ public boolean equals(Object object)
+ {
+ if (object == null || object instanceof ServiceAnnotationMetaData == false)
+ return false;
+
+ ServiceAnnotationMetaData amd = (ServiceAnnotationMetaData)object;
+ return (replace == amd.replace) && annotation.equals(amd.annotation);
+ }
+
+}
Property changes on: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceAnnotationMetaData.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaData.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaData.java 2007-07-19 20:52:56 UTC (rev 64148)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaData.java 2007-07-20 03:50:32 UTC (rev 64149)
@@ -74,6 +74,8 @@
/** The dependencies */
private List<ServiceDependencyMetaData> dependencies = Collections.emptyList();
+ /** The annotations */
+ private List<ServiceAnnotationMetaData> annotations = Collections.emptyList();
/** The class loader */
private ObjectName classLoaderName;
@@ -291,6 +293,25 @@
}
/**
+ * Get the service annotations
+ * @return the annotations
+ */
+ public List<ServiceAnnotationMetaData> getAnnotations()
+ {
+ return annotations;
+ }
+ /**
+ * Set the service annotations
+ * @param annotation - the annotations metadata
+ */
+ public void setAnnotations(List<ServiceAnnotationMetaData> annotations)
+ {
+ if (annotations == null)
+ throw new IllegalArgumentException("Null annotations");
+ this.annotations = annotations;
+ }
+
+ /**
* Get the classLoaderName.
*
* @return the classLoaderName.
@@ -335,4 +356,5 @@
children.addAll(attributes);
children.addAll(dependencies);
}
+
}
Modified: trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java
===================================================================
--- trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java 2007-07-19 20:52:56 UTC (rev 64148)
+++ trunk/system-jmx/src/main/org/jboss/system/metadata/ServiceMetaDataParser.java 2007-07-20 03:50:32 UTC (rev 64149)
@@ -176,7 +176,7 @@
Element xmbeanDescriptor = parseXMBeanDescriptor(mbeanName, mbeanElement);
service.setXMBeanDescriptor(xmbeanDescriptor);
}
-
+ List<ServiceAnnotationMetaData> annotations = new ArrayList<ServiceAnnotationMetaData>();
List<ServiceAttributeMetaData> attributes = new ArrayList<ServiceAttributeMetaData>();
List<ServiceDependencyMetaData> dependencies = new ArrayList<ServiceDependencyMetaData>();
@@ -340,10 +340,17 @@
}
aliases.add(getElementTextContent(element, true, true));
}
+ else if (element.getTagName().equals("annotation"))
+ {
+ String ann = getElementTextContent(element, true, true);
+ ServiceAnnotationMetaData amd = new ServiceAnnotationMetaData(ann);
+ annotations.add(amd);
+ }
}
service.setAttributes(attributes);
service.setDependencies(dependencies);
+ service.setAnnotations(annotations);
services.add(service);
Added: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/annotation/CompTypeAnno.xml
===================================================================
--- trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/annotation/CompTypeAnno.xml (rev 0)
+++ trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/annotation/CompTypeAnno.xml 2007-07-20 03:50:32 UTC (rev 64149)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id$ -->
+<mbean name="jboss.test:type=BasicMBeanName" code="BasicMBeanCode">
+ <annotation>@org.jboss.test.system.metadata.annotation.CompType(type="DS",subtype="LocalTX")</annotation>
+</mbean>
Property changes on: trunk/system-jmx/src/resources/tests/org/jboss/test/system/metadata/annotation/CompTypeAnno.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/AnnotationUnitTestCase.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/AnnotationUnitTestCase.java (rev 0)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/AnnotationUnitTestCase.java 2007-07-20 03:50:32 UTC (rev 64149)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.system.metadata.annotation;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import org.jboss.annotation.factory.AnnotationCreator;
+import org.jboss.system.metadata.ServiceAnnotationMetaData;
+import org.jboss.system.metadata.ServiceMetaData;
+import org.jboss.test.system.metadata.test.AbstractMetaDataTest;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AnnotationUnitTestCase extends AbstractMetaDataTest
+{
+ public AnnotationUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testCompTypeAnno() throws Exception
+ {
+ compTypeAnno();
+ }
+
+ protected void compTypeAnno() throws Exception
+ {
+ ServiceMetaData metaData = unmarshalSingleMBean();
+ String exp = "@org.jboss.test.system.metadata.annotation.CompType(type=\"DS\",subtype=\"LocalTX\")";
+ assertAnnotation(metaData, exp, CompType.class);
+ assertOthers(metaData);
+ }
+
+ protected void assertAnnotation(ServiceMetaData metaData, String exp, Class c)
+ throws Exception
+ {
+ List<ServiceAnnotationMetaData> annotations = metaData.getAnnotations();
+ assertEquals("annotations.size", 1, annotations.size());
+ ServiceAnnotationMetaData amd = annotations.get(0);
+ assertNotNull(amd);
+ String amdExp = amd.getAnnotation();
+ assertEquals(exp, amdExp);
+ Object expAnn = AnnotationCreator.createAnnotation(exp, c);
+ Annotation ann = amd.getAnnotationInstance();
+ assertEquals(expAnn, ann);
+ }
+ protected void assertOthers(ServiceMetaData metaData) throws Exception
+ {
+ assertEquals(testBasicMBeanName, metaData.getObjectName());
+ assertEquals(testBasicMBeanCode, metaData.getCode());
+ assertNull(metaData.getInterfaceName());
+ assertDefaultConstructor(metaData);
+ assertNoAttributes(metaData);
+ assertNoXMBean(metaData);
+ }
+
+}
Property changes on: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/AnnotationUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/CompType.java
===================================================================
--- trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/CompType.java (rev 0)
+++ trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/CompType.java 2007-07-20 03:50:32 UTC (rev 64149)
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * 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.system.metadata.annotation;
+
+public @interface CompType
+{
+ String type();
+ String subtype();
+}
Property changes on: trunk/system-jmx/src/tests/org/jboss/test/system/metadata/annotation/CompType.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list