[jboss-cvs] JBossAS SVN: r59194 - in projects/microcontainer/trunk/managed: . src src/main/org/jboss/managed src/main/org/jboss/managed/api src/main/org/jboss/managed/plugins src/main/org/jboss/managed/plugins/advice src/resources src/resources/tests src/resources/tests/org src/resources/tests/org/jboss src/resources/tests/org/jboss/test src/resources/tests/org/jboss/test/managed src/tests/org/jboss/test src/tests/org/jboss/test/managed src/tests/org/jboss/test/managed/mock

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 21 09:09:56 EST 2006


Author: adrian at jboss.org
Date: 2006-12-21 09:09:44 -0500 (Thu, 21 Dec 2006)
New Revision: 59194

Added:
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperSet.java
   projects/microcontainer/trunk/managed/src/resources/
   projects/microcontainer/trunk/managed/src/resources/tests/
   projects/microcontainer/trunk/managed/src/resources/tests/org/
   projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/
   projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/
   projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/
   projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedAdvices-aop.xml
   projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedObjectWrapper-aop.xml
   projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedPropertyWrapper-aop.xml
   projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedTest-aop.xml
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedAllTestSuite.java
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTest.java
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTestDelegate.java
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockDOMFields.java
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockDataSourceManagedObject.java
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockTest.java
Removed:
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/
Modified:
   projects/microcontainer/trunk/managed/.classpath
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java
Log:
Update the managed api to implement the AOP structure.
Need to implement the advices for interaction with the profile service and server.

Modified: projects/microcontainer/trunk/managed/.classpath
===================================================================
--- projects/microcontainer/trunk/managed/.classpath	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/.classpath	2006-12-21 14:09:44 UTC (rev 59194)
@@ -2,13 +2,19 @@
 <classpath>
 	<classpathentry kind="src" path="src/main"/>
 	<classpathentry kind="src" path="src/tests"/>
+	<classpathentry kind="lib" path="src/resources/tests"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/common-core/lib/jboss-common-core.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/common-logging-spi/lib/jboss-logging-spi.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/common-logging-log4j/lib/jboss-logging-log4j.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/aop/lib/jboss-aop-jdk50.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/oswego-concurrent/lib/concurrent.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/javassist/lib/javassist.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/trove/lib/trove.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/junit/lib/junit.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/test/lib/jboss-test.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/metatype"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/container"/>
 	<classpathentry kind="output" path="output/eclipse-classes"/>
 </classpath>

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	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -22,8 +22,6 @@
 package org.jboss.managed.api;
 
 import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.Set;
 
 /**
@@ -32,40 +30,14 @@
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
-public class ManagedObject implements Serializable
+public interface ManagedObject extends Serializable
 {
-   /** The serialVersionUID */
-   private static final long serialVersionUID = -2588364350006686542L;
-
-   /** The properties */
-   private Set<ManagedProperty> properties;
-   
    /**
-    * Create a new ManagedObject
-    * 
-    * @param properties the properties 
-    */
-   public ManagedObject(Set<ManagedProperty> properties)
-   {
-      if (properties == null)
-         properties = Collections.emptySet();
-      this.properties = properties;
-   }
-   
-   // TODO identity, deployment info, scope, etc.
-   
-   /**
     * Get the property names
     * 
     * @return the property names
     */
-   public Set<String> getPropertyNames()
-   {
-      Set<String> result = new HashSet<String>(properties.size());
-      for (ManagedProperty property : properties)
-         result.add(property.getName());
-      return result;
-   }
+   Set<String> getPropertyNames();
    
    /**
     * Get a property
@@ -73,42 +45,12 @@
     * @param name the name
     * @return the property
     */
-   public ManagedProperty getProperty(String name)
-   {
-      if (name == null)
-         throw new IllegalArgumentException("Null name");
-
-      for (ManagedProperty property : properties)
-      {
-         if (name.equals(property.getName()))
-            return property;
-      }
-      return null;
-   }
+   ManagedProperty getProperty(String name);
    
    /**
     * Get the properties
     * 
     * @return the properties
     */
