import org.simantics.db.AsyncReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.adaption.Adapter;
-import org.simantics.db.common.request.AsyncReadRequest;
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<T> implements Adapter<T, Resource> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ReflectionAdapter2.class);
+
Constructor<? extends T> constructor;
IDynamicAdapter2[] parameters;
if(parameters.length == 0) {
-// System.out.println("ReflectionAdapter2 " + ReflectionAdapter2.this);
-
try {
procedure.execute(g, constructor.newInstance());
} catch (IllegalArgumentException e) {
procedure.exception(g, e);
- e.printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e);
} catch (InstantiationException e) {
procedure.exception(g, e);
- e.printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e);
} catch (IllegalAccessException e) {
procedure.exception(g, e);
- e.printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e);
} catch (InvocationTargetException e) {
procedure.exception(g, e.getCause());
- e.getCause().printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e.getCause());
}
} else if( parameters.length == 1 && parameters[0] instanceof ThisResource2) {
procedure.execute(g, constructor.newInstance(r));
} catch (IllegalArgumentException e) {
procedure.exception(g, e);
- e.printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e);
} catch (InstantiationException e) {
procedure.exception(g, e);
- e.printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e);
} catch (IllegalAccessException e) {
procedure.exception(g, e);
- e.printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e);
} catch (InvocationTargetException e) {
procedure.exception(g, e.getCause());
- e.getCause().printStackTrace();
+ LOGGER.error("Unexpected exception during adapter creation", e.getCause());
}
} else {
- g.asyncRequest(new AsyncReadRequest() {
-
+ g.asyncRequest(new AsyncRead<T>() {
+
@Override
- public void run(AsyncReadGraph graph) {
-
+ public void perform(AsyncReadGraph graph, AsyncProcedure<T> p) {
+
Object[] args = new Object[parameters.length];
try {
- for(int i=0;i<parameters.length;++i)
- args[i] = parameters[i].adapt(graph, r);
- procedure.execute(graph, constructor.newInstance(args));
- } catch (IllegalArgumentException e) {
- procedure.exception(g, e);
- e.printStackTrace();
- } catch (InstantiationException e) {
- procedure.exception(g, e);
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- procedure.exception(g, e);
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- procedure.exception(g, e.getCause());
- e.getCause().printStackTrace();
- } catch (DatabaseException e) {
- procedure.exception(g, e);
- e.printStackTrace();
- } catch (Throwable t) {
- procedure.exception(g, t);
- t.printStackTrace();
- }
+ for(int i=0;i<parameters.length;++i)
+ args[i] = parameters[i].adapt(graph, r);
+ p.execute(graph, constructor.newInstance(args));
+ } catch (IllegalArgumentException e) {
+ p.exception(g, e);
+ LOGGER.error("Unexpected exception during adapter creation", e);
+ } catch (InstantiationException e) {
+ p.exception(g, e);
+ LOGGER.error("Unexpected exception during adapter creation", e);
+ } catch (IllegalAccessException e) {
+ p.exception(g, e);
+ LOGGER.error("Unexpected exception during adapter creation", e);
+ } catch (InvocationTargetException e) {
+ p.exception(g, e.getCause());
+ LOGGER.error("Unexpected exception during adapter creation", e);
+ } catch (DatabaseException e) {
+ p.exception(g, e);
+ LOGGER.error("Unexpected exception during adapter creation", e);
+ } catch (Throwable t) {
+ p.exception(g, t);
+ LOGGER.error("Unexpected exception during adapter creation", t);
+ }
+
}
@Override
return "ReflectionAdapter$1" + constructor + "$" + Arrays.toString(parameters);
}
- });
+ }, procedure);
}