--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.services.adaption.reflection;\r
+\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.Method;\r
+\r
+import org.simantics.db.AsyncReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.procedure.AsyncProcedure;\r
+\r
+public class StaticMethodAdapter<T> extends AbstractReflectionAdapter<T> {\r
+\r
+ Method constructor;\r
+ \r
+ public StaticMethodAdapter(Class<? extends T> clazz, String methodName, IDynamicAdapter2 ... parameters) throws SecurityException, NoSuchMethodException, DatabaseException {\r
+ super(parameters); \r
+ Class<?>[] parameterTypes = new Class<?>[parameters.length];\r
+ for(int i=0;i<parameters.length;++i)\r
+ parameterTypes[i] = parameters[i].getType();\r
+ this.constructor = clazz.getMethod(methodName, parameterTypes);\r
+ }\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public void construct(AsyncReadGraph g, AsyncProcedure<T> procedure, Object ... args) {\r
+ try {\r
+ procedure.execute(g, (T)constructor.invoke(null, args));\r
+ } catch (IllegalArgumentException e) {\r
+ procedure.exception(g, e);\r
+ e.printStackTrace();\r
+ } catch (IllegalAccessException e) {\r
+ procedure.exception(g, e);\r
+ e.printStackTrace();\r
+ } catch (InvocationTargetException e) {\r
+ procedure.exception(g, e);\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public String toString() {\r
+ return "ReflectionAdapter for " + constructor.getName();\r
+ }\r
+\r
+}\r