[jboss-cvs] JBossAS SVN: r65897 - in projects/microcontainer/trunk: managed/src/main/org/jboss/managed/api and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Oct 6 14:48:59 EDT 2007


Author: alesj
Date: 2007-10-06 14:48:59 -0400 (Sat, 06 Oct 2007)
New Revision: 65897

Added:
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedCommon.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementRuntimeRef.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedCommonImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractComponentNameTransformer.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/ObjectNameTransformer.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/RuntimeComponentNameTransformer.java
Modified:
   projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedComponent.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedObjectImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedComponentImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
Log:
Added ManagementRuntimeRef marking ManagedObject runtime component name.
Introduced ManagedCommon, joining common propertys of ManagedObject and ManagedComponent.
Setting WritethroughManagedPropertyImpl as default server side ManagedProperty instance.

Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractBeanMetaData.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -51,6 +51,7 @@
 import org.jboss.dependency.spi.DependencyItem;
 import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
 import org.jboss.reflect.spi.TypeInfo;
 import org.jboss.util.JBossObject;
 import org.jboss.util.JBossStringBuilder;
@@ -326,6 +327,7 @@
       flushJBossObjectCache();
    }
 
+   @ManagementRuntimeRef
    public String getName()
    {
       return name;

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedCommon.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedCommon.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedCommon.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.managed.api;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * ManagedCommon is used to hold common
+ * properties that both, server side and client side,
+ * object can see                                    .
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface ManagedCommon extends Serializable
+{
+   /**
+    * Get the attachment name
+    * @see {@linkplain ManagementObject#attachmentName}}
+    *
+    * @return the name
+    */
+   String getAttachmentName();
+
+   /**
+    * Get the external name by which the ManagedObject is known
+    * @see {@linkplain ManagementObject#name}}
+    * @see {@linkplain ManagementObjectID#name}}
+    * @return
+    */
+   String getName();
+   /**
+    * Get the external name type/qualifier.
+    * @see {@linkplain ManagementObject#type}
+    * @see {@linkplain ManagementObjectID#type}
+    * @return
+    */
+   String getNameType();
+
+   /**
+    * Get the property names
+    *
+    * @return the property names
+    */
+   Set<String> getPropertyNames();
+
+   /**
+    * Get a property
+    *
+    * @param name the name
+    * @return the property
+    */
+   ManagedProperty getProperty(String name);
+
+   /**
+    * Get the properties
+    *
+    * @return the properties
+    */
+   Map<String, ManagedProperty> getProperties();
+
+   /**
+    * Get the operations
+    *
+    * @return the operations
+    */
+   Set<ManagedOperation> getOperations();
+}

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedComponent.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedComponent.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedComponent.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -27,7 +27,7 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */
-public interface ManagedComponent extends ManagedObject
+public interface ManagedComponent extends ManagedCommon
 {
    /**
     * The component classification as a type/subtype.

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -24,7 +24,6 @@
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.util.Map;
-import java.util.Set;
 
 /**
  * ManagedObject is an interface for a manageable element. It
@@ -41,32 +40,9 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision: 1.1 $
  */
-public interface ManagedObject extends Serializable
+public interface ManagedObject extends ManagedCommon
 {
    /**
-    * Get the external name by which the ManagedObject is known
-    * @see {@linkplain ManagementObject#name}}
-    * @see {@linkplain ManagementObjectID#name}}
-    * @return
-    */
-   String getName();
-   /**
-    * Get the external name type/qualifier.
-    * @see {@linkplain ManagementObject#type}
-    * @see {@linkplain ManagementObjectID#type}
-    * @return
-    */
-   String getNameType();
-
-   /**
-    * Get the attachment name
-    * @see {@linkplain ManagementObject#attachmentName}}
-    * 
-    * @return the name
-    */
-   String getAttachmentName();
-
-   /**
     * Get the underlying object
     * 
     * @return the underlying object
@@ -80,31 +56,10 @@
    public Map<String, Annotation> getAnnotations();
 
    /**
-    * Get the property names
-    * 
-    * @return the property names
+    * Get the runtime component name.
+    *
+    * @see {@linkplain ManagementRuntimeRef}
+    * @return name of runtime component if one exists, null if no component exists.
     */
-   Set<String> getPropertyNames();
-
-   /**
-    * Get a property
-    * 
-    * @param name the name
-    * @return the property
-    */
-   ManagedProperty getProperty(String name);
-   
-   /**
-    * Get the properties
-    * 
-    * @return the properties
-    */
-   Map<String, ManagedProperty> getProperties();
-
-   /**
-    * Get the operations
-    * 
-    * @return the operations
-    */
-   Set<ManagedOperation> getOperations();
+   Object getComponentName();
 }

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementObjectRef.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -38,12 +38,13 @@
 {
    /** An explicit ManagedObject name. If empty, the name is
     * taken from the annotated property.
-    * @see {@linkplain ManagedObject#getExternalName()}
+    * @see {@linkplain ManagedObject#getName()}
     */
+
    String name() default AnnotationDefaults.EMPTY_STRING;
    /** A qualifier for the name that provides a context to
     * identify the type or scope of the ManagedObject name.
-    * @see {@linkplain ManagedObject#getExternalNameType()}
+    * @see {@linkplain ManagedObject#getNameType()}
     */
    String type() default AnnotationDefaults.EMPTY_STRING;
 }

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementProperty.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -70,37 +70,34 @@
    /** The class to use for the ManagedProperty Fields implementation */
    Class<? extends Fields> fieldsFactory() default NULL_FIELDS_FACTORY.class;
    /** The constraints, allowed values populator factory */
-   Class<? extends ManagedPropertyConstraintsPopulatorFactory> constraintsFactory()
-      default NULL_CONSTRAINTS.class;
+   Class<? extends ManagedPropertyConstraintsPopulatorFactory> constraintsFactory() default NULL_CONSTRAINTS.class;
 
    /**
     * Used in {@link ManagementProperty#constraintsFactory()} to
     * signal that the factory be inferred from the type
     * of the property.
     */
-   public static final class NULL_CONSTRAINTS
-      implements ManagedPropertyConstraintsPopulatorFactory
+   public static final class NULL_CONSTRAINTS implements ManagedPropertyConstraintsPopulatorFactory
    {
       public ManagedPropertyConstraintsPopulator newInstance()
       {
          return null;
       }
    }
+
    /**
     * Used in {@link ManagementProperty#fieldsFactory()} to
     * indicate that no Fields factory is defined.
     */
-   public static abstract class NULL_FIELDS_FACTORY
-      implements Fields
+   public static abstract class NULL_FIELDS_FACTORY implements Fields
    {
    }
+
    /**
-    * Used in {@link ManagementProperty#fieldsFactory()} to
-    * indicate that no Fields factory is defined.
+    * Used in {@link ManagementProperty#propertyFactory()} to
+    * indicate that no ManagedProperty factory is defined.
     */
-   public static abstract class NULL_PROPERTY_FACTORY
-      implements ManagedProperty
+   public static abstract class NULL_PROPERTY_FACTORY implements ManagedProperty
    {
    }
-
 }

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementRuntimeRef.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementRuntimeRef.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/annotation/ManagementRuntimeRef.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.managed.api.annotation;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.jboss.managed.spi.factory.RuntimeComponentNameTransformer;
+
+/**
+ * ManagementRuntimeRef annotation that can be used
+ * to identify which property defines the component name.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Target({ElementType.METHOD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ManagementRuntimeRef
+{
+   /**
+    * The name transformer.
+    *
+    * @return the transformer class
+    */
+   Class<? extends RuntimeComponentNameTransformer> transformer() default DEFAULT_NAME_TRANSFORMER.class;
+
+   /**
+    * Used in {@link @ManagementRuntimeRef#transformer()} to
+    * indicate that no name transformation is defined.
+    */
+   public static final class DEFAULT_NAME_TRANSFORMER implements RuntimeComponentNameTransformer
+   {
+      public Object transform(Object value)
+      {
+         return value;
+      }
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedCommonImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedCommonImpl.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedCommonImpl.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -0,0 +1,81 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.managed.plugins;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.ManagedCommon;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * Delegate managed common.
+ *
+ * @author ales.justin at jboss.org
+ */
+public class DelegateManagedCommonImpl implements ManagedCommon
+{
+   private static final long serialVersionUID = 1;
+   private ManagedObject delegate;
+
+   public DelegateManagedCommonImpl(ManagedObject delegate)
+   {
+      this.delegate = delegate;
+   }
+
+   public String getAttachmentName()
+   {
+      return delegate.getAttachmentName();
+   }
+
+   public String getName()
+   {
+      return delegate.getName();
+   }
+
+   public String getNameType()
+   {
+      return delegate.getNameType();
+   }
+
+   public Set<ManagedOperation> getOperations()
+   {
+      return delegate.getOperations();
+   }
+
+   public Map<String, ManagedProperty> getProperties()
+   {
+      return delegate.getProperties();
+   }
+
+   public ManagedProperty getProperty(String name)
+   {
+      return delegate.getProperty(name);
+   }
+
+   public Set<String> getPropertyNames()
+   {
+      return delegate.getPropertyNames();
+   }
+}

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedObjectImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedObjectImpl.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DelegateManagedObjectImpl.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -35,8 +35,7 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */
-public class DelegateManagedObjectImpl
-   implements ManagedObject
+public class DelegateManagedObjectImpl implements ManagedObject
 {
    private static final long serialVersionUID = 1;
    private ManagedObject delegate;
@@ -91,5 +90,8 @@
       return delegate.getPropertyNames();
    }
 
-   
+   public Object getComponentName()
+   {
+      return delegate.getComponentName();
+   }
 }

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedComponentImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedComponentImpl.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedComponentImpl.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -29,11 +29,12 @@
 import org.jboss.managed.api.ManagedObject;
 
 /**
- * 
+ * Managed component impl.
+ *
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */
-public class ManagedComponentImpl extends DelegateManagedObjectImpl
+public class ManagedComponentImpl extends DelegateManagedCommonImpl
    implements ManagedComponent, Serializable
 {
    private static final long serialVersionUID = 1;

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -61,6 +61,9 @@
    /** The operations */
    private Set<ManagedOperation> operations;
 
+   /** The runtime component name */
+   private transient Object componentName;
+
    /**
     * Create a new ManagedObjectImpl
     * 
@@ -250,6 +253,16 @@
       this.operations = operations;
    }
 
+   public Object getComponentName()
+   {
+      return componentName;
+   }
+
+   public void setComponentName(Object name)
+   {
+      this.componentName = name;
+   }
+
    @Override
    public boolean equals(Object obj)
    {

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/WritethroughManagedPropertyImpl.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -21,6 +21,7 @@
  */
 package org.jboss.managed.plugins;
 
+import java.io.ObjectStreamException;
 import java.io.Serializable;
 import java.lang.reflect.UndeclaredThrowableException;
 
@@ -30,7 +31,8 @@
 import org.jboss.metatype.api.values.MetaValue;
 
 /**
- * An extension of
+ * An extension of ManagedPropertyImpl.
+ *
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */
@@ -42,10 +44,12 @@
    {
       super(name);
    }
+
    public WritethroughManagedPropertyImpl(Fields fields)
    {
       super(fields);
    }
+
    public WritethroughManagedPropertyImpl(ManagedObject managedObject, Fields fields)
    {
       super(managedObject, fields);
@@ -58,9 +62,9 @@
     * primative
     */
    @Override
-   public void setField(String name, Serializable value)
+   public void setValue(Serializable value)
    {
-      super.setField(name, value);
+      super.setValue(value);
       // Skip MetaValues
       if( (value instanceof MetaValue) )
          return;
@@ -81,5 +85,14 @@
       }
    }
 
-   
+   /**
+    * Expose only plain ManangedPropertyImpl.
+    *
+    * @return simpler ManagedPropertyImpl
+    * @throws ObjectStreamException for any error
+    */
+   private Object writeReplace() throws ObjectStreamException
+   {
+      return new ManagedPropertyImpl(getManagedObject(), getFields());
+   }
 }

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractComponentNameTransformer.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractComponentNameTransformer.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractComponentNameTransformer.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.managed.plugins.factory;
+
+import org.jboss.managed.spi.factory.RuntimeComponentNameTransformer;
+
+/**
+ * Abstract component name transformer.
+ *
+ * @param <T> exact value type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractComponentNameTransformer<T> implements RuntimeComponentNameTransformer
+{
+   private Class<T> type;
+
+   protected AbstractComponentNameTransformer(Class<T> type)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type.");
+      this.type = type;
+   }
+
+   public Object transform(Object value)
+   {
+      if (value == null)
+         return null;
+
+      if (type.isAssignableFrom(value.getClass()) == false)
+         return new IllegalArgumentException("Value is not instance of " + type + ", value: " + value);
+
+      return doTransform(type.cast(value));
+   }
+
+   /**
+    * Transform on exact type.
+    *
+    * @param value the value
+    * @return transformed name
+    */
+   protected abstract Object doTransform(T value);
+}

Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2007-10-06 00:30:24 UTC (rev 65896)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -25,6 +25,7 @@
 import java.lang.annotation.Annotation;
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.UndeclaredThrowableException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -35,6 +36,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.WeakHashMap;
+
 import org.jboss.beans.info.spi.BeanInfo;
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.config.plugins.property.PropertyConfiguration;
@@ -43,9 +45,9 @@
 import org.jboss.managed.api.Fields;
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedOperation.Impact;
 import org.jboss.managed.api.ManagedParameter;
 import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.ManagedOperation.Impact;
 import org.jboss.managed.api.annotation.AnnotationDefaults;
 import org.jboss.managed.api.annotation.ManagementComponent;
 import org.jboss.managed.api.annotation.ManagementConstants;
