Package java.lang.reflect

Examples of java.lang.reflect.Method


import java.lang.reflect.Method;

public class _ObjectStreamClass {
  public static ObjectStreamClass lookupAny(Class<?> cl) {
    try {
      Method m = ObjectStreamClass.class.getDeclaredMethod("lookup",new Class[] { Class.class, Boolean.TYPE }); //$NON-NLS-1$
      m.setAccessible(true);
      return (ObjectStreamClass) m.invoke(null, new Object[] { cl,Boolean.valueOf(true) });
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here


  }

  private static Object convert(Object instance, Method method, TranslatorProperty prop, boolean needDefaultValue) {
    Class<?> type = method.getReturnType();
    String[] allowedValues = null;
    Method getter = null;
    boolean readOnly = false;
    if (type == Void.TYPE) { //check for setter
      Class<?>[] types = method.getParameterTypes();
      if (types.length != 1) {
        throw new TeiidRuntimeException("TranslatorProperty annotation should be placed on valid getter or setter method, " + method + " is not valid."); //$NON-NLS-1$ //$NON-NLS-2$
      }
      type = types[0];
      try {
        getter = instance.getClass().getMethod("get" + method.getName(), (Class[])null); //$NON-NLS-1$
      } catch (Exception e) {
        try {
          getter = instance.getClass().getMethod("get" + method.getName().substring(3), (Class[])null); //$NON-NLS-1$
        } catch (Exception e1) {
          //can't find getter, won't set the default value
        }
      }
    } else if (method.getParameterTypes().length != 0) {
      throw new TeiidRuntimeException("TranslatorProperty annotation should be placed on valid getter or setter method, " + method + " is not valid."); //$NON-NLS-1$ //$NON-NLS-2$
    } else {
      getter = method;
      try {
        TranslatorUtil.getSetter(instance.getClass(), method);
      } catch (Exception e) {
        readOnly = true;
      }
    }
    Object defaultValue = null;
    if (prop.required()) {
      if (prop.advanced()) {
        throw new TeiidRuntimeException("TranslatorProperty annotation should not both be advanced and required " + method); //$NON-NLS-1$
      }
    } else if (getter != null) {
      try {
        defaultValue = getter.invoke(instance, (Object[])null);
      } catch (Exception e) {
        //no simple default value
      }
    }
    if (type.isEnum()) {
View Full Code Here

        throw new AssertionError("unknown message contents"); //$NON-NLS-1$
      }
      final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)message.getContents();
      final ClientService clientService = this.csr.getClientService(serviceStruct.targetClass.getName());     
      loggingContext = clientService.getLoggingContext();
      Method m = clientService.getReflectionHelper().findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
      Object methodResult;
      try {
        methodResult = m.invoke(clientService.getInstance(), serviceStruct.args);
      } catch (InvocationTargetException e) {
        throw e.getCause();
      }
      if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
        ResultsFuture<Object> future = (ResultsFuture<Object>) methodResult;
        future.addCompletionListener(new ResultsFuture.CompletionListener<Object>() {

              public void onCompletion(
                  ResultsFuture<Object> completedFuture) {
View Full Code Here

            Arg arg = args[i];
            arg.execute();
            parameterTypes[i] = arg.getValueClass();
            parameters[i] = arg.getValue();
        }
        Method method = clazz.getMethod(methodName, parameterTypes);
        returnClass = method.getReturnType();
        try {
            Object obj = method.invoke(object, parameters);
            if (assignment) {
                player.assign(assignVariable, obj);
            }
            return obj;
        } catch (IllegalArgumentException e) {
View Full Code Here

      TranslatorProperty tp = props.get(method);
      String propertyName = getPropertyName(method);
      String value = caseInsensitivProps.remove(propertyName);
     
      if (value != null) {
        Method setterMethod = getSetter(ef.getClass(), method);
        setterMethod.invoke(ef, convert(value, method.getReturnType()));
      } else if (tp.required()) {
        throw new DeploymentException(RuntimePlugin.Util.getString("required_property_not_exists", tp.display())); //$NON-NLS-1$
      }
    }
    caseInsensitivProps.remove(Translator.EXECUTION_FACTORY_CLASS);
View Full Code Here

    this.ctx = ctx;
    this.message = me;
    ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)me.getMessage();

    try {
      Method m = this.clientProxy.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
      try {
        m.invoke(this, serviceStruct.args);
      } catch (InvocationTargetException e) {
        throw e.getCause();
      }   
    } catch (Throwable e) {
      terminate(e);
View Full Code Here

        }
  }

  private void processMessage(ServiceInvocationStruct serviceStruct) {
    try {
      Method m = this.serverProxy.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
      try {
        // since the postgres protocol can produce more than single response
        // objects to a request, all the methods are designed to return void.
        // and relies on client interface to build the responses.
        m.invoke(this.server, serviceStruct.args);
      } catch (InvocationTargetException e) {
        throw e.getCause();
      }   
    } catch (Throwable e) {
      this.client.errorOccurred(e);
View Full Code Here

            Class log4jLevel = Class.forName("org.apache.log4j.Level");
            Class log4jPriority = Class.forName("org.apache.log4j.Priority");
           
            // get static logger method & use to get our logger
            Class[] args = { String.class };
            Method getLogger = log4jLogger.getMethod("getLogger", args);
            Object[] invokeArgs = {clazz};
            logger = getLogger.invoke(null, invokeArgs);
           
            // get the logger's methods and store them
            Class[] plainArgs = {Object.class};
            Class[] throwableArgs = {Object.class,Throwable.class};
            logMethods[Level.FATAL_INT][0] = log4jLogger.getMethod("fatal", plainArgs);
View Full Code Here

            pos = 1;
        }
        args[0] = message;
       
        // retrieve the correct method
        Method method = logMethods[level.getLevel()][pos];
       
        // and invoke the method
        try {
            method.invoke(logger, args);
        }
        catch (Exception ex) { // there's a few, we don't care what they are
            ourLog(Level.ERROR, "Failed to invoke log4j logging method", ex);
            ourLog(level, message, t);
            useLog4j = false;
View Full Code Here

    String result = "\nSynopsis for " + classifier.getClass().getName()
      + ":\n\n";

    for (int i = 0; i < methods.length; i++) {
      String name = methods[i].getDisplayName();
      Method meth = methods[i].getMethod();
      if (name.equals("globalInfo")) {
        String globalInfo = (String)(meth.invoke(classifier, args));
        result += globalInfo;
        break;
      }
    }
View Full Code Here

TOP

Related Classes of java.lang.reflect.Method

Copyright © 2018 www.massapicom. 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.