Package org.gap.jseed.util

Source Code of org.gap.jseed.util.FieldExtractor

package org.gap.jseed.util;

import java.lang.reflect.Field;

import org.gap.jseed.NoSuchInvocationHandlerError;

public class FieldExtractor {
  public static Object getPropertyFromField(Object object, String fieldName) {
    Object result = tryGetProperty(object, fieldName);
    return result;
  }

  private static Object tryGetProperty(Object object, String fieldName) throws NoSuchInvocationHandlerError {
    try {
      return getDeclaredFieldPropertyOn(object, fieldName);     
    } catch (SecurityException e) {
      throw new NoSuchInvocationHandlerError("This class does not declare a the invocation " + fieldName, e);
    } catch (NoSuchFieldException e) {
      throw new NoSuchInvocationHandlerError("This class does not declare a the invocation " + fieldName, e);
    } catch (IllegalArgumentException e) {
      throw new NoSuchInvocationHandlerError("This class does not declare a the invocation " + fieldName, e);
    } catch (IllegalAccessException e) {
      throw new NoSuchInvocationHandlerError("This class does not declare a the invocation " + fieldName, e);
    }
  }

  private static Object getDeclaredFieldPropertyOn(Object object, String fieldName)
      throws NoSuchFieldException, IllegalAccessException {
    Field field = object.getClass().getDeclaredField(fieldName);
    field.setAccessible(true);
    return field.get(object);
  }
}
TOP

Related Classes of org.gap.jseed.util.FieldExtractor

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.