[jboss-cvs] javassist SVN: r636 - in branches/rel_3_12_0_ga_JBPAPP-9257/src: test/test/javassist/proxy and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 12 12:15:32 EDT 2012


Author: chiba
Date: 2012-06-12 12:15:32 -0400 (Tue, 12 Jun 2012)
New Revision: 636

Added:
   branches/rel_3_12_0_ga_JBPAPP-9257/src/main/javassist/util/proxy/Proxy.java
   branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/Foo.java
   branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/JBPAPP9257Test.java
Log:
commit Kyle's fixes

Added: branches/rel_3_12_0_ga_JBPAPP-9257/src/main/javassist/util/proxy/Proxy.java
===================================================================
--- branches/rel_3_12_0_ga_JBPAPP-9257/src/main/javassist/util/proxy/Proxy.java	                        (rev 0)
+++ branches/rel_3_12_0_ga_JBPAPP-9257/src/main/javassist/util/proxy/Proxy.java	2012-06-12 16:15:32 UTC (rev 636)
@@ -0,0 +1,33 @@
+/*
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License.  Alternatively, the contents of this file may be used under
+ * the terms of the GNU Lesser General Public License Version 2.1 or later,
+ * or the Apache License Version 2.0.
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ */
+
+package javassist.util.proxy;
+
+/**
+ * The interface implemented by proxy classes.
+ * This interface only provides a setter method.
+ * To obtain a handler, call {@link ProxyFactory#getHandler(Proxy)}.
+ *
+ * @see ProxyFactory
+ * @see 3.16
+ */
+public interface Proxy {
+    /**
+     * Sets a handler.  It can be used for changing handlers
+     * during runtime.
+     */
+    void setHandler(MethodHandler mi);
+}

Added: branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/Foo.java
===================================================================
--- branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/Foo.java	                        (rev 0)
+++ branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/Foo.java	2012-06-12 16:15:32 UTC (rev 636)
@@ -0,0 +1,14 @@
+package test.javassist.proxy;
+
+public class Foo
+{
+    public String doSomething()
+    {
+      return "I'm doing something";
+    }
+
+    public Object getHandler()
+    {
+        return "This is a secret handler";
+    }
+}

Added: branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/JBPAPP9257Test.java
===================================================================
--- branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/JBPAPP9257Test.java	                        (rev 0)
+++ branches/rel_3_12_0_ga_JBPAPP-9257/src/test/test/javassist/proxy/JBPAPP9257Test.java	2012-06-12 16:15:32 UTC (rev 636)
@@ -0,0 +1,44 @@
+package test.javassist.proxy;
+
+import java.lang.reflect.Method;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.MethodFilter;
+import javassist.util.proxy.ProxyObject;
+import javassist.util.proxy.Proxy;
+import junit.framework.TestCase;
+
+public class JBPAPP9257Test extends TestCase
+{
+    public void testGetHandler() throws Exception
+    {
+        try
+        {
+            ProxyFactory f = new ProxyFactory();
+            f.setSuperclass(Foo.class);
+            f.setFilter(new MethodFilter() {
+                public boolean isHandled(Method m) {
+                  // ignore finalize()
+                  return !m.getName().equals("finalize");
+              }
+            });
+            Class c = f.createClass();
+            MethodHandler mi = new MethodHandler() {
+              public Object invoke(Object self, Method m, Method proceed,
+                                   Object[] args) throws Throwable {
+                System.out.println("Name: " + m.getName());
+                return proceed.invoke(self, args);  // execute the original method.
+              }
+            };
+            Foo foo = (Foo)c.newInstance();
+            ((ProxyObject)foo).setHandler(mi);
+            if(!foo.doSomething().equals("I'm doing something"))
+              fail("Proxy isn't working properly");
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace();
+            throw e;
+        }
+    }
+}



More information about the jboss-cvs-commits mailing list