Sfoglia il codice sorgente

ogarnięcie tego cglib

Ranides Atterwim 13 anni fa
parent
commit
71ae0e2c43

File diff suppressed because it is too large
+ 0 - 188
hs_err_pid3152.log


+ 19 - 5
pom.xml

@@ -65,6 +65,25 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-install-plugin</artifactId>
+                <version>2.4</version>
+                <executions>
+                    <execution>
+                        <id>repo</id>
+                        <phase>verify</phase>
+                        <goals>
+                            <goal>install</goal>
+                        </goals>
+                        <configuration>
+                            <localRepository>false</localRepository>
+                            <localRepositoryPath>file://${project.basedir}/target/repo</localRepositoryPath>
+                            <!--<pomFile>${basedir}/assira.asm.xml</pomFile>-->
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
             <!-- Pamięć dla LFSRTest -->
 <!--            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -150,10 +169,5 @@
             <artifactId>joda-time</artifactId>
             <version>2.1</version>
         </dependency>
-        <dependency>
-            <groupId>cglib</groupId>
-            <artifactId>cglib</artifactId>
-            <version>2.2.2</version>
-        </dependency>
     </dependencies>
 </project>

+ 8 - 9
src/main/java/net/ranides/assira/asm/ProxyDelegator.java

@@ -4,12 +4,12 @@
  */
 package net.ranides.assira.asm;
 
+import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import net.ranides.assira.collection.ArrayUtils;
 import net.ranides.assira.generic.BiFunction;
-import net.sf.cglib.proxy.Enhancer;
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
+
 
 
 /**
@@ -22,14 +22,13 @@ public final class ProxyDelegator {
         // utility class
     }
     
-    
     @SuppressWarnings("unchecked")
-    public static <T> T paramWrapper(T object, BiFunction<Object,Object> function) {
-        return (T)Enhancer.create(object.getClass(), new ParamWrapper(object, function));
+    public static <T> T paramWrapper(final T object, Class<T> intface, final BiFunction<Object,Object> function) {
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        return (T)Proxy.newProxyInstance(loader, new Class[]{intface}, new ParamWrapper(object, function));
     }
     
-    private static class ParamWrapper implements MethodInterceptor {
-        
+    private static class ParamWrapper implements InvocationHandler {
         private final Object delegator;
         private final BiFunction<Object, Object> function;
 
@@ -39,7 +38,7 @@ public final class ProxyDelegator {
         }
         
         @Override
-        public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
             return function.apply(method.invoke(delegator, ArrayUtils.inverse(args, function)));
         }
     }

+ 6 - 0
src/main/java/net/ranides/assira/collection/ArrayUtils.java

@@ -702,6 +702,9 @@ public final class ArrayUtils {
     }
 
     public static <S> Object[] apply(S[] values, Function<?,S> function) { // @test
+        if(values == null) {
+            return values;
+        }
         final int n = values.length;
         Object[] target = new Object[values.length];
         for(int i=0; i<n; i++) {
@@ -711,6 +714,9 @@ public final class ArrayUtils {
     }
 
     public static <T> Object[] inverse(T[] values, CoFunction<T,?> function) {
+        if(values == null) {
+            return values;
+        }
         final int n = values.length;
         Object[] target = new Object[values.length];
         for(int i=0; i<n; i++) {

+ 17 - 7
src/test/java/net/ranides/assira/asm/ProxyDelegatorTest.java

@@ -35,30 +35,40 @@ public class ProxyDelegatorTest {
         }
     };
     
-    private static class JMath {
+    private interface JMath {
+        void width(Number value);
+        void height(Number value);
+        double width();
+        double height();
+        double mul(double a, double b);
+    }
+    
+    private static class CJMath implements JMath {
         
         private double w;
         private double h;
         
-        public JMath() {
+        public CJMath() {
             w = 1.0;
             h = 2.0;
         }
-        
+        @Override
         public void width(Number value) {
             this.w = value.doubleValue();
         }
+        @Override
         public void height(Number value) {
             this.h = value.doubleValue();
         }
-        
+        @Override
         public double width() {
             return w;
         }
+        @Override
         public double height() {
             return h;
         }
-        
+        @Override
         public double mul(double a, double b) {
             return a * b;
         }
@@ -72,8 +82,8 @@ public class ProxyDelegatorTest {
 
     @Test
     public void testCreate() {
-        final JMath jmath = new JMath();
-        final JMath wmath = ProxyDelegator.paramWrapper(jmath, WRAPPER);
+        final JMath jmath = new CJMath();
+        final JMath wmath = ProxyDelegator.paramWrapper(jmath, JMath.class, WRAPPER);
         
         assertEquals(1.0, (Double)jmath.width(), 0.1);
         assertEquals(2.0, (Double)jmath.height(), 0.1);