List of usage examples for java.lang IllegalAccessException getMessage
public String getMessage()
From source file:com.spectralogic.ds3contractcomparator.print.utils.HtmlRowGeneratorUtils.java
/** * Retrieves the specified property of type {@link ImmutableList} */// w w w . j a v a 2 s. c om public static <T, N> ImmutableList<N> getListPropertyFromObject(final Field field, final T object) { if (object == null) { return ImmutableList.of(); } try { field.setAccessible(true); final Object objectField = field.get(object); if (objectField == null) { return ImmutableList.of(); } if (objectField instanceof ImmutableList) { return (ImmutableList<N>) objectField; } throw new IllegalArgumentException( "Object should be of type ImmutableList, but was: " + object.getClass().toString()); } catch (final IllegalAccessException e) { LOG.error("Could not retrieve list element " + field.getName() + " from object of class " + object.getClass().toString() + ": " + e.getMessage(), e); return ImmutableList.of(); } }
From source file:com.jeysan.modules.utils.reflection.ReflectionUtils.java
/** * ?, private/protected, ??getter./*from ww w . j av a2 s .c o m*/ */ public static Object getFieldValue(final Object obj, final String fieldName) { Object result = null; if (obj instanceof Map) { result = ((Map) obj).get(fieldName); } else { Field field = getAccessibleField(obj, fieldName); if (field == null) { throw new IllegalArgumentException( "Could not find field [" + fieldName + "] on target [" + obj + "]"); } try { result = field.get(obj); } catch (IllegalAccessException e) { logger.error("??{}", e.getMessage()); } } return result; }
From source file:com.xhsoft.framework.common.utils.ReflectionUtils.java
/** * <p>Description:?, private/protected, ??getter.</p> * @param obj/*w ww.j a va2s .com*/ * @param fieldName * @return Object */ public static Object getFieldValue(final Object obj, final String fieldName) { Field field = getAccessibleField(obj, fieldName); if (field == null) { throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]"); } Object result = null; try { result = field.get(obj); } catch (IllegalAccessException e) { logger.error("??{}", e.getMessage()); } return result; }
From source file:com.ekingsoft.core.utils.ReflectionUtils.java
/** * ,private/protected./* w w w . j a v a2 s .co m*/ */ public static Object invokeMethod(final Object object, final String methodName, final Class<?>[] parameterTypes, final Object[] parameters) throws InvocationTargetException { Method method = getDeclaredMethod(object, methodName, parameterTypes); if (method == null) throw new IllegalArgumentException( "Could not find method [" + methodName + "] on target [" + object + "]"); method.setAccessible(true); try { return method.invoke(object, parameters); } catch (IllegalAccessException e) { logger.error("??:{}", e.getMessage()); } return null; }
From source file:com.framework.infrastructure.utils.ReflectionUtils.java
/** * , private/protected, setter./*from w w w . j a va2 s . c om*/ */ public static void setFieldValue(final Object obj, final String fieldName, final Object value) { Field field = getAccessibleField(obj, fieldName); if (field == null) { throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]"); } try { field.set(obj, value); } catch (IllegalAccessException e) { logger.error(":{}", e.getMessage()); } }
From source file:com.framework.infrastructure.utils.ReflectionUtils.java
/** * , private/protected, getter./*from w ww. jav a2 s. c o m*/ */ public static Object getFieldValue(final Object obj, final String fieldName) { Field field = getAccessibleField(obj, fieldName); if (field == null) { throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]"); } Object result = null; try { result = field.get(obj); } catch (IllegalAccessException e) { logger.error("{}", e.getMessage()); } return result; }
From source file:com.zigbee.framework.common.util.BeanCopyUtil.java
/** * Apache Copy Properties//from w w w . j a v a 2s .c o m * @Date : 2011-8-5 * @param srcBean source bean instance * @param destBean destination bean instance * @throws AppException */ public static void beanCopyProperties(Object srcBean, Object destBean) throws AppException { try { org.apache.commons.beanutils.BeanUtils.copyProperties(destBean, srcBean); } catch (IllegalAccessException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception!" + e.getMessage() + e.getStackTrace(); throw new AppException(CommonErrorConstants.BEAN_COPY_EXCEPTION, errMsg, e.getCause()); } catch (InvocationTargetException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception!" + e.getMessage() + e.getStackTrace(); throw new AppException(CommonErrorConstants.BEAN_COPY_EXCEPTION, errMsg, e.getCause()); } }
From source file:com.sammyun.util.SettingUtils.java
/** * /* www .j a va 2 s . co m*/ * * @param setting */ public static void set(Setting setting) { try { File preschoolEduXmlFile = new ClassPathResource(CommonAttributes.PRESCHOOLEDU_XML_PATH).getFile(); Document document = new SAXReader().read(preschoolEduXmlFile); List<Element> elements = document.selectNodes("/preschoolEdu/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (InvocationTargetException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (NoSuchMethodException e) { e.printStackTrace(); logger.error(e.getMessage()); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(preschoolEduXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); } }
From source file:org.grails.datastore.mapping.reflect.ReflectionUtils.java
/** * Instantiates an object catching any relevant exceptions and rethrowing as a runtime exception * * @param clazz The class/*w w w . j a v a 2 s .c om*/ * @return The instantiated object or null if the class parameter was null */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Object instantiate(Class clazz) { if (clazz == null) return null; try { return clazz.getConstructor(EMPTY_CLASS_ARRAY).newInstance(); } catch (IllegalAccessException e) { throw new InstantiationException(e.getClass().getName() + " error creating instance of class [" + e.getMessage() + "]: " + e.getMessage(), e); } catch (InvocationTargetException e) { throw new InstantiationException(e.getClass().getName() + " error creating instance of class [" + e.getMessage() + "]: " + e.getMessage(), e); } catch (NoSuchMethodException e) { throw new InstantiationException(e.getClass().getName() + " error creating instance of class [" + e.getMessage() + "]: " + e.getMessage(), e); } catch (java.lang.InstantiationException e) { throw new InstantiationException(e.getClass().getName() + " error creating instance of class [" + e.getMessage() + "]: " + e.getMessage(), e); } }
From source file:com.xyz.util.ReflectionUtil.java
/** * ,private/protected,??setter.//from w ww. ja va 2 s . c o m */ public static void setFieldValue(final Object object, final String fieldName, final Object value) { Field field = getDeclaredField(object, fieldName); if (field == null) throw new IllegalArgumentException( "Could not find field [" + fieldName + "] on target [" + object + "]"); makeAccessible(field); try { field.set(object, value); } catch (IllegalAccessException e) { logger.error("??:" + e.getMessage()); } }