Announcement Announcement Module
Collapse
No announcement yet.
Dynamically parameterized prototypes?! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamically parameterized prototypes?!

    Hi

    I've been reading up on Spring lately and it looks quite nice, but lets say I want to do someting like this

    Code:
    public interface AddRoleCommand {
       public void execute();
    }
    
    public class AddRoleCommandImpl implements AddRoleCommand {
       private Person user;
       private Role role;
    
       public AddRoleCommandImpl (Person user, Role role) {
          this.user = user;
          this.role = role;
       }
    
       public void execute() {
          // do some checks
          // do the real stuff
       }
    }
    Is it possible to pass 'user' and 'role' to a constructor of a prototype bean? Is there a way to do it cleany in without knowning the implementation, except maybe in configuration files of Spring?!

    Thanks

  • #2
    I do not, really, understand what you are trying to achieve as I do not understand where User and Role instances come from?
    You can use the following code to configure a command:
    Code:
    <bean id="user" .../>
    <bean id="role" .../>
    <bean id="command" class="AddRoleCommandImpl">
      <contructor-arg index="0"><ref local="user"/></contructor-arg>
      <contructor-arg index="1"><ref local="role"/></contructor-arg>
    <bean>
    You can hide the implementation in your code by simply using the AddRoleCommand interface to access bean command.
    HTH

    Comment

    Working...
    X