@@ -56,13 +58,13 @@
 import org.jboss.managed.api.annotation.ManagementParameter;
 import org.jboss.managed.api.annotation.ManagementProperties;
 import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
 import org.jboss.managed.api.factory.ManagedObjectFactory;
 import org.jboss.managed.plugins.DefaultFieldsImpl;
 import org.jboss.managed.plugins.ManagedObjectImpl;
 import org.jboss.managed.plugins.ManagedOperationImpl;
 import org.jboss.managed.plugins.ManagedParameterImpl;
-import org.jboss.managed.plugins.ManagedPropertyImpl;
-import org.jboss.managed.plugins.advice.WrapperAdvice;
+import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
 import org.jboss.managed.spi.factory.InstanceClassFactory;
 import org.jboss.managed.spi.factory.ManagedObjectBuilder;
 import org.jboss.managed.spi.factory.ManagedObjectPopulator;
@@ -70,6 +72,7 @@
 import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
 import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
 import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+import org.jboss.managed.spi.factory.RuntimeComponentNameTransformer;
 import org.jboss.metatype.api.types.ArrayMetaType;
 import org.jboss.metatype.api.types.GenericMetaType;
 import org.jboss.metatype.api.types.MetaType;
@@ -114,6 +117,9 @@
    /** The instance to class factories */
    private Map<Class, WeakReference<InstanceClassFactory>> instanceFactories = new WeakHashMap<Class, WeakReference<InstanceClassFactory>>();
 
