Results 1 to 2 of 2

Thread: Dynamically parameterized prototypes?!

  1. #1
    Join Date
    Dec 2004
    Posts
    1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

Similar Threads

  1. Replies: 8
    Last Post: Dec 12th, 2006, 05:40 AM
  2. Replies: 1
    Last Post: Jan 11th, 2006, 08:11 AM
  3. Replies: 3
    Last Post: Oct 19th, 2005, 03:32 PM
  4. using jmx autodetect with prototypes
    By Anonymous in forum Management
    Replies: 1
    Last Post: Oct 13th, 2005, 06:57 AM
  5. Multiple Resource Bundles Dynamically Loaded
    By frozenquest in forum Web
    Replies: 1
    Last Post: Jan 27th, 2005, 04:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •