Example usage for java.lang NoSuchFieldException getMessage

List of usage examples for java.lang NoSuchFieldException getMessage

Introduction

In this page you can find the example usage for java.lang NoSuchFieldException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.jtheque.persistence.CachedJDBCDaoTest.java

@Before
public void before() {
    dao = new BasicDao();

    try {/* w w w. ja va2s  .  com*/
        Field f = dao.getClass().getSuperclass().getSuperclass().getDeclaredField("persistenceContext");
        f.setAccessible(true);
        f.set(dao, daoPersistenceContext);
    } catch (NoSuchFieldException e) {
        LoggerFactory.getLogger(ReflectionUtils.class).error(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        LoggerFactory.getLogger(ReflectionUtils.class).error(e.getMessage(), e);
    }
}

From source file:com.madrobot.di.wizard.json.JSONDeserializer.java

/**
 * Deserialize a specific element, recursively.
 * //from w w  w  .j  ava 2  s. co m
 * @param obj
 *            Object whose fields need to be set
 * @param jsonObject
 *            JSON Parser to read data from
 * @param stack
 *            Stack of {@link ClassInfo} - entity type under consideration
 * @throws JSONException
 *             If an exception occurs during parsing
 */
private void deserialize(Object obj, JSONObject jsonObject, Stack<Class<?>> stack) throws JSONException {

    Iterator<?> iterator = jsonObject.keys();
    Class<?> userClass = stack.peek();

    while (iterator.hasNext()) {
        Object jsonKey = iterator.next();

        if (jsonKey instanceof String) {
            String key = (String) jsonKey;
            Object jsonElement = jsonObject.get(key);

            try {

                Field field = getField(userClass, key);
                String fieldName = field.getName();
                Class<?> classType = field.getType();

                if (jsonElement instanceof JSONObject) {
                    if (!Converter.isPseudoPrimitive(classType)) {

                        String setMethodName = getSetMethodName(fieldName, classType);
                        Method setMethod = userClass.getDeclaredMethod(setMethodName, classType);

                        JSONObject fieldObject = (JSONObject) jsonElement;

                        stack.push(classType);
                        Object itemObj = classType.newInstance();
                        deserialize(itemObj, fieldObject, stack);

                        setMethod.invoke(obj, itemObj);
                    } else {
                        Log.e(TAG, "Expecting composite type for " + fieldName);
                    }
                } else if (jsonElement instanceof JSONArray) {
                    if (Converter.isCollectionType(classType)) {
                        if (field.isAnnotationPresent(ItemType.class)) {
                            ItemType itemType = field.getAnnotation(ItemType.class);
                            Class<?> itemValueType = itemType.value();
                            int size = itemType.size();

                            JSONArray fieldArrayObject = (JSONArray) jsonElement;

                            if (size == JSONDeserializer.DEFAULT_ITEM_COLLECTION_SIZE
                                    || size > fieldArrayObject.length()) {
                                size = fieldArrayObject.length();
                            }

                            for (int index = 0; index < size; index++) {
                                Object value = fieldArrayObject.get(index);
                                if (value instanceof JSONObject) {
                                    stack.push(itemValueType);
                                    Object itemObj = itemValueType.newInstance();
                                    deserialize(itemObj, (JSONObject) value, stack);

                                    String addMethodName = getAddMethodName(fieldName);
                                    Method addMethod = userClass.getDeclaredMethod(addMethodName,
                                            itemValueType);
                                    addMethod.invoke(obj, itemObj);
                                }
                            }
                        }
                    } else {
                        Log.e(TAG, "Expecting collection type for " + fieldName);
                    }
                } else if (Converter.isPseudoPrimitive(classType)) {

                    Object value = Converter.convertTo(jsonObject, key, classType, field);

                    String setMethodName = getSetMethodName(fieldName, classType);
                    Method setMethod = userClass.getDeclaredMethod(setMethodName, classType);
                    setMethod.invoke(obj, value);
                } else {
                    Log.e(TAG, "Unknown datatype");
                }

            } catch (NoSuchFieldException e) {
                Log.e(TAG, e.getMessage());
            } catch (NoSuchMethodException e) {
                Log.e(TAG, e.getMessage());
            } catch (IllegalAccessException e) {
                Log.e(TAG, e.getMessage());
            } catch (InvocationTargetException e) {
                Log.e(TAG, e.getMessage());
            } catch (InstantiationException e) {
                Log.e(TAG, e.getMessage());
            }
        }
    }
}

From source file:com.telefonica.iot.cygnus.nodes.CygnusApplication.java

/**
 * Constructor.//from  ww w  . java 2s .  c  o m
 * @param components
 */
public CygnusApplication(List<LifecycleAware> components) {
    super(components);

    try {
        // get a reference to the supervisor, if not possible then Cygnus application cannot start
        getSupervisorRef();
    } catch (NoSuchFieldException e) {
        LOGGER.debug(e.getMessage());
        supervisorRef = null;
    } catch (IllegalAccessException e) {
        LOGGER.debug(e.getMessage());
        supervisorRef = null;
    } // try catch // try catch
}

From source file:se.nrm.dina.data.util.Util.java

public Field getTimestampCreated(Class clazz) {
    logger.info("getTimestampCreated : {} ", clazz);
    try {/*  www . j  a v a 2 s.  c o m*/
        return clazz.getDeclaredField("timestampCreated");
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            return getTimestampCreated(superClass);
        }
    }
}

From source file:se.nrm.dina.data.util.Util.java

/**
 * Checks if the field is an Entity/* www .  j  ava 2  s  .  com*/
 * @param clazz
 * @param fieldName
 * @return boolean
 */
public boolean isEntity(Class clazz, String fieldName) {
    logger.info("isEntity : {} -- {}", clazz, fieldName);
    try {
        return clazz.getDeclaredField(fieldName).getType().getName().contains(ENTITY_PACKAGE);
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            return isEntity(superClass, fieldName);
        }
    }
}

From source file:se.nrm.dina.data.util.Util.java

/**
 * Checks if the field is a java.util.date
 * @param clazz//from w ww.j  a va  2  s.  c o  m
 * @param fieldName
 * @return 
 */
public boolean isDate(Class clazz, String fieldName) {
    logger.info("isDate : {} -- {}", clazz, fieldName);
    try {
        return clazz.getDeclaredField(fieldName).getType().getName().equals("java.util.Date");
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            return isDate(superClass, fieldName);
        }
    }
}

From source file:se.nrm.dina.data.util.Util.java

/**
 * Checks if the field is a java.util.date
 *
 * @param clazz//from   w  w  w  .j a  va 2 s  .c  o  m
 * @param fieldName
 * @return
 */
public boolean isBigDecimal(Class clazz, String fieldName) {
    logger.info("isBigDecimal : {} -- {}", clazz, fieldName);
    try {
        return clazz.getDeclaredField(fieldName).getType().getName().equals("java.math.BigDecimal");
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            return isBigDecimal(superClass, fieldName);
        }
    }
}

From source file:se.nrm.dina.data.util.Util.java

/**
 * Checks if the field is int of Integer
 * @param clazz/*from ww  w  .ja  v a 2s.c  o  m*/
 * @param fieldName
 * @return boolean
 */
public boolean isIntField(Class clazz, String fieldName) {
    //        logger.info("isIntField : {} -- {}", clazz, fieldName); 
    try {
        return clazz.getDeclaredField(fieldName).getType().getName().equals("int")
                || clazz.getDeclaredField(fieldName).getType().getName().equals("java.lang.Integer");
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            return isIntField(superClass, fieldName);
        }
    }
}

From source file:se.nrm.dina.data.util.Util.java

/**
 * Checks if the field is a collection/*from  ww  w .j  a  va2s.  co m*/
 * @param clazz
 * @param fieldName
 * @return 
 */
public boolean isCollection(Class clazz, String fieldName) {
    //        logger.info("isIntField : {} -- {}", clazz, fieldName);
    try {
        return clazz.getDeclaredField(fieldName).getType().getName().equals("java.util.List");
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            //                return validateFields(superClass, fieldName);
            return isCollection(superClass, fieldName);
        }
    }
}

From source file:se.nrm.dina.data.util.Util.java

/**
 * Creates an Entity//from  ww w  .jav a 2s . com
 * @param clazz
 * @param fieldName
 * @return EntityBean
 */
public EntityBean getEntity(Class clazz, String fieldName) {
    logger.info("getEntity : {} -- {}", clazz, fieldName);
    try {
        return createNewInstance(
                convertClassNameToClass(clazz.getDeclaredField(fieldName).getType().getSimpleName()));
    } catch (NoSuchFieldException e) {
        Class superClass = clazz.getSuperclass();
        if (superClass == null) {
            throw new DinaException(e.getMessage());
        } else {
            return getEntity(superClass, fieldName);
        }
    }
}