[jboss-cvs] JBossAS SVN: r70431 - in trunk/profileservice/src/main/org/jboss/managed/plugins: advice and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 5 10:30:23 EST 2008


Author: adrian at jboss.org
Date: 2008-03-05 10:30:22 -0500 (Wed, 05 Mar 2008)
New Revision: 70431

Added:
   trunk/profileservice/src/main/org/jboss/managed/plugins/advice/
   trunk/profileservice/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java
   trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java
   trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java
   trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperSet.java
Log:
Move the managed advices to the profile service project

Added: trunk/profileservice/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java	                        (rev 0)
+++ trunk/profileservice/src/main/org/jboss/managed/plugins/advice/TraceAdvice.java	2008-03-05 15:30:22 UTC (rev 70431)
@@ -0,0 +1,99 @@
+/*
+* 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);
+   
+   /**
+    * Interceptor
+    * 
+    * @param invocation the invocation
+    * @return the result
+    * @throws Throwable for any problem
+    */
+   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: trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java	                        (rev 0)
+++ trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperAdvice.java	2008-03-05 15:30:22 UTC (rev 70431)
@@ -0,0 +1,139 @@
+/*
+* 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.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: 63962 $
+ */
+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)
+   {
+      return GeneratedAOPProxyFactory.createProxy(target, interfaceClass);
+   }
+}

Added: trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java	                        (rev 0)
+++ trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperIterator.java	2008-03-05 15:30:22 UTC (rev 70431)
@@ -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: trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperSet.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperSet.java	                        (rev 0)
+++ trunk/profileservice/src/main/org/jboss/managed/plugins/advice/WrapperSet.java	2008-03-05 15:30:22 UTC (rev 70431)
@@ -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();
+   }
+}




More information about the jboss-cvs-commits mailing list