/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
 *
 * @author ULAN
 */
public class externalApp extends util {

    public static void getApp(String aragorn) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
        String frodo=aragorn;
        

        String [] sam;
        String [] pippin;

        sam=frodo.split("#");
        pippin=sam[2].split(" ");

        Class [] ring = { String.class };
        Object [] params = { new String(pippin[1]) };
        
        Class klass = Class.forName(sam[0]);
        Object theObject = klass.newInstance();
        Method method = klass.getMethod(sam[1], ring);
        method.invoke(theObject, params);
        System.out.println(method.invoke(theObject, params));

        /*if(pippin.length==0)
        {
            Class [] ring = {};
            method = klass.getMethod(sam[1],ring);
        }
        else if(pippin.length==1)
        {
            gandalf=pippin[0].split(" ");
            if(gandalf[0].equals("int"))
            {Class [] ring = { int.class };
            method = klass.getMethod(sam[1],ring);
            } else if(gandalf[0].equals("String"))
            {
                Class [] ring = { String.class };
            method = klass.getMethod(sam[1],ring);
            } else if(gandalf[0].equals("float"))
            {
                Class [] ring = { float.class };
            method = klass.getMethod(sam[1],ring);
            } else if(gandalf[0].equals("double"))
            {
                Class [] ring = { double.class };
            method = klass.getMethod(sam[1],ring);
            } else if(gandalf[0].equals("boolean"))
            {
                Class [] ring = { boolean.class };
            method = klass.getMethod(sam[1],ring);
            } else if(gandalf[0].equals("char"))
            {
                Class [] ring = { char.class };
            method = klass.getMethod(sam[1],ring);
            }
        } else if(pippin.length==2)
        {
            gandalf=pippin[0].split(" ");
            bilbo=pippin[1].split(" ");
            if(gandalf[0].equals("int")&&bilbo[0].equals("String"))
            {Class [] ring = { int.class, String.class };
            method = klass.getMethod(sam[1],ring);
            } else if(gandalf[0].equals("String")&&bilbo[0].equals("int"))
            {Class [] ring = { String.class, int.class };
            method = klass.getMethod(sam[1],ring);
            } else if(gandalf[0].equals("String")&&bilbo[0].equals("String"))
            {Class [] ring = { String.class, String.class };
            method = klass.getMethod(sam[1],ring);
            }
            else {Class [] ring = { int.class, int.class };
            method = klass.getMethod(sam[1],ring);
            }
        }*/
        //params[0]=3;
        //params[1]=7;
        //sauron=merry.substring(0, (merry.length()-2));
        //sauron+=" }";
        //System.out.println(sauron);

        //Class [] argtypes = { ring };
                
            

        
        //Method method = klass.getMethod(sam[1],ring);
        //System.out.println(method);
        //Object [] passedarg = { params };
        //Object theObject = klass.newInstance();
        //System.out.println(method.invoke(null,sa);



    }






}