-   public Set<ManagedProperty> getProperties()
-   {
-      return Collections.unmodifiableSet(properties);
-   }
-
-   /**
-    * Get the real properties
-    * 
-    * @return the properties
-    */
-   protected Set<ManagedProperty> getManagedProperties()
-   {
-      return properties;
-   }
-   
-   // TODO state, lifecycle, on-demand, etc.
-   
-   // TODO statistics
-   
-   // TODO listener api
+   Set<ManagedProperty> getProperties();
 }

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	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -21,15 +21,11 @@
 */
 package org.jboss.managed.api;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectStreamField;
 import java.io.Serializable;
 import java.util.Set;
 
 import org.jboss.metatype.api.types.MetaType;
 import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
 
 /**
  * ManagedProperty.
@@ -37,183 +33,95 @@
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
-public class ManagedProperty implements Serializable
+public interface ManagedProperty extends Serializable
 {
-   /** The serialVersionUID */
-   private static final long serialVersionUID = 2268454772998030799L;
-   
-   /** The serialized form */
-   private static final ObjectStreamField[] serialPersistentFields =
-      new ObjectStreamField[]
-      {
-         new ObjectStreamField("fields", Fields.class),
-      };
-
-   /** The fields */
-   private Fields fields;
-
-   /** The property name */
-   private transient String name;
-   
    /**
-    * Create a new ManagedProperty.
+    * Get the managed object
     * 
-    * @param fields the fields
-    * @throws IllegalArgumentException for null fields
+    * @return the managed object
     */
-   public ManagedProperty(Fields fields)
-   {
-      if (fields == null)
-         throw new IllegalArgumentException("Null fields");
-      this.fields = fields;
-      
-      name = getField(Fields.NAME, String.class);
-      if (name == null)
-         throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
-   }
+   ManagedObject getManagedObject();
    
    /**
     * Get the fields
     * 
     * @return the fields
     */
-   public Fields getFields()
-   {
-      return fields;
-   }
+   Fields getFields();
    
    /**
     * Get a field
     *
-    * TODO general reconstruction code for metatypes
     * @param <T> the expected type
     * @param fieldName the field name
     * @param expected the expected type
     * @return the value
     */
-   @SuppressWarnings("unchecked")
-   public <T> T getField(String fieldName, Class<T> expected)
-   {
-      if (fieldName == null)
-         throw new IllegalArgumentException("Null field name");
-      if (expected == null)
-         throw new IllegalArgumentException("Null expected type");
-      
-      Serializable field = getFields().getField(fieldName);
-      
-      if (field == null)
-         return null;
-
-      if (expected.isInstance(field))
-         return expected.cast(field);
-      
-      if (field instanceof SimpleValue)
-      {
-         SimpleValue value = (SimpleValue) field;
-         Object result = value.getValue();
-         if (result == null)
-            return null;
-         return expected.cast(result);
-      }
-      
-      throw new IllegalStateException("Field " + fieldName + " with value " + field + " is  a of the expected type: " + expected.getName());
-   }
+   <T> T getField(String fieldName, Class<T> expected);
    
    /**
     * Set a field
     *
-    * TODO metaType stuff
     * @param fieldName the field name
     * @param value the value
     */
-   public void setField(String fieldName, Serializable value)
-   {
-      if (fieldName == null)
-         throw new IllegalArgumentException("Null field name");
-      
-      getFields().setField(fieldName, value);
-   }
+   void setField(String fieldName, Serializable value);
    
    /**
     * Get the property's name
     * 
     * @return the property's name
     */
-   public String getName()
-   {
-      return name;
-   }
+   String getName();
 
    /**
     * Get the description
     * 
     * @return the description
     */
-   public String getDescription()
-   {
-      return getField(Fields.DESCRIPTION, String.class);
-   }
+   String getDescription();
 
    /**
     * Get the type
     * 
     * @return the type
     */
-   public MetaType getMetaType()
-   {
-      return getField(Fields.META_TYPE, MetaType.class);
-   }
+   MetaType getMetaType();
 
    /**
     * Get the value
     * 
     * @return the value
     */
-   public Object getValue()
-   {
-      return getField(Fields.VALUE, Object.class);
-   }
+   Object getValue();
 
    /**
     * Set the value
     * 
     * @param value the value
     */
-   public void setValue(Serializable value)
-   {
-      setField(Fields.VALUE, value);
-   }
+   void setValue(Serializable value);
 
    /**
     * Get the legal values
     * 
     * @return the legal values
     */
-   @SuppressWarnings("unchecked")
-   public Set<MetaValue> getLegalValues()
-   {
-      return getField(Fields.LEGAL_VALUES, Set.class);
-   }
+   Set<MetaValue> getLegalValues();
 
    /**
     * Get the minimum value
     * 
     * @return the minimum value
     */
-   public MetaValue getMinimumValue()
-   {
-      return getField(Fields.MINIMUM_VALUE, MetaValue.class);
-   }
+   Comparable getMinimumValue();
 
    /**
     * Get the miximum value
     * 
     * @return the maximum value
     */
-   public MetaValue getMaximumValue()
-   {
-      return getField(Fields.MAXIMUM_VALUE, MetaValue.class);
-   }
+   Comparable getMaximumValue();
 
    /**
     * Check whether this is a valid value
@@ -221,77 +129,12 @@
     * @param value the value
     * @return null for a valid value, an error message otherwise
     */
-   public String checkValidValue(Serializable value)
-   {
-      // TODO check min/max/etc.
-      return null;
-   }
+   String checkValidValue(Serializable value);
    
    /**
     * Whether the property is mandatory
     * 
     * @return true when mandatory
     */
