Package java.lang.reflect

Examples of java.lang.reflect.Method


    try
    {
      BadlyTypedValidatorForm bean = new BadlyTypedValidatorForm();

      Method method = bean.getClass().getMethod("getRequiredInteger");
      MaxLengthValidator validator = new MaxLengthValidator();

      ValidationAnnotationReader reader = new ValidationAnnotationReader();
      reader.checkValidatorType("propertyName", method, validator.getClass(), Validator.class,
          ValidateInteger.class);
View Full Code Here


*/
public abstract class BaseSampleBeanFactory implements BeanFactory {

  protected static void setCreatedByFactoryName(Object target, String name) {
    try {
      Method method = target.getClass().getMethod("setCreatedByFactoryName", new Class[] { String.class });
      method.invoke(target, new Object[] { name });
    } catch (Exception e) {
      // this object is only used for unit testing so do a catch all for ease of use
    }
  }
View Full Code Here

        furnitureLibraryEditorBootstrapClass.getProtectionDomain(),
        extensionJarsAndDlls.toArray(new String [extensionJarsAndDlls.size()]), applicationPackages)
   
    String applicationClassName = "com.eteks.furniturelibraryeditor.FurnitureLibraryEditor";
    Class<?> applicationClass = java3DClassLoader.loadClass(applicationClassName);
    Method applicationClassMain =
        applicationClass.getMethod("main", Array.newInstance(String.class, 0).getClass());
    // Call application class main method with reflection
    applicationClassMain.invoke(null, new Object [] {args});
  }
View Full Code Here

  public void testInitMethod() throws Exception
  {
    LifecycleMethodReader c = new LifecycleMethodReader();
    ActionWithLifecycleMethods actionBean = new ActionWithLifecycleMethods();
    c.readAnnotations(actionBean.getClass());
    final Method initMethod = c.getInitMethod();

    SimpleControllerAction action = new SimpleControllerAction();
    action.setInitMethod(initMethod);

    action.doInitMethod(actionBean);
View Full Code Here

  public void testCloseMethod() throws Exception
  {
    LifecycleMethodReader c = new LifecycleMethodReader();
    ActionWithLifecycleMethods actionBean = new ActionWithLifecycleMethods();
    c.readAnnotations(actionBean.getClass());
    final Method closeMethod = c.getCloseMethod();

    SimpleControllerAction action = new SimpleControllerAction();
    action.setCloseMethod(closeMethod);

    action.doCloseMethod(actionBean);
View Full Code Here

        int idColumn = -1;
        int counter = 0;

        for (String column : firstLine.split(columnSeparator)) {
            column = column.trim();
            Method method = setterMethods.get(column);

            if (method == null)
                continue;

            Class[] params = method.getParameterTypes();
            if (params.length != 1) {
                logger.warn("Setter method " + method.getName() + " should have one parameter!");
                continue;
            }
            Parsing parsing = objParsing.getParsing(params[0]);

            if (parsing == null) {
View Full Code Here

  public Method getMethod(Object actionBean, String methodName)
  {
    synchronized (methods)
    {
      Method method = methods.get(methodName);
      if (method == null)
      {
        method = ReflectHelper.getMethod(actionBean, methodName);
        methods.put(methodName, method);
      }
View Full Code Here

    }

    private Element writeElements(Element element, Object object, String... properties) {
        Map<String, Method> methods = Helper.findGetterMethods(object.getClass());
        for (String property : properties) {
            Method m = methods.get(property);
            try {
                if (m == null)
                    throw new IllegalStateException("No getter found for " + property);

                Object result = m.invoke(object);
                if (result != null) {
                    Writing writing = getWriting(m.getReturnType());
                    if (writing == null)
                        throw new UnsupportedOperationException("No writing found for " + m.getReturnType());

                    element.addElement(property).setText(writing.toString(result));
                }
            } catch (Exception ex) {
                throw new RuntimeException("exception while writing "
View Full Code Here

    private Element readElements(Element rootElement, Object object) {
        Map<String, Method> methods = Helper.findSetterMethods(object.getClass());
        for (Object objectEl : rootElement.elements()) {
            Element element = (Element) objectEl;
            Method m = methods.get(element.getName());
            if (m == null)
                throw new NullPointerException("Cannot find setter for element:" + element.getName());
            try {
                Class setterType = m.getParameterTypes()[0];
                Object result = getResult(object, setterType, element);
                m.invoke(object, result);
            } catch (Exception ex) {
                throw new RuntimeException("Exception while parsing ("
                        + element.getName() + ") to "
                        + object.getClass().getName() + " " + object, ex);
            }
View Full Code Here

        Map<String, Method> setterMapping = new TreeMap();
        fillSettersAndGetters(obj.getClass(), setterMapping, getterMapping);

        getterMapping.keySet().retainAll(setterMapping.keySet());
        for (Entry<String, Method> getter : getterMapping.entrySet()) {
            Method setter = setterMapping.get(getter.getKey());

            // getter object should be castable to setter type:
            if (!setter.getParameterTypes()[0].isAssignableFrom(
                    getter.getValue().getReturnType()))
                continue;

            try {
                Object param = getter.getValue().invoke(obj);

                if (getter.getValue().getReturnType().isArray()) {
                    param = ((Object[]) param).clone();
                } else if (Collection.class.isAssignableFrom(getter.getValue().getReturnType())) {
                    param = new HashSet((Collection) param);
                } else if (Map.class.isAssignableFrom(getter.getValue().getReturnType())) {
                    param = new HashMap((Map) param);
                }

                setter.invoke(newObj, param);
            } catch (Exception ex) {
                logger.fatal("Cannot set:" + getter.getKey(), ex);
            }
        }
    }
View Full Code Here

TOP

Related Classes of java.lang.reflect.Method

Copyright © 2015 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.