title: Java configuration file instantiate object with parameters
body: <p>I'm trying to find a way that I can specify a class in a configuration file, as well as the parameters that should be passed to the constructor.</p>
  
  <p>For example, imagine the following XML configuration file:</p>
  
  <pre><code>&lt;AuthServer&gt;
      &lt;Authenticator type="com.mydomain.server.auth.DefaultAuthenticator"&gt;
          &lt;Param type="com.mydomain.database.Database" /&gt;
      &lt;/Authenticator&gt;
  &lt;/AuthServer&gt;
  </code></pre>
  
  <p>Now, in my Java code, I want to do the following:</p>
  
  <pre><code>public class AuthServer {
      protected IAuthenticator authenticator;
  
      public AuthServer(IAuthenticator authenticator) {
          this.authenticator = authenticator;
      }
  
      public int authenticate(String username, String password) {
          return authenticator.authenticator(username, password);
      }
  
      public static void main(String[] args) throws Exception {
          //Read XML configuration here.
  
          AuthServer authServer = new AuthServer(
              new DefaultAuthenticator(new Database()) //Want to replace this line with what comes from the configuration file.
          );
      }
  }
  </code></pre>
  
  <p>I can read the XML of course, and get the values from it, but then I'm unsure how to emulate the line indicated above (want to replace...) with the comment with the values from the XML configuration file. Is there a way to do something like this?</p>