Example: I have a an abstract class "animal" and subclass "lion" and "tiger". Subclass name is written on NotesDocument field "Form". How do i create bean named animal with class "Tiger" or "Lion" at runtime.
My plan is: I make a bean with managed-bean-name "animal", managed-bean-class "AnimalFactory". Then somewhere, where?, I want to (pseudocode)
Document doc = database.getDocById("AAAA"); //from docId parameter
String animalType = doc.getItemValueString("Form");
if (animalType.equals("Lion") return makeLionInstance();
else return makeTigerInstance();
Can someone point me in a right direction or give me an example?
EDIT
I havent study any answers provided... Will do tomorrow.
Problem is we have 100k-300k LoC project and noone knows what exactly it is doing. It is 15 years old and had 30-50 developers. Anyway, we decided to go web. In java we see a great oppurtunity to rewrite project to java (as many have already done), remove redundant code, define interfaces etc (and later, where no MS objects are involved, replace java code with LS code)... We have 6 different (with similar base) doc (form)types with subtypes and every type has 5 different workflows, which are exclusive.
I dont have the knowledge of how to instantiate specific class from notesdocument at runtime. One workaround is to provide variables to base class and instantiate them at runtime based on field "Form". I have a feeling, this will not suffice in the long run.
As in my "plan", I THINK I have a vague idea of what must be done. I dont know where to insert code, neither what I must be careful about.
TL:DR
How to have instance of type defined on document field "Form" resolved to managed bean at runtime.
I think this article was revolutionary at the time. It helped me a lot to take control over managed beans. Get inspired by it and make factory bean Zoo implementing Map interface. Your
get(String)
method will instantiate or retrieve according animal object based on its name.Your EL/SSJS will be easy as: