[jboss-cvs] JBossAS SVN: r84191 - in projects/jboss-man/trunk/managed/src: main/java/org/jboss/managed/api/annotation and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 13 12:07:25 EST 2009


Author: scott.stark at jboss.org
Date: 2009-02-13 12:07:25 -0500 (Fri, 13 Feb 2009)
New Revision: 84191

Added:
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/MutableManagedComponent.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunState.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunStateMapper.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/RunStateProperty.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/StringRunStateMapper.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/RunStateBean.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagedDeploymentUnitTestCase.java
Modified:
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedCommon.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedComponent.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedObject.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedCommonImpl.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedComponentImpl.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
   projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java
   projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementDeploymentUnitTestCase.java
Log:
JBMAN-51, explicitly define a component run state

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedCommon.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedCommon.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedCommon.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -27,6 +27,7 @@
 
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
 
 /**
  * ManagedCommon is used to hold common
@@ -54,6 +55,7 @@
     * @return the name
     */
    String getName();
+
    /**
     * Get the external name type/qualifier.
     * @see {@linkplain ManagementObject#type}
@@ -63,6 +65,14 @@
    String getNameType();
 
    /**
+    * Get the runtime component name.
+    *
+    * @see {@linkplain ManagementRuntimeRef}
+    * @return name of runtime component if one exists, null if no component exists.
+    */
+   Object getComponentName();
+
+   /**
     * Get the property names
     *
     * @return the property names

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedComponent.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedComponent.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedComponent.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -36,6 +36,12 @@
    public ComponentType getType();
    
    /**
+    * Get the component run state
+    * @return
+    */
+   public RunState getRunState();
+
+   /**
     * The deployment the component is associated with.
     * @return component deployment.
     */

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedObject.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedObject.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedObject.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -60,14 +60,6 @@
    public Map<String, Annotation> getAnnotations();
 
    /**
-    * Get the runtime component name.
-    *
-    * @see {@linkplain ManagementRuntimeRef}
-    * @return name of runtime component if one exists, null if no component exists.
-    */
-   Object getComponentName();
-
-   /**
     * Get the parent ManagedObject
     * @return the parent if one exists, null otherwise
     */
@@ -96,10 +88,10 @@
    <T> T getTransientAttachment(Class<T> expectedType);
 
    /**
-    * Set an transient attachment against the property. A transient attachment
+    * Set a transient attachment against the property. A transient attachment
     * is one that will not be available to clients of the property, typically
     * admin tools. Such attachments are used by the server side where the
-    * underlying metadata to which the property is 
+    * underlying metadata to which the property is associated is available.
     * 
     * @param name the name
     * @param attachment the attachment, pass null to remove an attachment

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -120,6 +120,13 @@
    Map<String, Annotation> getAnnotations();
 
    /**
+    * Does the property have the annotation referenced by key.
+    * @param key the key into {@link #getAnnotations()}
+    * @return true if the annotation exists, false otherwise.
+    */
+   boolean hasAnnotation(String key);
+
+   /**
     * See if the property has the indicated ViewUse among its
     * @ManagementProperty annotation uses.
     * 

Added: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/MutableManagedComponent.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/MutableManagedComponent.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/MutableManagedComponent.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.api;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface MutableManagedComponent extends ManagedComponent
+{
+   /**
+    * 
+    * @param runState
+    */
+   public void setRunState(RunState runState);
+}


Property changes on: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/MutableManagedComponent.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunState.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunState.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunState.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.api;
+
+/**
+ * Enum for the ManagedComponent run state
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public enum RunState
+{
+   STARTING,
+   RUNNING,
+   STOPPING,
+   STOPPED,
+   FAILED,
+   UNKNOWN
+}


Property changes on: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunState.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunStateMapper.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunStateMapper.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunStateMapper.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.api;
+
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * An interface for mapping a property meta value to a RunState.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface RunStateMapper
+{
+   /**
+    * Map from the given property meta value to a RunState
+    * 
+    * @param property - the property supplying the value
+    * @param value - the property meta value
+    * @return the RunState. This may be Unknown if the value could not
+    * be mapped to an known run state.
+    */
+   public RunState getRunState(ManagedProperty property, MetaValue value);
+}


Property changes on: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/RunStateMapper.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/RunStateProperty.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/RunStateProperty.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/api/annotation/RunStateProperty.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.managed.api.RunStateMapper;
+
+/**
+ * An annotation one can use on a ManagedProperty to indicate that the property
+ * provides RunState value information. The metaValues, enumValues attributes
+ * can be used to pass information to the RunStateMapper class ctor. If both
+ * metaValues, enumValues are non-zero arrays, a
+ * ctor(String[] metaValues, String[] enumValues) is used to instantiate the
+ * RunStateMapper. Otherwise, the default ctor will be used.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at Target({ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface RunStateProperty
+{
+   /** The class to use for the RunStateMapper implementation */
+   Class<? extends RunStateMapper> value();
+   /** Optional meta value strings for the */
+   String[] metaValues() default {};
+   String[] enumValues() default {};
+}

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedCommonImpl.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedCommonImpl.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/DelegateManagedCommonImpl.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -61,6 +61,11 @@
       return delegate.getNameType();
    }
 
