[jboss-cvs] JBossAS SVN: r82343 - in projects/aop/trunk/aophelper/src/main: java/org/jboss/aophelper/core and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 17 09:09:16 EST 2008


Author: stalep
Date: 2008-12-17 09:09:15 -0500 (Wed, 17 Dec 2008)
New Revision: 82343

Added:
   projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/annotation/Undoable.java
   projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableInterceptor.java
   projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableManager.java
   projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableValue.java
Modified:
   projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/AopRun.java
   projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/SettingInterceptor.java
   projects/aop/trunk/aophelper/src/main/resources/jboss-aop.xml
Log:
[JBAOP-538]
initial undo upload. nothing works atm. 
wait a few days if you want to see something usefull :)


Added: projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/annotation/Undoable.java
===================================================================
--- projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/annotation/Undoable.java	                        (rev 0)
+++ projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/annotation/Undoable.java	2008-12-17 14:09:15 UTC (rev 82343)
@@ -0,0 +1,40 @@
+/*
+  * 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.aophelper.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A Undoable annotation
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.METHOD})
+public @interface Undoable 
+{
+   String callback();
+}

Modified: projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/AopRun.java
===================================================================
--- projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/AopRun.java	2008-12-17 14:01:53 UTC (rev 82342)
+++ projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/AopRun.java	2008-12-17 14:09:15 UTC (rev 82343)
@@ -24,6 +24,8 @@
 import java.io.Serializable;
 import java.util.ArrayList;
 
+import org.jboss.aophelper.annotation.Undoable;
+
 /**
  * A AopRun.
  * 
@@ -63,6 +65,7 @@
     * 
     * @param executionClass The executionClass to set.
     */