-   public boolean isMandatory()
-   {
-      Boolean result = getField(Fields.MANDATORY, Boolean.class);
-      if (result == null)
-         return false;
-      return result.booleanValue();
-   }
-
-   @Override
-   public String toString()
-   {
-      return "ManagedProperty{" + name + "}"; 
-   }
-
-   @Override
-   public int hashCode()
-   {
-      return name.hashCode(); 
-   }
-
-   @Override
-   public boolean equals(Object obj)
-   {
-      if (obj == this)
-         return true;
-      if (obj == null || obj instanceof ManagedProperty == false)
-         return false;
-      
-      ManagedProperty other = (ManagedProperty) obj;
-      return name.equals(other.getName());
-   }
-   
-   /**
-    * Create a new ManagedProperty.
-    * 
-    * @param fields the fields
-    * @throws IllegalArgumentException for null fields
-    */
-   private void init(Fields fields)
-   {
-      if (fields == null)
-         throw new IllegalArgumentException("Null fields");
-      this.fields = fields;
-      
-      name = getField(Fields.NAME, String.class);
-      if (name == null)
-         throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
-   }
-
-   private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
-   {
-      ObjectInputStream.GetField getField = in.readFields();
-      Fields fields = (Fields) getField.get("fields", null);
-      try
-      {
-         init(fields);
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException("Error deserializing managed property", e);
-      }
-   }
+   boolean isMandatory();
 }

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedObjectImpl.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,82 @@
+/*
+* 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.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * ManagedObjectImpl.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ManagedObjectImpl implements ManagedObject
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -2588364350006686542L;
+
+   /** The properties */
+   private Set<ManagedProperty> properties;
+   
+   /**
+    * Create a new ManagedObjectImpl
+    * 
+    * @param properties the properties 
+    */
+   public ManagedObjectImpl(Set<ManagedProperty> properties)
+   {
+      if (properties == null)
+         properties = Collections.emptySet();
+      this.properties = properties;
+   }
+   
+   public Set<String> getPropertyNames()
+   {
+      Set<String> result = new HashSet<String>(properties.size());
+      for (ManagedProperty property : properties)
+         result.add(property.getName());
+      return result;
+   }
+   
+   public ManagedProperty getProperty(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+      
+      for (ManagedProperty property : properties)
+      {
+         if (name.equals(property.getName()))
+            return property;
+      }
+      return null;
+   }
+   
+   public Set<ManagedProperty> getProperties()
+   {
+      return properties;
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,247 @@
+/*
+* 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.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.util.Set;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * ManagedProperty.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ManagedPropertyImpl implements ManagedProperty
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 2268454772998030799L;
+   
+   /** The serialized form */
+   private static final ObjectStreamField[] serialPersistentFields =
+      new ObjectStreamField[]
+      {
+         new ObjectStreamField("managedObject", ManagedObjectImpl.class),
+         new ObjectStreamField("fields", Fields.class),
+      };
+
+   /** The managed object */
+   private ManagedObjectImpl managedObject;
+   
+   /** The fields */
+   private Fields fields;
+
+   /** The property name */
+   private transient String name;
+   
+   /**
+    * Create a new ManagedProperty.
+    * 
+    * @param managedObject the managed object
+    * @param fields the fields
+    * @throws IllegalArgumentException for null fields
+    */
+   public ManagedPropertyImpl(ManagedObjectImpl managedObject, Fields fields)
+   {
+      init(managedObject, fields);
+   }
+   
+   public ManagedObject getManagedObject()
+   {
+      return managedObject;
+   }
+
+   public Fields getFields()
+   {
+      return fields;
+   }
+   
+   // TODO general reconstruction code for metatypes
+   @SuppressWarnings("unchecked")
+   public <T> T getField(String fieldName, Class<T> expected)
+   {
+      if (fieldName == null)
+         throw new IllegalArgumentException("Null field name");
+      if (expected == null)
+         throw new IllegalArgumentException("Null expected type");
+      
+      Serializable field = getFields().getField(fieldName);
+      
+      if (field == null)
+         return null;
+
+      if (expected.isInstance(field))
+         return expected.cast(field);
+      
+      if (field instanceof SimpleValue)
+      {
+         SimpleValue value = (SimpleValue) field;
+         Object result = value.getValue();
+         if (result == null)
+            return null;
+         return expected.cast(result);
+      }
+      
+      throw new IllegalStateException("Field " + fieldName + " with value " + field + " is  a of the expected type: " + expected.getName());
+   }
+   
+   // TODO metaType stuff
+   public void setField(String fieldName, Serializable value)
+   {
+      if (fieldName == null)
+         throw new IllegalArgumentException("Null field name");
+      
+      getFields().setField(fieldName, value);
+   }
+   
+   public String getName()
+   {
+      return name;
+   }
+
+   public String getDescription()
+   {
+      return getField(Fields.DESCRIPTION, String.class);
+   }
+
+   public MetaType getMetaType()
+   {
+      return getField(Fields.META_TYPE, MetaType.class);
+   }
+
+   public Object getValue()
+   {
+      return getField(Fields.VALUE, Object.class);
+   }
+
+   public void setValue(Serializable value)
+   {
+      setField(Fields.VALUE, value);
+   }
+
+   @SuppressWarnings("unchecked")
+   public Set<MetaValue> getLegalValues()
+   {
+      return getField(Fields.LEGAL_VALUES, Set.class);
+   }
+
+   public Comparable getMinimumValue()
+   {
+      return getField(Fields.MINIMUM_VALUE, Comparable.class);
+   }
+
+   public Comparable getMaximumValue()
+   {
+      return getField(Fields.MAXIMUM_VALUE, Comparable.class);
+   }
+
+   public String checkValidValue(Serializable value)
+   {
+      // TODO check min/max/etc.
+      return null;
+   }
+   
+   public boolean isMandatory()
+   {
+      Boolean result = getField(Fields.MANDATORY, Boolean.class);
+      if (result == null)
+         return false;
+      return result.booleanValue();
+   }
+
+   @Override
+   public String toString()
+   {
+      return "ManagedProperty{" + name + "}"; 
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return name.hashCode(); 
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof ManagedProperty == false)
+         return false;
+      
+      ManagedProperty other = (ManagedProperty) obj;
+      return getName().equals(other.getName()) && getManagedObject().equals(other.getManagedObject()) ;
+   }
+   
+   /**
+    * Initialise a ManagedPropertyImpl.
+    * 
+    * @param managedObject the managed object
+    * @param fields the fields
+    * @throws IllegalArgumentException for null fields
+    */
+   private void init(ManagedObjectImpl managedObject, Fields fields)
+   {
+      if (managedObject == null)
+         throw new IllegalArgumentException("Null managed object");
+      if (fields == null)
+         throw new IllegalArgumentException("Null fields");
+      
+      this.managedObject = managedObject;
+      this.fields = fields;
+      
+      name = getField(Fields.NAME, String.class);
+      if (name == null)
+         throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
+   }
+
+   /**
+    * Read from a stream
+    * 
+    * @param in the stream
+    * @throws IOException for IO problem
+    * @throws ClassNotFoundException for a classloading problem
+    */
+   private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+   {
+      ObjectInputStream.GetField getField = in.readFields();
+      ManagedObjectImpl managedObject = (ManagedObjectImpl) getField.get("managedObject", null);
+      Fields fields = (Fields) getField.get("fields", null);
+      try
+      {
+         init(managedObject, fields);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error deserializing managed property", e);
+      }
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,92 @@
+/*
+* 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.advice;
+
+import java.util.Arrays;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.logging.Logger;
+
+/**
+ * TraceAdvice.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TraceAdvice
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(TraceAdvice.class);
+   
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      boolean trace = log.isTraceEnabled();
+      if (trace)
+         logMethod(false, invocation, null, null);
+      
+      Throwable e = null;
+      Object result = null;
+      try
+      {
+         result = invocation.invokeNext();
+         return result;
+      }
+      catch (Throwable t)
+      {
+         e = t;
+         throw t;
+      }
+      finally
+      {
+         logMethod(true, invocation, result, e);
+      }
+   }
+   
+   private void logMethod(boolean beforeAfter, Invocation invocation, Object result, Throwable t)
+   {
+      MethodInvocation mi = (MethodInvocation) invocation;
+      StringBuilder builder = new StringBuilder();
+      Object target = mi.getTargetObject();
+      builder.append(target.getClass().getSimpleName());
+      builder.append('@');
+      builder.append(System.identityHashCode(target));
+      if (beforeAfter == false)
+         builder.append(" before ");
+      else
+         builder.append(" after  ");
+      builder.append(mi.getActualMethod().getName());
+      if (beforeAfter == false)
+      {
+         builder.append(" params=");
+         builder.append(Arrays.asList(mi.getArguments()));
+      }
+      else if (t == null)
+      {
+         builder.append(" result=");
+         builder.append(result);
+      }
+      if (t != null)
+         builder.append(" ended in error:");
+      log.trace(builder.toString(), t);
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,149 @@
+/*
+* 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.advice;
+
+import java.util.Set;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.proxy.container.AOPProxyFactoryParameters;
+import org.jboss.aop.proxy.container.GeneratedAOPProxyFactory;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * WrapperAdvice, intercepts methods that produce objects
+ * that require proxies.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class WrapperAdvice
+{
+   /**
+    * Wrap a managed object
+    * 
+    * @param managedObject the managed object
+    * @return the managed object wrapper
+    */
+   public static ManagedObject wrapManagedObject(ManagedObject managedObject)
+   {
+      return createProxy(managedObject, ManagedObject.class);
+   }
+   
+   /**
+    * Wrap a managed property
+    * 
+    * @param managedProperty the managed property
+    * @return the managed property wrapper
+    */
+   public static ManagedProperty wrapManagedProperty(ManagedProperty managedProperty)
+   {
+      return createProxy(managedProperty, ManagedProperty.class);
+   }
+   
+   /**
+    * Wrap fields
+    * 
+    * @param fields the fields
+    * @return the fields wrapper
+    */
+   public static Fields wrapFields(Fields fields)
+   {
+      return createProxy(fields, Fields.class);
+   }
+
+   /**
+    * Wrap a returned managed object
+    * 
+    * @param invocation the invocation
+    * @return the wrapped managed object
+    * @throws Throwable for any error
+    */
+   public ManagedObject wrapManagedObject(Invocation invocation) throws Throwable
+   {
+      ManagedObject result = (ManagedObject) invocation.invokeNext();
+      return wrapManagedObject(result);
+   }
+
+   /**
+    * Wrap a returned managed property
+    * 
+    * @param invocation the invocation
+    * @return the wrapped managed property
+    * @throws Throwable for any error
+    */
+   public ManagedProperty wrapManagedProperty(Invocation invocation) throws Throwable
+   {
+      ManagedProperty result = (ManagedProperty) invocation.invokeNext();
+      return wrapManagedProperty(result);
+   }
+
+   /**
+    * Wrap a returned managed property set
+    * 
+    * @param invocation the invocation
+    * @return the wrapped managed property set
+    * @throws Throwable for any error
+    */
+   @SuppressWarnings("unchecked")
+   public Set<ManagedProperty> wrapManagedPropertySet(Invocation invocation) throws Throwable
+   {
+      Set<ManagedProperty> result = (Set<ManagedProperty>) invocation.invokeNext();
+      return new WrapperSet<ManagedProperty>(result, ManagedProperty.class);
+   }
+
+   /**
+    * Wrap fields
+    * 
+    * @param invocation the invocation
+    * @return the wrapped managed property
+    * @throws Throwable for any error
+    */
+   public Fields wrapFields(Invocation invocation) throws Throwable
+   {
+      Fields result = (Fields) invocation.invokeNext();
+      return wrapFields(result);
+   }
+   
+   /**
+    * Create a proxy 
+    * 
+    * @param <T> the expected type
+    * @param target the target
+    * @param interfaceClass the interface class
+    * @return the proxy
+    */
+   static <T> T createProxy(T target, Class<T> interfaceClass)
+   {
+      if (target == null)
+         return null;
+      
+      GeneratedAOPProxyFactory proxyFactory = new GeneratedAOPProxyFactory();
+      AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+      params.setInterfaces(new Class[] { interfaceClass });
+      params.setObjectAsSuperClass(true);
+      params.setTarget(target);
+      Object proxy = proxyFactory.createAdvisedProxy(params);
+      return interfaceClass.cast(proxy);
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,73 @@
+/*
+* 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.advice;
+
+import java.util.Iterator;
+
+/**
+ * WrapperIterator.
+ * 
+ * @param <T> the interface
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class WrapperIterator<T> implements Iterator<T>
+{
+   /** The delegate */
+   private Iterator<T> delegate;
+
+   /** The interface class */
+   private Class<T> interfaceClass;
+   
+   /**
+    * Create a new WrapperIterator.
+    * 
+    * @param delegate the delegate
+    * @param interfaceClass the interface class
+    */
+   public WrapperIterator(Iterator<T> delegate, Class<T> interfaceClass)
+   {
+      if (delegate == null)
+         throw new IllegalArgumentException("Null delegate");
+      if (interfaceClass == null)
+         throw new IllegalArgumentException("Null interface class");
+      
+      this.delegate = delegate;
+      this.interfaceClass = interfaceClass;
+   }
+
+   public boolean hasNext()
+   {
+      return delegate.hasNext();
+   }
+
+   public T next()
+   {
+      T next = delegate.next();
+      return WrapperAdvice.createProxy(next, interfaceClass);
+   }
+
+   public void remove()
+   {
+      throw new UnsupportedOperationException();
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperSet.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperSet.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/advice/WrapperSet.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,73 @@
+/*
+* 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.advice;
+
+import java.io.Serializable;
+import java.util.AbstractSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * WrapperSet.
+ * 
+ * @param <T> the interface type
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class WrapperSet<T> extends AbstractSet<T> implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -5588975054846538928L;
+
+   /** The delegate */
+   private Set<T> delegate;
+
+   /** The interface class */
+   private Class<T> interfaceClass;
+   
+   /**
+    * Create a new WrapperSet.
+    * 
+    * @param delegate the delegate
+    * @param interfaceClass the interface class
+    */
+   public WrapperSet(Set<T> delegate, Class<T> interfaceClass)
+   {
+      if (delegate == null)
+         throw new IllegalArgumentException("Null delegate");
+      if (interfaceClass == null)
+         throw new IllegalArgumentException("Null interface class");
+
+      this.delegate = delegate;
+      this.interfaceClass = interfaceClass;
+   }
+
+   public Iterator<T> iterator()
+   {
+      return new WrapperIterator<T>(delegate.iterator(), interfaceClass);
+   }
+
+   public int size()
+   {
+      return delegate.size();
+   }
+}

Added: projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedAdvices-aop.xml
===================================================================
--- projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedAdvices-aop.xml	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedAdvices-aop.xml	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+   <!-- A trace advice for debugging -->
+   <aspect name="trace" class="org.jboss.managed.plugins.advice.TraceAdvice"/>
+
+   <!-- A wrapping advice -->
+   <aspect name="wrap" class="org.jboss.managed.plugins.advice.WrapperAdvice"/>

Added: projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedObjectWrapper-aop.xml
===================================================================
--- projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedObjectWrapper-aop.xml	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedObjectWrapper-aop.xml	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+   <!-- Wrapper methods for managed object -->
+   <bind pointcut="execution(* $instanceof{org.jboss.managed.api.ManagedObject}->getProperty(..))">
+      <advice name="wrapManagedProperty" aspect="wrap"/>
+   </bind>
+   <bind pointcut="execution(* $instanceof{org.jboss.managed.api.ManagedObject}->getProperties(..))">
+      <advice name="wrapManagedPropertySet" aspect="wrap"/>
+   </bind>

Added: projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedPropertyWrapper-aop.xml
===================================================================
--- projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedPropertyWrapper-aop.xml	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedPropertyWrapper-aop.xml	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+   <!-- Wrapper methods for managed property -->
+   <bind pointcut="execution(* $instanceof{org.jboss.managed.api.ManagedProperty}->getManagedObject(..))">
+      <advice name="wrapManagedObject" aspect="wrap"/>
+   </bind>
+
+   <!-- Wrapper methods for managed property -->
+   <bind pointcut="execution(* $instanceof{org.jboss.managed.api.ManagedProperty}->getFields(..))">
+      <advice name="wrapFields" aspect="wrap"/>
+   </bind>

Added: projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedTest-aop.xml
===================================================================
--- projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedTest-aop.xml	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/resources/tests/org/jboss/test/managed/ManagedTest-aop.xml	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE aop SYSTEM "jboss-aop_1_0.dtd" [
+   <!ENTITY ManagedAdvices SYSTEM "resource:org/jboss/test/managed/ManagedAdvices-aop.xml">
+   <!ENTITY ManagedObjectWrapper SYSTEM "resource:org/jboss/test/managed/ManagedObjectWrapper-aop.xml">
+   <!ENTITY ManagedPropertyWrapper SYSTEM "resource:org/jboss/test/managed/ManagedPropertyWrapper-aop.xml">
+]>
+
+<aop>
+
+   <!-- This is the default AOP setup when the test doesn't having anything specific -->
+
+   <!-- ==== Advices ==== -->
+
+   &ManagedAdvices;
+
+   <!-- ==== Managed Object ==== -->
+
+   <!-- The managed object advice stack -->
+   <bind pointcut="execution(* $instanceof{org.jboss.managed.api.ManagedObject}->$implements{org.jboss.managed.api.ManagedObject}(..))">
+      <advice name="invoke" aspect="trace"/>
+   </bind>
+
+   <!-- Wrapper methods for managed object -->
+   &ManagedObjectWrapper;
+
+   <!-- ==== Managed Property ==== -->
+
+   <!-- The managed property advice stack -->
+   <bind pointcut="execution(* $instanceof{org.jboss.managed.api.ManagedProperty}->$implements{org.jboss.managed.api.ManagedProperty}(..))">
+      <advice name="invoke" aspect="trace"/>
+   </bind>
+
+   <!-- Wrapper methods for managed object -->
+   &ManagedPropertyWrapper;
+
+   <!-- ==== Fields ==== -->
+
+   <!-- The fields advice stack -->
+   <bind pointcut="execution(* $instanceof{org.jboss.managed.api.Fields}->$implements{org.jboss.managed.api.Fields}(..))">
+      <advice name="invoke" aspect="trace"/>
+   </bind>
+
+</aop>

Added: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedAllTestSuite.java
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedAllTestSuite.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedAllTestSuite.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.managed;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Managed All Test Suite.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class ManagedAllTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Managed All Tests");
+
+      //suite.addTest(TypesTestSuite.suite());
+
+      return suite;
+   }
+}

