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