+   @Undoable(callback="this_is_callback_method")
    public final void setExecutionClass(String executionClass)
    {
       this.executionClass = executionClass;

Modified: projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/SettingInterceptor.java
===================================================================
--- projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/SettingInterceptor.java	2008-12-17 14:01:53 UTC (rev 82342)
+++ projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/SettingInterceptor.java	2008-12-17 14:09:15 UTC (rev 82343)
@@ -38,7 +38,7 @@
 
    public String getName()
    {
-      return "ClasspathInterceptor";
+      return "SettingInterceptor";
    }
 
    public Object invoke(Invocation invocation) throws Throwable

Added: projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableInterceptor.java
===================================================================
--- projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableInterceptor.java	                        (rev 0)
+++ projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableInterceptor.java	2008-12-17 14:09:15 UTC (rev 82343)
@@ -0,0 +1,67 @@
+/*
+  * 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.aophelper.core;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aophelper.annotation.Undoable;
+
+/**
+ * A UndoableInterceptor.
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class UndoableInterceptor implements Interceptor
+{
+
+   public String getName()
+   {
+      return "SettingInterceptor";
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      MethodInvocation mi = (MethodInvocation) invocation;
+      Undoable undoable = (Undoable) invocation.resolveAnnotation(org.jboss.aophelper.annotation.Undoable.class);
+      System.out.println("callback: "+undoable.callback());
+      
+      System.out.println("Class: "+mi.getTargetObject().getClass().getName());
+      System.out.println("Method: "+mi.getMethod().getName());
+      
+      Object[] args = mi.getArguments();
+      if(args != null && args.length > 0)
+      {
+         UndoableManager.instance().addUndoable(mi.getTargetObject(), mi.getMethod(), args[0]);
+         for(Object o : args)
+         System.out.println("args: "+o.toString());
+      }
+
+      
+      return invocation.invokeNext();
+      
+   }
+   
+   
+
+}

Added: projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableManager.java
===================================================================
--- projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableManager.java	                        (rev 0)
+++ projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableManager.java	2008-12-17 14:09:15 UTC (rev 82343)
@@ -0,0 +1,66 @@
+/*
+  * 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.aophelper.core;
+
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+
+/**
+ * A UndoableManager.
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class UndoableManager
+{
+   private LinkedList<UndoableValue> undoables;
+   
+   private static UndoableManager instance = new UndoableManager();
+   
+   private UndoableManager()
+   {
+      undoables = new LinkedList<UndoableValue>();
+   }
+   
+   public static UndoableManager instance()
+   {
+      return instance;
+   }
+
+   public UndoableValue findUndoable(Object o, Method m)
+   {
+      UndoableValue uv = new UndoableValue(o,m);
+      int index = undoables.lastIndexOf(uv);
+      if(index < 0)
+         System.out.println("NO UNDOHISTORY ON: "+uv.toString());
+      
+      
+      return null;
+   }
+   
+   public void addUndoable(Object o, Method m, Object value)
+   {
+      UndoableValue uv = new UndoableValue(o,m,value);
+      undoables.add(uv);
+      System.out.println("Adding to undoablelist: "+uv);
+   }
+}

Added: projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableValue.java
===================================================================
--- projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableValue.java	                        (rev 0)
+++ projects/aop/trunk/aophelper/src/main/java/org/jboss/aophelper/core/UndoableValue.java	2008-12-17 14:09:15 UTC (rev 82343)
@@ -0,0 +1,160 @@
+/*
+  * 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.aophelper.core;
+
+import java.lang.reflect.Method;
+
+/**
+ * A UndoableValue.
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class UndoableValue
+{
+   private Object executionObject;
+   private Method method;
+   private Object value;
+
+   /**
+    * Create a new UndoableValue.
+    * 
+    * @param o
+    * @param m
+    */
+   public UndoableValue(Object o, Method m)
+   {
+      setExecutionObject(o);
+      setMethod(m);
+   }
+
+   /**
+    * Create a new UndoableValue.
+    * 
+    * @param o
+    * @param m
+    * @param value
+    */
+   public UndoableValue(Object o, Method m, Object value)
+   {
+      setExecutionObject(o);
+      setMethod(m);
+      setValue(value);
+   }
+
+   /**
+    * Get the executionObject.
+    * 
+    * @return the executionObject.
+    */
+   public Object getExecutionObject()
+   {
+      return executionObject;
+   }
+
+   /**
+    * Set the executionObject.
+    * 
+    * @param executionObject The executionObject to set.
+    */
+   public void setExecutionObject(Object executionObject)
+   {
+      this.executionObject = executionObject;
+   }
+
+   /**
+    * Get the method.
+    * 
+    * @return the method.
+    */
+   public Method getMethod()
+   {
+      return method;
+   }
+
+   /**
+    * Set the method.
+    * 
+    * @param method The method to set.
+    */
+   public void setMethod(Method method)
+   {
+      this.method = method;
+   }
+
+   /**
+    * Get the data.
+    * 
+    * @return the data.
+    */
+   public Object getValue()
+   {
+      return value;
+   }
+
+   /**
+    * Set the data.
+    * 
+    * @param data The data to set.
+    */
+   public void setValue(Object value)
+   {
+      this.value = value;
+   }
+   
+   @Override
+   public boolean equals(Object o)
+   {
+      if(!(o instanceof UndoableValue))
+         return false;
+      UndoableValue uv = (UndoableValue) o;
+      if(uv.getMethod().getName().equals(getMethod().getName()) &&
+            uv.getExecutionObject().getClass().getName().equals(getExecutionObject().getClass().getName()))
+            return true;
+      else
+         return false;
+  }
+   public boolean equals(Object o, Method m)
+   {
+      if(m.getName().equals(getMethod().getName()) &&
+            o.getClass().getName().equals(getExecutionObject().getClass().getName()))
+            return true;
+      else
+         return false;
+  }
+   
+   @Override
+   public int hashCode()
+   {
+      return getMethod().getName().hashCode() + getExecutionObject().getClass().getName().hashCode();
+   }
+   
+   @Override
+   public String toString()
+   {
+      StringBuffer sb = new StringBuffer();
+      sb.append("Execution class: ").append(getExecutionObject().getClass().getName());
+      sb.append(", Method: ").append(getMethod().getName());
+      return sb.toString();
+   }
+
+}

Modified: projects/aop/trunk/aophelper/src/main/resources/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aophelper/src/main/resources/jboss-aop.xml	2008-12-17 14:01:53 UTC (rev 82342)
+++ projects/aop/trunk/aophelper/src/main/resources/jboss-aop.xml	2008-12-17 14:09:15 UTC (rev 82343)
@@ -5,4 +5,7 @@
        <interceptor class="org.jboss.aophelper.core.SettingInterceptor"/>
    </bind>
 
+   <bind pointcut="execution(* *->@org.jboss.aophelper.annotation.Undoable(..))">
+       <interceptor class="org.jboss.aophelper.core.UndoableInterceptor"/>
+   </bind>
 </aop>




More information about the jboss-cvs-commits mailing list