Hi guys...
See the following code:
Code:public class User{ String login; String center; //gets and sets } public abstract class MyBean{ abstract void doBusiness(); } public class MyBeanToCenterX extends MyBean{ void doBusiness(){ //Do the business according to rules of center X } } public class MyBeanToCenterY extends MyBean{ void doBusiness(){ //Do the business according to rules of center Y } }
Ok, I have a requirement that a determined subclass of MyBean must be used according to the value of the "center" attribute of a User instance... Let´s say that the center X has a business rule and the center Y has another rule... The same runtime (deployment) will be used by users from centers X and Y, the decision must be on runtime... A custom security system will set the value of the "center" attribute, previously stored on a database....
I would like to do somethinhlike this:
Code:User user = //get the user MyBean bean = context.getBean("myBean",user.getCenter()); bean.doBusiness();
I´ve already a solution using an adapter to the context ("MyContext") and naming the concrete beans as "myBeanX" and "myBeanY" on the xml... Then "MyContext" will use Spring context appending the center to the name of the bean...
Spring has any standard feature to do this? The problem is simple as to getting a different instance based on runtime values...
Thank you very much!


Reply With Quote