I've got some problem that i can't figure out for a loong time.
I'm building web app in core-plugin architecture. Plugins provides some functionality by methods. For example:
public void doSomething(Input input){
// Some functionality
}
The Input class can be basically anything. For example:
public class Input{
private String text;
private List<String> textList;
private InnerField inner;
private List<InnerField> innerList;
}
public class InnerField{
private String text;
pirvate Integer number;
}
The core module is collecting all methods of plugins and provides them to webpage user so the user can pick a method and set input data.
I know how to use java reflection api and get into metadata of methods and classes. The problem is with figuring out the structure of Class that would describe the Input and in same time store the data of Object.
In other words. I want to create a Class let's say InputData that i can pass to frontend which will:
- build form based on fields declaration
- fill form based on data
This InputData on submit would be serialized to json and saved in DB and, of course, should be mapped to original Input class so we can pass it to the plugin method.
I was thinking about something like this:
public class InputField{
private String className; //java.lang.String, some.package.CustomClass
private boolean variable; // if true, the strVal is a reference to other object (stored in map)
private String strVal; //value parsed to String if it's basic type like String, Integer, Boolean
private List<InputField> fields; //list of inner fields if it's complex type
}
And this would be good enough but only if the Input class would not have List types in it.
The one last kicker is that each field (even Input object itself) can be a referece to some variable. So for example the user provided some values for Input class and want to reuse that so in form he just provides a name of the variable that it refers to. At the runtime when we invoke the plugin method the processor istead of parsing this json to data would search for data referenced by the variable name.
I know.. probably none of you know what i'm talking about but i'm in so awfull mindset that i can't even explain it well.
I am hoping that somone will kind of understand me and put me on the right tracks. Maybe someone had similar issue?
Aucun commentaire:
Enregistrer un commentaire