/******************************************************************************* * Copyright (c) 2007, 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.db.services.adaption.reflection; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import org.simantics.db.AsyncReadGraph; import org.simantics.db.Resource; import org.simantics.db.adaption.Adapter; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.request.AsyncRead; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ReflectionAdapter2 implements Adapter { private static final Logger LOGGER = LoggerFactory.getLogger(ReflectionAdapter2.class); Constructor constructor; IDynamicAdapter2[] parameters; public ReflectionAdapter2(Class clazz, IDynamicAdapter2 ... parameters) throws SecurityException, NoSuchMethodException, DatabaseException { Class[] parameterTypes = new Class[parameters.length]; for(int i=0;i procedure) { if(parameters.length == 0) { try { procedure.execute(g, constructor.newInstance()); } catch (IllegalArgumentException e) { procedure.exception(g, e); LOGGER.error("Unexpected exception during adapter creation", e); } catch (InstantiationException e) { procedure.exception(g, e); LOGGER.error("Unexpected exception during adapter creation", e); } catch (IllegalAccessException e) { procedure.exception(g, e); LOGGER.error("Unexpected exception during adapter creation", e); } catch (InvocationTargetException e) { procedure.exception(g, e.getCause()); LOGGER.error("Unexpected exception during adapter creation", e.getCause()); } } else if( parameters.length == 1 && parameters[0] instanceof ThisResource2) { try { procedure.execute(g, constructor.newInstance(r)); } catch (IllegalArgumentException e) { procedure.exception(g, e); LOGGER.error("Unexpected exception during adapter creation", e); } catch (InstantiationException e) { procedure.exception(g, e); LOGGER.error("Unexpected exception during adapter creation", e); } catch (IllegalAccessException e) { procedure.exception(g, e); LOGGER.error("Unexpected exception during adapter creation", e); } catch (InvocationTargetException e) { procedure.exception(g, e.getCause()); LOGGER.error("Unexpected exception during adapter creation", e.getCause()); } } else { g.asyncRequest(new AsyncRead() { @Override public void perform(AsyncReadGraph graph, AsyncProcedure p) { Object[] args = new Object[parameters.length]; try { for(int i=0;i