Package org.jboss.fresh.shell.commands.cms

Source Code of org.jboss.fresh.shell.commands.cms.ProxyExe

package org.jboss.fresh.shell.commands.cms;

import org.jboss.fresh.io.BufferObjectReader;
import org.jboss.fresh.io.BufferObjectWriter;
import org.jboss.fresh.shell.AbstractExecutable;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ProxyExe extends AbstractExecutable {

  public void process(String exepath, String[] args) throws Exception {

    if (args.length < 2 || helpRequested()) {
      this.usage();
      return;
    }

    Object ret = new Object();

    BufferObjectReader in = new BufferObjectReader(getStdIn());
    BufferObjectWriter out = new BufferObjectWriter(getStdOut());

    Object[] input = (Object[]) in.readObject();

    System.out.println("Input Object[] is: " + String.valueOf(input));

    Object[] cons_params = (Object[]) input[0];
    System.out.println("Constructor params is: " + String.valueOf(cons_params));

    Object[] met_params = (Object[]) input[1];
    System.out.println("Method params is: " + String.valueOf(met_params));

    Class[] types = new Class[cons_params.length];

    for (int i = 0; i < cons_params.length; i++) {
      types[i] = cons_params[i].getClass();
    }

    System.out.println("Types is: " + String.valueOf(types));

    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class c = cl.loadClass(args[0]);
    Constructor con = c.getConstructor(types);
    Object thing = con.newInstance(cons_params);
    Method[] methods = c.getMethods();
    for (int i = 0; i < methods.length; i++) {
      Method m = methods[i];
      System.out.println("Method name: " + m.getName());
      if (m.getName().equals(args[1])) {
        ret = m.invoke(thing, met_params);
        System.out.println("Return Object is: " + String.valueOf(ret));
        break;
      }
    }

    out.writeObject(ret);
  }

  private void usage() {
    System.out.println("Usage: ProxyExe [class] [method] [as stdin an Object[] containing two arrays: params for the constructor and params for the method]");
  }
}
TOP

Related Classes of org.jboss.fresh.shell.commands.cms.ProxyExe

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.