X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fmethod%2FMethodInterfaceUtil.java;h=eb27fa5de8c978b9e9bfb5efc1caf23a1e8a5468;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=a1ec2a697ab25a485209e84abcbd7144dbd29909;hpb=86e91ef31d25e4d5950cae130754846d15119c61;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/method/MethodInterfaceUtil.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/method/MethodInterfaceUtil.java index a1ec2a697..eb27fa5de 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/method/MethodInterfaceUtil.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/method/MethodInterfaceUtil.java @@ -1,81 +1,81 @@ -/******************************************************************************* - * Copyright (c) 2010 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2010 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.databoard.method; -import static org.objectweb.asm.Opcodes.AALOAD; -import static org.objectweb.asm.Opcodes.AASTORE; -import static org.objectweb.asm.Opcodes.ACC_ABSTRACT; -import static org.objectweb.asm.Opcodes.ACC_FINAL; -import static org.objectweb.asm.Opcodes.ACC_INTERFACE; -import static org.objectweb.asm.Opcodes.ACC_PUBLIC; -import static org.objectweb.asm.Opcodes.ACC_STATIC; -import static org.objectweb.asm.Opcodes.ACC_SUPER; -import static org.objectweb.asm.Opcodes.ALOAD; -import static org.objectweb.asm.Opcodes.ANEWARRAY; -import static org.objectweb.asm.Opcodes.ARETURN; -import static org.objectweb.asm.Opcodes.ARRAYLENGTH; -import static org.objectweb.asm.Opcodes.ASTORE; -import static org.objectweb.asm.Opcodes.ATHROW; -import static org.objectweb.asm.Opcodes.CHECKCAST; -import static org.objectweb.asm.Opcodes.DLOAD; -import static org.objectweb.asm.Opcodes.DRETURN; -import static org.objectweb.asm.Opcodes.DUP; -import static org.objectweb.asm.Opcodes.FLOAD; -import static org.objectweb.asm.Opcodes.FRETURN; -import static org.objectweb.asm.Opcodes.GETFIELD; -import static org.objectweb.asm.Opcodes.GETSTATIC; -import static org.objectweb.asm.Opcodes.GOTO; -import static org.objectweb.asm.Opcodes.ICONST_0; -import static org.objectweb.asm.Opcodes.IFEQ; -import static org.objectweb.asm.Opcodes.IF_ICMPLT; -import static org.objectweb.asm.Opcodes.ILOAD; -import static org.objectweb.asm.Opcodes.INSTANCEOF; -import static org.objectweb.asm.Opcodes.INVOKEINTERFACE; -import static org.objectweb.asm.Opcodes.INVOKESPECIAL; -import static org.objectweb.asm.Opcodes.INVOKESTATIC; -import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; -import static org.objectweb.asm.Opcodes.IRETURN; -import static org.objectweb.asm.Opcodes.ISTORE; -import static org.objectweb.asm.Opcodes.LLOAD; -import static org.objectweb.asm.Opcodes.LRETURN; -import static org.objectweb.asm.Opcodes.NEW; -import static org.objectweb.asm.Opcodes.POP; -import static org.objectweb.asm.Opcodes.PUTFIELD; -import static org.objectweb.asm.Opcodes.PUTSTATIC; -import static org.objectweb.asm.Opcodes.RETURN; -import static org.objectweb.asm.Opcodes.V1_6; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; - -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.Label; -import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Methods; -import org.simantics.databoard.adapter.AdaptException; -import org.simantics.databoard.adapter.Adapter; -import org.simantics.databoard.adapter.AdapterConstructionException; -import org.simantics.databoard.binding.error.BindingConstructionException; -import org.simantics.databoard.method.MethodInterface.AsyncResult; -import org.simantics.databoard.method.MethodInterface.ExecutionError; +import static org.objectweb.asm.Opcodes.AALOAD; +import static org.objectweb.asm.Opcodes.AASTORE; +import static org.objectweb.asm.Opcodes.ACC_ABSTRACT; +import static org.objectweb.asm.Opcodes.ACC_FINAL; +import static org.objectweb.asm.Opcodes.ACC_INTERFACE; +import static org.objectweb.asm.Opcodes.ACC_PUBLIC; +import static org.objectweb.asm.Opcodes.ACC_STATIC; +import static org.objectweb.asm.Opcodes.ACC_SUPER; +import static org.objectweb.asm.Opcodes.ALOAD; +import static org.objectweb.asm.Opcodes.ANEWARRAY; +import static org.objectweb.asm.Opcodes.ARETURN; +import static org.objectweb.asm.Opcodes.ARRAYLENGTH; +import static org.objectweb.asm.Opcodes.ASTORE; +import static org.objectweb.asm.Opcodes.ATHROW; +import static org.objectweb.asm.Opcodes.CHECKCAST; +import static org.objectweb.asm.Opcodes.DLOAD; +import static org.objectweb.asm.Opcodes.DRETURN; +import static org.objectweb.asm.Opcodes.DUP; +import static org.objectweb.asm.Opcodes.FLOAD; +import static org.objectweb.asm.Opcodes.FRETURN; +import static org.objectweb.asm.Opcodes.GETFIELD; +import static org.objectweb.asm.Opcodes.GETSTATIC; +import static org.objectweb.asm.Opcodes.GOTO; +import static org.objectweb.asm.Opcodes.ICONST_0; +import static org.objectweb.asm.Opcodes.IFEQ; +import static org.objectweb.asm.Opcodes.IF_ICMPLT; +import static org.objectweb.asm.Opcodes.ILOAD; +import static org.objectweb.asm.Opcodes.INSTANCEOF; +import static org.objectweb.asm.Opcodes.INVOKEINTERFACE; +import static org.objectweb.asm.Opcodes.INVOKESPECIAL; +import static org.objectweb.asm.Opcodes.INVOKESTATIC; +import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; +import static org.objectweb.asm.Opcodes.IRETURN; +import static org.objectweb.asm.Opcodes.ISTORE; +import static org.objectweb.asm.Opcodes.LLOAD; +import static org.objectweb.asm.Opcodes.LRETURN; +import static org.objectweb.asm.Opcodes.NEW; +import static org.objectweb.asm.Opcodes.POP; +import static org.objectweb.asm.Opcodes.PUTFIELD; +import static org.objectweb.asm.Opcodes.PUTSTATIC; +import static org.objectweb.asm.Opcodes.RETURN; +import static org.objectweb.asm.Opcodes.V1_6; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; + +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.Type; +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Methods; +import org.simantics.databoard.adapter.AdaptException; +import org.simantics.databoard.adapter.Adapter; +import org.simantics.databoard.adapter.AdapterConstructionException; +import org.simantics.databoard.binding.error.BindingConstructionException; +import org.simantics.databoard.method.MethodInterface.AsyncResult; +import org.simantics.databoard.method.MethodInterface.ExecutionError; public class MethodInterfaceUtil { @@ -91,17 +91,17 @@ public class MethodInterfaceUtil { public static MethodInterface bindInterface(Class interfaze, final T obj) throws BindingConstructionException { final Interface interfaceType = Methods.getInterfaceType(interfaze); - MethodInterface mi = bindInterface(interfaceType, obj); - /* - System.out.println("Created methodinterface for "+interfaze.getName()); - for (MethodTypeDefinition k : mi.getInterface().methodDefinitions) { - System.out.print(k); - if (k.getType().requestType.getComponentCount()>0) { - System.out.print(System.identityHashCode( k.getType().requestType.getComponentType(0) ) ); - } - System.out.println(); - } - */ + MethodInterface mi = bindInterface(interfaceType, obj); + /* + System.out.println("Created methodinterface for "+interfaze.getName()); + for (MethodTypeDefinition k : mi.getInterface().methodDefinitions) { + System.out.print(k); + if (k.getType().requestType.getComponentCount()>0) { + System.out.print(System.identityHashCode( k.getType().requestType.getComponentType(0) ) ); + } + System.out.println(); + } + */ return mi; } @@ -177,14 +177,14 @@ public class MethodInterfaceUtil { AsyncResultImpl result = new AsyncResultImpl(); try { Object response = method.invoke(obj, (Object[]) request); - if (response != null) result.setResponse(response); + if (response != null) result.setResponse(response); else result.setInvokeException(new org.simantics.databoard.method.InvokeException(new NullPointerException())); - } catch(InvocationTargetException t) { - Throwable e = t.getTargetException(); - if (e instanceof RuntimeException) { - result.setInvokeException(new org.simantics.databoard.method.InvokeException( (Exception) e)); + } catch(InvocationTargetException t) { + Throwable e = t.getTargetException(); + if (e instanceof RuntimeException) { + result.setInvokeException(new org.simantics.databoard.method.InvokeException( (Exception) e)); } else { - result.setExecutionError(e); + result.setExecutionError(e); } } catch(IllegalArgumentException e) { result.setInvokeException(new org.simantics.databoard.method.InvokeException(e)); @@ -358,12 +358,12 @@ public class MethodInterfaceUtil { Class interfaze = loadClass(name.substring(0, name.length()-5)); ClassWriter cw = new ClassWriter(0); createImpl(name, interfaze, cw); - byte[] b = cw.toByteArray(); - /* - new ClassReader(b).accept( - new ASMifierClassVisitor(new PrintWriter(System.out)), - 0 - ); + byte[] b = cw.toByteArray(); + /* + new ClassReader(b).accept( + new ASMifierClassVisitor(new PrintWriter(System.out)), + 0 + ); */ Class clazz = defineClass(name, b, 0, b.length); return clazz; @@ -678,7 +678,7 @@ public class MethodInterfaceUtil { Class returnType = m.getReturnType(); if (returnType==void.class) { - mv.visitInsn(POP); + mv.visitInsn(POP); mv.visitLabel(l1); mv.visitInsn(RETURN); } else if (returnType==int.class) {