+   /** The instance to name transformers */
+   private Map<Class<?>, WeakReference<RuntimeComponentNameTransformer>> transformers = new WeakHashMap<Class<?>, WeakReference<RuntimeComponentNameTransformer>>();
+
    static
    {
       configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
@@ -191,6 +197,17 @@
       }      
    }
 
+   public void setNameTransformers(Class<?> clazz, RuntimeComponentNameTransformer transformer)
+   {
+      synchronized (transformers)
+      {
+         if (transformer == null)
+            transformers.remove(clazz);
+         else
+            transformers.put(clazz, new WeakReference<RuntimeComponentNameTransformer>(transformer));
+      }
+   }
+
    /**
     * Default InstanceClassFactory implementation simply returns the
     * instance class. 
@@ -421,9 +438,6 @@
                   log.debug("Failed to populate constraints for: "+propertyInfo, e);
                }
 
-               // wrap fields
-               fields = WrapperAdvice.wrapFields(fields);
-
                ManagedProperty property = null;
                if (managementProperty != null)
                {
@@ -433,10 +447,11 @@
                   if (factory != ManagementProperty.NULL_PROPERTY_FACTORY.class)
                      property = getManagedProperty(factory, fields);
                }
+               // we should have write-through by default
+               // use factory to change this default behavior
                if (property == null)
-                  property = new ManagedPropertyImpl(fields);
-               // wrap property
-               properties.add(WrapperAdvice.wrapManagedProperty(property));
+                  property = new WritethroughManagedPropertyImpl(fields);
+               properties.add(property);
             }
             else if (trace)
                log.trace("Ignoring property: " + propertyInfo);
@@ -485,8 +500,6 @@
       
       ManagedObjectImpl managedObjectImpl = (ManagedObjectImpl) managedObject;
       Serializable object = createUnderlyingObject(managedObjectImpl, clazz);
-      // todo - missing this?
-      // managedObjectImpl.setAttachment(object);
       populateManagedObject(managedObject, object);
    }
    
@@ -541,6 +554,37 @@
       }
       BeanInfo beanInfo = configuration.getBeanInfo(moClass);
 
+      Set<PropertyInfo> propertyInfos = beanInfo.getProperties();
+      if (propertyInfos != null && propertyInfos.isEmpty() == false)
+      {
+         for(PropertyInfo propertyInfo : propertyInfos)
+         {
+            ManagementRuntimeRef componentRef = propertyInfo.getUnderlyingAnnotation(ManagementRuntimeRef.class);
+            if (componentRef != null)
+            {
+               try
+               {
+                  Class<? extends RuntimeComponentNameTransformer> tClass = componentRef.transformer();
+                  RuntimeComponentNameTransformer transformer;
+                  if (tClass != ManagementRuntimeRef.DEFAULT_NAME_TRANSFORMER.class)
+                     transformer = getComponentNameTransformer(tClass);
+                  else
+                     transformer = getComponentNameTransformer(propertyInfo.getType().getType());
+
+                  Object value = propertyInfo.get(object);
+                  Object componentName = (transformer != null) ? transformer.transform(value) : value;
+
+                  managedObject.setComponentName(componentName);
+                  break;
+               }
+               catch (Throwable t)
+               {
+                  throw new UndeclaredThrowableException(t);
+               }
+            }
+         }
+      }
+
       Map<String, ManagedProperty> properties = managedObject.getProperties();
       if (properties != null && properties.size() > 0)
       {
@@ -756,6 +800,33 @@
    }
 
    /**
+    * Get component name transformer.
+    *
+    * @param clazz the transformer class
+    * @return transformer instance
+    * @throws Exception for any error
+    */
+   protected RuntimeComponentNameTransformer getComponentNameTransformer(Class<?> clazz)
+         throws Exception
+   {
+      synchronized(transformers)
+      {
+         WeakReference<RuntimeComponentNameTransformer> weak = transformers.get(clazz);
+         if (weak != null)
+            return weak.get();
+
+         if (RuntimeComponentNameTransformer.class.isAssignableFrom(clazz))
+         {
+            RuntimeComponentNameTransformer transformer = (RuntimeComponentNameTransformer)clazz.newInstance();
+            transformers.put(clazz, new WeakReference<RuntimeComponentNameTransformer>(transformer));
+            return transformer;
+         }
+
+         return null;
+      }
+   }
+
+   /**
     * Get the populator for a class
     * 
     * @param clazz the class

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/ObjectNameTransformer.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/ObjectNameTransformer.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/factory/ObjectNameTransformer.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.managed.plugins.factory;
+
+import javax.management.ObjectName;
+
+/**
+ * Object name transformer.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ObjectNameTransformer extends AbstractComponentNameTransformer<ObjectName>
+{
+   public ObjectNameTransformer()
+   {
+      super(ObjectName.class);
+   }
+
+   protected Object doTransform(ObjectName value)
+   {
+      return value.getCanonicalName();
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/RuntimeComponentNameTransformer.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/RuntimeComponentNameTransformer.java	                        (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/spi/factory/RuntimeComponentNameTransformer.java	2007-10-06 18:48:59 UTC (rev 65897)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.managed.spi.factory;
+
+/**
+ * Runtime component name transformer. 
+ *
+ * @author ales.justin at jboss.org
+ */
+public interface RuntimeComponentNameTransformer
+{
+   /**
+    * Transform the name from string.
+    *
+    * @param value current name value
+    * @return transformed name
+    */
+   Object transform(Object value);
+}




More information about the jboss-cvs-commits mailing list