1 package org.simantics.db.services.adaption.reflection;
3 import org.simantics.db.AsyncReadGraph;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.adaption.Adapter;
7 import org.simantics.db.common.request.ReadRequest;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.procedure.AsyncProcedure;
11 public abstract class AbstractReflectionAdapter<T> implements Adapter<T,Resource> {
12 IDynamicAdapter2[] parameters;
14 public AbstractReflectionAdapter(IDynamicAdapter2 ... parameters) throws SecurityException, NoSuchMethodException, DatabaseException {
15 this.parameters = parameters;
18 public abstract void construct(AsyncReadGraph g, AsyncProcedure<T> procedure, Object ... args);
21 public void adapt(AsyncReadGraph g, final Resource source, final Resource r, final AsyncProcedure<T> procedure) {
23 if(parameters.length == 0) {
25 // System.out.println("ReflectionAdapter2 " + ReflectionAdapter2.this);
26 construct(g, procedure);
28 } else if( parameters.length == 1 && parameters[0] instanceof ThisResource2) {
30 construct(g, procedure, r);
34 g.asyncRequest(new ReadRequest() {
37 public void run(ReadGraph graph) throws DatabaseException {
39 // System.out.println("ReflectionAdapter2 " + ReflectionAdapter2.this);
41 Object[] args = new Object[parameters.length];
42 for(int i=0;i<parameters.length;++i)
43 args[i] = parameters[i].adapt(graph, r);
44 construct(graph, procedure, args);