Package java.lang.reflect

Examples of java.lang.reflect.Method


    // use Reflection to invoke the getHostName method.
    Object dirContext = context.getAttribute("org.apache.catalina.resources");
    Class dirContextClass = dirContext.getClass();

    try {
      Method hostMethod = dirContextClass.getMethod("getHostName", null);
      host = (String) hostMethod.invoke(dirContext, null);
    } catch (Exception e) {
      logger.error("[getHostName] Cannot retrieve hostname.", e);
    }

    // if it is null the above method call failed for some reason.
View Full Code Here


      Object ejb = CVUtility.setupEJB(jndiName, remoteClassName, dataSource);
      Class ejbClass = ejb.getClass();
      // iterate the parameters array and get the types to build a Class[] to
      // find the method.
      Class[] methodArgType = CVUtility.getClassArray(parameters);
      Method remoteMethod = ejbClass.getMethod(remoteMethodName, methodArgType);
      // it'd be really cool if this actually works consistently.
      result = remoteMethod.invoke(ejb, parameters);
    } catch (Exception e) {
      // Catch all possible exceptions log and rethrow as a generic exception
      // the struts world should handle this somehow or wrap up in a servlet
      // exception
      // and bubble it up.
View Full Code Here

    try {
      // Get the home object
      Object ejbHome = CVUtility.getHomeObject(remoteClassName, jndiName);
      Class ejbHomeClass = ejbHome.getClass();
      // Call create
      Method homeCreateMethod = ejbHomeClass.getMethod("create", null);
      ejb = homeCreateMethod.invoke(ejbHome, null);
      Class ejbClass = ejb.getClass();
      // set the dataSource
      Class[] setDataSourceArgType = { String.class };
      Method setDataSourceMethod = ejbClass.getMethod("setDataSource", setDataSourceArgType);
      Object[] setDataSourceArg = { dataSource };
      setDataSourceMethod.invoke(ejb, setDataSourceArg);
    } catch (Exception e) {
      throw e;
    }
    return ejb;
  }
View Full Code Here

        }

        Method[] methods = serviceClass.getMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methodName.equals(methods[i].getName())) {
                Method method = methods[i];
                ParamIndices idxs = matchSignature(method, opdef.getInputClassName(), opdef.getOutputClassName());
                if (idxs != null) {
                    return new Operation(opdef, method, idxs);
                }
            }
View Full Code Here

  }

  @Test
  public void testGetSetter() throws Exception
  {
    Method getter = BeanWithGetterValidator.class.getMethod("getProperty");
    Assert.assertEquals(ReflectHelper.getSetter(getter).getName(), "setProperty");
  }
View Full Code Here

  }

  @Test
  public void testCheckSetterMethodName() throws Exception
  {
    Method setter = BeanWithGetterValidator.class.getMethod("setProperty", new Class[]
    {
      String.class
    });
    Assert.assertEquals(ReflectHelper.checkSetterMethodName(setter), "setProperty");
  }
View Full Code Here

  }

  @Test
  public void testCheckInvalidSetterMethodName() throws Exception
  {
    Method setter = BeanWithGetterValidator.class.getMethod("getProperty");

    try
    {
      ReflectHelper.checkSetterMethodName(setter);
    }
View Full Code Here

  @Test
  public void testParameterLength() throws Exception
  {
    Class c = MyClass.class;
    Method method = c.getMethod("methodWithOneParam", new Class[]
    {
      String.class
    });
    ReflectHelper.checkParameterTypeLength(method, 1);
  }
View Full Code Here

  @Test(expectedExceptions=ApplicationRuntimeException.class)
  public void testParameterLength2() throws Exception
  {
    Class c = MyClass.class;
    Method method = c.getMethod("methodWithTwoParams", new Class[]
    {
        String.class, String.class
    });
    ReflectHelper.checkParameterTypeLength(method, 1);
  }
View Full Code Here

  public void testIsGetter() throws SecurityException, NoSuchMethodException
  {
    BindableBean bean = new BindableBean();
    Class<? extends BindableBean> clazz = bean.getClass();

    Method method = clazz.getMethod("isBoolValue");
    assert ReflectHelper.isGetter(method);

    method = clazz.getMethod("getBooleanValue");
    assert ReflectHelper.isGetter(method);
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.