Added: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTest.java
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTest.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTest.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,62 @@
+/*
+* 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.test.managed;
+
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * ManagedTest.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ManagedTest extends AbstractTestCaseWithSetup
+{
+   /**
+    * Get the test delegate
+    * 
+    * @param clazz the test class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+   {
+      return new ManagedTestDelegate(clazz);
+   }
+   
+   /**
+    * Create a new Managed test
+    * 
+    * @param name the test name
+    */
+   public ManagedTest(String name)
+   {
+      super(name);
+   }
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      configureLogging();
+   }
+}

Added: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTestDelegate.java
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTestDelegate.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/ManagedTestDelegate.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,138 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.managed;
+
+import java.net.URL;
+
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.net.protocol.URLStreamHandlerFactory;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * 
+ * ManagedTestDelegate.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 58245 $
+ */
+public class ManagedTestDelegate extends AbstractTestDelegate
+{
+   /** The AOP URL used */
+   private URL aopURL;
+   
+   /**
+    * Create a new ManagedTestDelegate.
+    * 
+    * @param clazz the class
+    * @throws Exception for any error
+    */
+   public ManagedTestDelegate(Class clazz) throws Exception
+   {
+      super(clazz);
+   }
+
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      if (deployAOP(clazz) == false)
+         deployAOP(ManagedTest.class);
+   }
+
+   public void tearDown() throws Exception
+   {
+      super.tearDown();
+      undeployAOP();
+   }
+
+   protected boolean deployAOP(Class referenceClass) throws Exception
+   {
+      String testName = referenceClass.getName();
+      testName = testName.replace('.', '/') + "-aop.xml";
+      URL url = clazz.getClassLoader().getResource(testName);
+      if (url != null)
+      {
+         log.debug("Deploying " + url);
+         aopURL = url;
+         try
+         {
+            initURLHandlers();
+            AspectXmlLoader.deployXML(aopURL);
+         }
+         catch (Throwable t)
+         {
+            throw new RuntimeException("Error deploying: " + url, t);
+         }
+         return true;
+      }
+      else
+      {
+         log.debug("No test specific deployment " + testName);
+         return false;
+      }
+   }
+
+   protected void undeployAOP()
+   {
+      if (aopURL == null)
+         return;
+      try
+      {
+         log.debug("Undeploying " + aopURL);
+         AspectXmlLoader.undeployXML(aopURL);
+      }
+      catch (Exception e)
+      {
+         log.warn("Ignored error undeploying " + aopURL, e);
+      }
+   }
+
+   private void initURLHandlers()
+   {
+      try
+      {
+         // Install a URLStreamHandlerFactory that uses the TCL
+         URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());
+   
+         // Preload JBoss URL handlers
+         URLStreamHandlerFactory.preload();
+      }
+      catch (Error error)
+      { //very naughty but we HAVE to do this or
+         //we'll fail if we ever try to do this again
+         log.warn("Caught Throwable Error, this probably means " +
+            "we've already set the URLStreamHAndlerFactory before"); 
+         //Sys.out because we don't have logging yet
+      }
+
+      // Include the default JBoss protocol handler package
+      String handlerPkgs = System.getProperty("java.protocol.handler.pkgs");
+      if (handlerPkgs != null)
+      {
+         handlerPkgs += "|org.jboss.net.protocol";
+      }
+      else
+      {
+         handlerPkgs = "org.jboss.net.protocol";
+      }
+      System.setProperty("java.protocol.handler.pkgs", handlerPkgs);
+   }
+}

