/*
class maintained by martl@sulis.de

purpose: arrange setup so main() of given class is invoked with windchill credentials set.

This program is free software; you can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation;
see http://www.gnu.org/licenses/lgpl.html (und deutsch: http://www.gnu.de/lgpl-ger.html)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

*/
package ext.tools;
import java.lang.reflect.*;
import wt.method.*;
/**
  * set user and password, then call main() on class passed as argument.
  *
  * @author mkraegeloh
  * @version 1.0
  */

class WtWrap{
   public static final String CVSVersion = "$Header: /usr/local/cvsroot/SULIS/src/ext/tools/WtWrap.java,v 1.4 2007/01/22 10:41:43 mkr Exp $";
   /**
     *  set user and password, then call main() on class passed as argument.
     *
     * @param a	the program args - starting with user, password, class, remaining args are passed to main()
     * @exception Exception	
     * @return void	
   */
   public static void main(String[] a)throws Exception{
      if(a.length < 3){
         System.err.println("usage: wtwrap userid passwd class [args]");
         return;
      }
	RemoteMethodServer server = RemoteMethodServer.getDefault();
	server.setUserName(a[0]);
	server.setPassword(a[1]);
      Class c = Class.forName(a[2]);
      String[] b=new String[a.length-3];
      Method m=c.getMethod("main",new Class[]{b.getClass()});
      for(int j=0,i=3;i<a.length;)
        b[j++]=a[i++];
      m.invoke(c,new Object[]{b});
	System.exit(0);
   }
}
