[jboss-cvs] JBossAS SVN: r70462 - in projects/microcontainer/trunk/managed/src: main/org/jboss/managed/plugins and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 6 01:20:44 EST 2008
Author: scott.stark at jboss.org
Date: 2008-03-06 01:20:43 -0500 (Thu, 06 Mar 2008)
New Revision: 70462
Added:
projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/support/ManagementPropertyAnnotations.java
Modified:
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java
Log:
Add a hasViewUse accessor to ManagedProperty
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java 2008-03-06 06:12:07 UTC (rev 70461)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java 2008-03-06 06:20:43 UTC (rev 70462)
@@ -27,6 +27,7 @@
import java.util.Set;
import org.jboss.managed.api.annotation.ManagementObjectRef;
+import org.jboss.managed.api.annotation.ViewUse;
import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.values.MetaValue;
@@ -119,6 +120,15 @@
Map<String, Annotation> getAnnotations();
/**
+ * See if the property has the indicated ViewUse among its
+ * @ManagementProperty annotation uses.
+ *
+ * @param use - the ViewUse to check for
+ * @return true if the ViewUse exists in the property uses, false otherwise
+ */
+ boolean hasViewUse(ViewUse use);
+
+ /**
* Get the value
*
* @return the value
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java 2008-03-06 06:12:07 UTC (rev 70461)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java 2008-03-06 06:20:43 UTC (rev 70462)
@@ -33,6 +33,8 @@
import org.jboss.managed.api.Fields;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ViewUse;
import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValue;
@@ -217,6 +219,29 @@
setField(Fields.ANNOTATIONS, (Serializable) annotations);
}
+ /**
+ * See if the property has the indicated ViewUse among its
+ * @ManagementProperty annotation uses.
+ *
+ * @param use - the ViewUse to check for
+ * @return true if the ViewUse exists in the property uses, false otherwise
+ */
+ public boolean hasViewUse(ViewUse use)
+ {
+ boolean hasViewUse = false;
+ Map<String, Annotation> annotations = getAnnotations();
+ if(annotations != null)
+ {
+ ManagementProperty mp = (ManagementProperty) annotations.get(ManagementProperty.class.getName());
+ if(mp != null)
+ {
+ for(ViewUse vu : mp.use())
+ hasViewUse |= vu == use;
+ }
+ }
+ return hasViewUse;
+ }
+
public MetaType getMetaType()
{
return getField(Fields.META_TYPE, MetaType.class);
Added: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/support/ManagementPropertyAnnotations.java
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/support/ManagementPropertyAnnotations.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/support/ManagementPropertyAnnotations.java 2008-03-06 06:20:43 UTC (rev 70462)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.managed.factory.support;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ViewUse;
+
+/**
+ * Test property annotations
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at ManagementObject
+public class ManagementPropertyAnnotations implements Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -1L;
+
+ /**
+ * Get property
+ *
+ * @return null
+ */
+ @ManagementProperty(description="Property with extra annotations",
+ use={ViewUse.RUNTIME})
+ @ManagementObjectID(name="SomeObject", type="SomeType")
+ public String getRuntime()
+ {
+ return null;
+ }
+
+ @ManagementProperty(description="Property with CONFIGURATION use",
+ use={ViewUse.CONFIGURATION})
+ public String getConfiguration()
+ {
+ return null;
+ }
+ public void setConfiguration(String config)
+ {
+ }
+
+ @ManagementProperty(description="Property with STATISTIC use",
+ use={ViewUse.STATISTIC})
+ public String getStat()
+ {
+ return null;
+ }
+}
Property changes on: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/support/ManagementPropertyAnnotations.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java 2008-03-06 06:12:07 UTC (rev 70461)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/factory/test/ManagementPropertyUnitTestCase.java 2008-03-06 06:20:43 UTC (rev 70462)
@@ -21,10 +21,18 @@
*/
package org.jboss.test.managed.factory.test;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
import junit.framework.Test;
import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ViewUse;
import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.ManagementPropertyAnnotations;
import org.jboss.test.managed.factory.support.ManagementPropertyDescription;
import org.jboss.test.managed.factory.support.ManagementPropertyMandatory;
import org.jboss.test.managed.factory.support.ManagementPropertySimpleManaged;
@@ -84,4 +92,37 @@
ManagedObject managedObject = checkManagedObject(test);
checkPropertyIsManagedObject(managedObject, "property", "property", false, test.getProperty());
}
+
+ /**
+ * Test property annotations
+ */
+ public void testAnnotations()
+ {
+ ManagedObject managedObject = createAndCheckDefaultManagedObject(ManagementPropertyAnnotations.class);
+ ManagedProperty managedProperty = managedObject.getProperty("runtime");
+ assertNotNull(managedProperty);
+ Map<String, Annotation> annotations = managedProperty.getAnnotations();
+ assertEquals(2, annotations.size());
+ assertTrue(annotations.containsKey(ManagementProperty.class.getName()));
+ assertTrue(annotations.containsKey(ManagementObjectID.class.getName()));
+ }
+
+ /**
+ * Test property ViewUse
+ */
+ public void testViewUse()
+ {
+ ManagedObject managedObject = createAndCheckDefaultManagedObject(ManagementPropertyAnnotations.class);
+ ManagedProperty runtime = managedObject.getProperty("runtime");
+ assertNotNull(runtime);
+ assertTrue("has ViewUse.RUNTIME", runtime.hasViewUse(ViewUse.RUNTIME));
+ assertTrue("!has ViewUse.CONFIGURATION", !runtime.hasViewUse(ViewUse.CONFIGURATION));
+ assertTrue("!has ViewUse.STATISTIC", !runtime.hasViewUse(ViewUse.STATISTIC));
+
+ ManagedProperty configuration = managedObject.getProperty("configuration");
+ assertTrue("has ViewUse.CONFIGURATION", configuration.hasViewUse(ViewUse.CONFIGURATION));
+
+ ManagedProperty stat = managedObject.getProperty("stat");
+ assertTrue("has ViewUse.STATISTIC", stat.hasViewUse(ViewUse.STATISTIC));
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list