Copied: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockDOMFields.java (from rev 59145, projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDOMFields.java)
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDOMFields.java	2006-12-19 14:12:21 UTC (rev 59145)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockDOMFields.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,105 @@
+/*
+* 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.test.managed.mock;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.Fields;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * DOMFields.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockDOMFields implements Fields
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   /** The datasource element */
+   private Element element; 
+   
+   /** The element name */
+   private String elementName;
+   
+   /**
+    * Create a new DOMFields.
+    *
+    * @param element the data source element
+    * @param elementName the element name
+    */
+   public MockDOMFields(Element element, String elementName)
+   {
+      this.element = element;
+      this.elementName = elementName;
+   }
+   
+   public Serializable getField(String name)
+   {
+      if (NAME.equals(name))
+         return elementName;
+      if (VALUE.equals(name))
+      {
+         NodeList nodes = element.getElementsByTagName(elementName);
+         if (nodes.getLength() == 0)
+            return null;
+         else
+         {
+            Element element = (Element) nodes.item(0);
+            return element.getTextContent();
+         }
+      }
+      return null;
+   }
+
+   public void setField(String name, Serializable value)
+   {
+      if (VALUE.equals(name))
+      {
+         String string = (String) value;
+         NodeList nodes = element.getElementsByTagName(elementName);
+         Element childElement = null;
+         if (nodes.getLength() == 0)
+         {
+            if (string == null || string.length() == 0)
+               return;
+            childElement = element.getOwnerDocument().createElement(elementName);
+            element.appendChild(childElement);
+         }
+         else
+         {
+            childElement = (Element) nodes.item(0);
+            if (string == null || string.length() == 0)
+            {
+               element.removeChild(childElement);
+               return;
+            }
+         }
+         childElement.setTextContent(string);
+         return;
+      }
+      throw new UnsupportedOperationException("setField " + name);
+   }
+}