+   public Object getComponentName()
+   {
+      return delegate.getComponentName();
+   }
+
    public Set<ManagedOperation> getOperations()
    {
       return delegate.getOperations();

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedComponentImpl.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedComponentImpl.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedComponentImpl.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -22,11 +22,18 @@
 package org.jboss.managed.plugins;
 
 import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.util.Map;
 
 import org.jboss.managed.api.ComponentType;
-import org.jboss.managed.api.ManagedComponent;
 import org.jboss.managed.api.ManagedDeployment;
 import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.MutableManagedComponent;
+import org.jboss.managed.api.RunState;
+import org.jboss.managed.api.RunStateMapper;
+import org.jboss.managed.api.annotation.RunStateProperty;
+import org.jboss.metatype.api.values.MetaValue;
 
 /**
  * Managed component impl.
@@ -35,20 +42,100 @@
  * @version $Revision$
  */
 public class ManagedComponentImpl extends DelegateManagedCommonImpl
-   implements ManagedComponent, Serializable
+   implements MutableManagedComponent, Serializable
 {
    private static final long serialVersionUID = 1;
    
    private ManagedDeployment owner;
    private ComponentType type;
+   private RunState runState = RunState.UNKNOWN;
+   private transient RunStateMapper stateMapper;
+   private transient ManagedProperty stateProperty;
    
    public ManagedComponentImpl(ComponentType type, ManagedDeployment owner, ManagedObject mo)
    {
+      this(type, owner, mo, null);
+   }
+   public ManagedComponentImpl(ComponentType type, ManagedDeployment owner, ManagedObject mo,
+         RunStateMapper stateMapper)
+   {
       super(mo);
       this.type = type;
       this.owner = owner;
+      this.stateMapper = stateMapper;
+      // Determine what the run state property is
+      Map<String, ManagedProperty> props = mo.getProperties();
+      if(props != null)
+      {
+         for(ManagedProperty prop : props.values())
+         {
+            if(prop.hasAnnotation(RunStateProperty.class.getName()))
+            {
+               stateProperty = prop;
+               if(stateMapper == null)
+               {
+                  // Try to create it from the RunStateProperty
+                  RunStateProperty rsp = (RunStateProperty) prop.getAnnotations().get(RunStateProperty.class.getName());
+                  String[] metaValues = rsp.metaValues();
+                  String[] enumValues = rsp.enumValues();
+                  try
+                  {
+                     Constructor<? extends RunStateMapper> ctor = rsp.value().getConstructor(metaValues.getClass(), enumValues.getClass());
+                     this.stateMapper = ctor.newInstance(metaValues, enumValues);
+                  }
+                  catch (Exception e)
+                  {
+                     try
+                     {
+                        this.stateMapper = rsp.value().newInstance();
+                     }
+                     catch (Exception e1)
+                     {
+                     }
+                  }
+               }
+               // Cache the run state
+               runState = updateRunState();
+               break;
+            }
+         }
+      }
    }
 
+   public RunStateMapper getStateMapper()
+   {
+      return stateMapper;
+   }
+   public void setStateMapper(RunStateMapper stateMapper)
+   {
+      this.stateMapper = stateMapper;
+   }
+
+   public RunState getRunState()
+   {
+      return runState;
+   }
+   public void setRunState(RunState runState)
+   {
+      this.runState = runState;
+   }
+
+   /**
+    * Update the cached run state
+    * @return the updated cache state
+    */
+   public RunState updateRunState()
+   {
+      RunState state = RunState.UNKNOWN;
+      if(stateMapper != null && stateProperty != null)
+      {
+         MetaValue value = stateProperty.getValue();
+         state = stateMapper.getRunState(stateProperty, value);
+         this.runState = state;
+      }
+      return runState;
+   }
+
    public ManagedDeployment getDeployment()
    {
       return owner;

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -224,6 +224,19 @@
       setField(Fields.ANNOTATIONS, (Serializable) annotations);      
    }
 
+   
+   public boolean hasAnnotation(String key)
+   {
+      boolean hasAnnotation = false;
+      // Look to the ManagementProperty annotation
+      Map<String, Annotation> annotations = getAnnotations();
+      if(annotations != null)
+      {
+         hasAnnotation = annotations.containsKey(key);
+      }
+      return hasAnnotation;
+   }
+
    /**
     * See if the property has the indicated ViewUse among its
     * @ManagementProperty annotation or VIEW_USE field uses.

Modified: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -59,6 +59,7 @@
 import org.jboss.managed.api.annotation.ManagementProperty;
 import org.jboss.managed.api.annotation.ManagementPropertyFactory;
 import org.jboss.managed.api.annotation.ManagementRuntimeRef;
+import org.jboss.managed.api.annotation.RunStateProperty;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
 import org.jboss.managed.api.factory.ManagedObjectDefinition;
 import org.jboss.managed.plugins.DefaultFieldsImpl;
@@ -529,6 +530,7 @@
             ManagementObjectID id = getAnnotation(ManagementObjectID.class, propertyInfo, metaData);
             ManagementObjectRef ref = getAnnotation(ManagementObjectRef.class, propertyInfo, metaData);
             ManagementRuntimeRef runtimeRef = getAnnotation(ManagementRuntimeRef.class, propertyInfo, metaData);
+            RunStateProperty rsp = getAnnotation(RunStateProperty.class, propertyInfo, metaData);
             HashMap<String, Annotation> propAnnotations = new HashMap<String, Annotation>();
             if (managementProperty != null)
                propAnnotations.put(ManagementProperty.class.getName(), managementProperty);
@@ -542,6 +544,8 @@
                propAnnotations.put(ManagementObjectRef.class.getName(), ref);
             if (runtimeRef != null)
                propAnnotations.put(ManagementRuntimeRef.class.getName(), runtimeRef);
+            if (rsp != null)
+               propAnnotations.put(RunStateProperty.class.getName(), rsp);
 
             // Check whether this property should be included
             boolean includeProperty = false;

Added: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/StringRunStateMapper.java
===================================================================
--- projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/StringRunStateMapper.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/StringRunStateMapper.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.plugins.factory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.RunState;
+import org.jboss.managed.api.RunStateMapper;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * A RunStateMapper implementation that maps string based meta values to
+ * the RunState enum based on a Map<String,String> of meta value to enum
+ * string.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class StringRunStateMapper implements RunStateMapper
+{
+   private Map<String, String> valueMapping = new HashMap<String, String>();
+
+   public StringRunStateMapper()
+   {
+      
+   }
+   public StringRunStateMapper(String[] valueStrings, String[] enumStrings)
+   {
+      for(int n = 0; n < valueStrings.length; n ++)
+      {
+         String value = valueStrings[n];
+         String enums = enumStrings[n];
+         valueMapping.put(value, enums);
+      }
+   }
+
+   public Map<String, String> getValueMapping()
+   {
+      return valueMapping;
+   }
+   public void setValueMapping(Map<String, String> valueMapping)
+   {
+      this.valueMapping = valueMapping;
+   }
+
+   public RunState getRunState(ManagedProperty property, MetaValue value)
+   {
+      RunState state = RunState.UNKNOWN;
+      if ( value.getMetaType().isSimple() )
+      {
+         SimpleValue sv = SimpleValue.class.cast(value);
+         String s = sv.getValue().toString();
+         String es = valueMapping.get(s);
+         if(es != null)
+         {
+            state = RunState.valueOf(es);
+         }
+      }
+      else if (value.getMetaType().isEnum() )
+      {
+         
+      }
+      return state;
+   }
+
+}


Property changes on: projects/jboss-man/trunk/managed/src/main/java/org/jboss/managed/plugins/factory/StringRunStateMapper.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Added: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/RunStateBean.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/RunStateBean.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/RunStateBean.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.factory.support;
+
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.RunStateProperty;
+import org.jboss.managed.plugins.factory.StringRunStateMapper;
+
+/**
+ * Tests of the RunState view of a ManagedComponent
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class RunStateBean
+{
+   private String state;
+
+   @ManagementProperty
+   @RunStateProperty(value=StringRunStateMapper.class,
+         metaValues={"State0", "State1", "ErrorState"},
+         enumValues={"RUNNING", "STOPPED", "FAILED"}
+   )
+   public String getState()
+   {
+      return state;
+   }
+
+   public void setState(String state)
+   {
+      this.state = state;
+   }
+}

Modified: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/support/deployment/JmsDestination.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -25,7 +25,9 @@
 
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.RunStateProperty;
 import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.managed.plugins.factory.StringRunStateMapper;
 
 /**
  * @author Scott.Stark at jboss.org
@@ -38,7 +40,24 @@
    private static final long serialVersionUID = 1;
    private String jndiName;
    private SecDomainMD domain;
+   private String state;
 
+   
+   @ManagementProperty(description="The destination state",
+         use={ViewUse.STATISTIC}, includeInTemplate=false)
+   @RunStateProperty(value=StringRunStateMapper.class,
+         metaValues={"State0", "State1", "ErrorState"},
+         enumValues={"RUNNING", "STOPPED", "FAILED"}
+   )
+   public String getState()
+   {
+      return state;
+   }
+   public void setState(String state)
+   {
+      this.state = state;
+   }
+
    @ManagementProperty(description="JNDI binding location of destination", includeInTemplate=true)
    public String getJndiName()
    {

Added: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagedDeploymentUnitTestCase.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagedDeploymentUnitTestCase.java	                        (rev 0)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagedDeploymentUnitTestCase.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.managed.factory.test;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.RunState;
+import org.jboss.managed.api.RunStateMapper;
+import org.jboss.managed.api.ManagedDeployment.DeploymentPhase;
+import org.jboss.managed.api.annotation.ManagementDeployment;
+import org.jboss.managed.plugins.ManagedComponentImpl;
+import org.jboss.managed.plugins.ManagedDeploymentImpl;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.deployment.JmsDestination;
+import org.jboss.test.managed.factory.support.deployment.JmsDestinations;
+import org.jboss.test.managed.factory.support.deployment.QueueDestination;
+import org.jboss.test.managed.factory.support.deployment.SecurityDomain;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ManagedDeploymentUnitTestCase extends AbstractManagedObjectFactoryTest
+{
+   public ManagedDeploymentUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testManagementDeploymentMO()
+   {
+      getLog().info("JmsDestinations.CS: "+JmsDestinations.class.getProtectionDomain().getCodeSource());
+      JmsDestinations destinations = new JmsDestinations();
+      List<JmsDestination> queues = new ArrayList<JmsDestination>();
+      QueueDestination q1 = new QueueDestination();
+      q1.setJndiName("queues/Q1");
+      q1.setDomain(new SecurityDomain("java:/jaas/JMS"));
+      q1.setState("State0");
+      queues.add(q1);
+      destinations.setDestinations(queues);
+
+      ManagedObject mo = initManagedObject(destinations);
+      assertNotNull(mo);
+      Map<String, Annotation> annotations = mo.getAnnotations();
+      getLog().info(annotations);
+      ManagementDeployment mda = (ManagementDeployment) annotations.get(ManagementDeployment.class.getName());
+      assertNotNull(mda);
+      assertEquals(DeploymentPhase.APPLICATION, mda.phase());
+      assertEquals(1, mda.types().length);
+      assertEquals("jms", mda.types()[0]);
+
+      // Create a ManagedDeployment for the root MO
+      Map<String, ManagedObject> unitMOs = Collections.singletonMap(JmsDestinations.class.getName(), mo);
+      ManagedDeploymentImpl md = new ManagedDeploymentImpl("testManagementDeploymentMO",
+            "testManagementDeploymentMO", DeploymentPhase.APPLICATION, null, unitMOs);
+      // Create ManagedComponents for the destinations
+      ManagedProperty destinationsMP = mo.getProperty("destinations");
+      assertNotNull(destinationsMP);
+      CollectionValue destinationsValue = (CollectionValue) destinationsMP.getValue();
+      assertNotNull(destinationsValue);
+      assertEquals(1, destinationsValue.getSize());
+      GenericValue q1GV = (GenericValue) destinationsValue.getElements()[0];
+      assertNotNull(q1GV);
+      ManagedObject q1MO = (ManagedObject) q1GV.getValue();
+      assertNotNull(q1MO);
+
+      ComponentType type = new ComponentType("JMSDestination", "queue");
+      RunStateMapper stateMapper = null;
+      ManagedComponentImpl mc = new ManagedComponentImpl(type, md, q1MO, stateMapper);
+      md.addComponent(q1MO.getName(), mc);
+
+      RunState state = mc.getRunState();
+      assertEquals(RunState.RUNNING, state);
+   }
+}

Modified: projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementDeploymentUnitTestCase.java
===================================================================
--- projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementDeploymentUnitTestCase.java	2009-02-13 17:03:56 UTC (rev 84190)
+++ projects/jboss-man/trunk/managed/src/test/java/org/jboss/test/managed/factory/test/ManagementDeploymentUnitTestCase.java	2009-02-13 17:07:25 UTC (rev 84191)
@@ -48,7 +48,7 @@
     * Test that the ManagementDeployment annotation shows up on the root
     * ManagedObject
     */
-   public void testManagementDeploymentonMO()
+   public void testManagementDeploymentMO()
    {
       getLog().info("JmsDestinations.CS: "+JmsDestinations.class.getProtectionDomain().getCodeSource());
       Annotation[] reflectAnnotations = JmsDestinations.class.getAnnotations();




More information about the jboss-cvs-commits mailing list