1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.services.adaption.reflection;
14 import java.lang.reflect.InvocationTargetException;
15 import java.lang.reflect.Method;
17 import org.simantics.db.AsyncReadGraph;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.procedure.AsyncProcedure;
21 public class StaticMethodAdapter<T> extends AbstractReflectionAdapter<T> {
25 public StaticMethodAdapter(Class<? extends T> clazz, String methodName, IDynamicAdapter2 ... parameters) throws SecurityException, NoSuchMethodException, DatabaseException {
27 Class<?>[] parameterTypes = new Class<?>[parameters.length];
28 for(int i=0;i<parameters.length;++i)
29 parameterTypes[i] = parameters[i].getType();
30 this.constructor = clazz.getMethod(methodName, parameterTypes);
33 @SuppressWarnings("unchecked")
35 public void construct(AsyncReadGraph g, AsyncProcedure<T> procedure, Object ... args) {
37 procedure.execute(g, (T)constructor.invoke(null, args));
38 } catch (IllegalArgumentException e) {
39 procedure.exception(g, e);
41 } catch (IllegalAccessException e) {
42 procedure.exception(g, e);
44 } catch (InvocationTargetException e) {
45 procedure.exception(g, e.getCause());
46 e.getCause().printStackTrace();
51 public String toString() {
52 return "ReflectionAdapter for " + constructor.getName();