Copied: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockDataSourceManagedObject.java (from rev 59145, projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDataSourceManagedObject.java)
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDataSourceManagedObject.java	2006-12-19 14:12:21 UTC (rev 59145)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockDataSourceManagedObject.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,89 @@
+/*
+* 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.test.managed.mock;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.util.xml.DOMWriter;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * MockDataSourceManagedObject.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockDataSourceManagedObject extends ManagedObjectImpl
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   /** The document */
+   private Document document;
+   
+   /**
+    * Create a new MockDataSourceManagedObject.
+    */
+   public MockDataSourceManagedObject()
+   {
+      super(new HashSet<ManagedProperty>());
+      Element element;
+      try
+      {
+         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+         DocumentBuilder builder = factory.newDocumentBuilder();
+         DOMImplementation impl = builder.getDOMImplementation();
+         document = impl.createDocument(null, null, null);
+         
+         element = document.createElement("data-source");
+         document.appendChild(element);
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error creating dom", e);
+      }
+      
+      Set<ManagedProperty> properties = getProperties();
+      properties.add(new ManagedPropertyImpl(this, new MockDOMFields(element, "jndi-name")));
+      properties.add(new ManagedPropertyImpl(this, new MockDOMFields(element, "connection-url")));
+      properties.add(new ManagedPropertyImpl(this, new MockDOMFields(element, "user")));
+      properties.add(new ManagedPropertyImpl(this, new MockDOMFields(element, "password")));
+   }
+   
+   public String prettyPrint()
+   {
+      return DOMWriter.printNode(document, true);
+   }
+}

