// (c) MIT 2003.  All rights reserved.

package rec.agent;




import java.rmi.*;
import java.io.*;
import java.lang.reflect.*;
import metaglue.*;
import rec.util.*;
import rec.sys.*;


public class ModuleMaker implements Serializable {

  String classname = null;

  public ModuleMaker()
  {
    classname = null;
  }
  
  public ModuleMaker( String classname )
  {
    this.classname = classname;
  }

  /**
   * The basic module maker.
   */
  public Module make( Object parent )
  {
    try 
      {
	Class c = Class.forName( classname );
	Class[] args = new Class[1];
	args[0] = Class.forName( "rec.agent.ModuleListener" );
	Constructor con = c.getConstructor( args );
	
	Object[] rargs = new Object[1];
	rargs[0] = parent;

	RemoteModule rm = (RemoteModule)con.newInstance( rargs );

	return (Module)rm;
      }
    catch ( Exception e )
      {
	System.err.println( "Error in attempting to dymanically build " + classname );
	e.printStackTrace();
      }

    return null;
  }


}