Added: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockTest.java
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockTest.java	2006-12-21 14:08:20 UTC (rev 59193)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/managed/mock/MockTest.java	2006-12-21 14:09:44 UTC (rev 59194)
@@ -0,0 +1,96 @@
+/*
+* 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.test.managed.mock;
+
+import junit.framework.Test;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.advice.WrapperAdvice;
+import org.jboss.test.managed.ManagedTest;
+
+/**
+ * MockTest
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockTest extends ManagedTest
+{
+   public static Test suite()
+   {
+      return suite(MockTest.class);
+   }
+   
+   public MockTest(String name)
+   {
+      super(name);
+   }
+
+   public void testMock() throws Exception
+   {
+      MockDataSourceManagedObject mock = new MockDataSourceManagedObject();
+
+      ManagedObject mo = WrapperAdvice.wrapManagedObject(mock);
+      
+      getLog().debug("MockDataSourceManagedObject, available propertes...");
+      getLog().debug(mock.getPropertyNames());
+
+      getLog().debug("Initial MetaData...");
+      getLog().debug(mock.prettyPrint());
+      
+      getLog().debug("Adding jndi-name...");
+      mo.getProperty("jndi-name").setValue("DefaultDS");
+      getLog().debug(mock.prettyPrint());
+
+      getLog().debug("Adding user and password...");
+      mo.getProperty("user").setValue("Scott");
+      mo.getProperty("password").setValue("Tiger");
+      getLog().debug(mock.prettyPrint());
+
+      getLog().debug("Changing jndi-name...");
+      mo.getProperty("jndi-name").setValue("ChangedDS");
+      getLog().debug(mock.prettyPrint());
+
+      getLog().debug("Removing jndi-name...");
+      mo.getProperty("jndi-name").setValue(null);
+      getLog().debug(mock.prettyPrint());
+      
+      getLog().debug("Displaying properties...");
+      for (ManagedProperty property : mo.getProperties())
+         getLog().debug(property.getName() + "=" + property.getValue());
+      
+      ManagedProperty jndiName = mo.getProperty("jndi-name");
+      
+      getLog().debug("Displaying jndi-name field values...");
+      getLog().debug("jndi-name name  field is: " + jndiName.getFields().getField(Fields.NAME));
+      getLog().debug("jndi-name value field is: " + jndiName.getFields().getField(Fields.VALUE));
+      
+      assertEquals(mo, jndiName.getManagedObject());
+   }
+
+   protected void configureLogging()
+   {
+      //enableTrace("org.jboss.managed.plugins.advice");
+   }
+}




More information about the jboss-cvs-commits mailing list