List of usage examples for java.lang IllegalAccessException getMessage
public String getMessage()
From source file:org.projectforge.core.AbstractBaseDO.java
/** * //from www. j av a2 s.c o m * @param srcClazz * @param src * @param dest * @param ignoreFields * @return true, if any modifications are detected, otherwise false; */ @SuppressWarnings("unchecked") private static ModificationStatus copyDeclaredFields(final Class<?> srcClazz, final BaseDO<?> src, final BaseDO<?> dest, final String... ignoreFields) { final Field[] fields = srcClazz.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); ModificationStatus modificationStatus = null; for (final Field field : fields) { final String fieldName = field.getName(); if ((ignoreFields != null && ArrayUtils.contains(ignoreFields, fieldName) == true) || accept(field) == false) { continue; } try { final Object srcFieldValue = field.get(src); final Object destFieldValue = field.get(dest); if (field.getType().isPrimitive() == true) { if (ObjectUtils.equals(destFieldValue, srcFieldValue) == false) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } continue; } else if (srcFieldValue == null) { if (field.getType() == String.class) { if (StringUtils.isNotEmpty((String) destFieldValue) == true) { field.set(dest, null); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else if (destFieldValue != null) { field.set(dest, null); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } else { // dest was already null } } else if (srcFieldValue instanceof Collection) { Collection<Object> destColl = (Collection<Object>) destFieldValue; final Collection<Object> srcColl = (Collection<Object>) srcFieldValue; final Collection<Object> toRemove = new ArrayList<Object>(); if (srcColl != null && destColl == null) { if (srcColl instanceof TreeSet) { destColl = new TreeSet<Object>(); } else if (srcColl instanceof HashSet) { destColl = new HashSet<Object>(); } else if (srcColl instanceof List) { destColl = new ArrayList<Object>(); } else if (srcColl instanceof PersistentSet) { destColl = new HashSet<Object>(); } else { log.error("Unsupported collection type: " + srcColl.getClass().getName()); } field.set(dest, destColl); } for (final Object o : destColl) { if (srcColl.contains(o) == false) { toRemove.add(o); } } for (final Object o : toRemove) { if (log.isDebugEnabled() == true) { log.debug("Removing collection entry: " + o); } destColl.remove(o); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } for (final Object srcEntry : srcColl) { if (destColl.contains(srcEntry) == false) { if (log.isDebugEnabled() == true) { log.debug("Adding new collection entry: " + srcEntry); } destColl.add(srcEntry); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } else if (srcEntry instanceof BaseDO) { final PFPersistancyBehavior behavior = field.getAnnotation(PFPersistancyBehavior.class); if (behavior != null && behavior.autoUpdateCollectionEntries() == true) { BaseDO<?> destEntry = null; for (final Object entry : destColl) { if (entry.equals(srcEntry) == true) { destEntry = (BaseDO<?>) entry; break; } } Validate.notNull(destEntry); final ModificationStatus st = destEntry.copyValuesFrom((BaseDO<?>) srcEntry); modificationStatus = getModificationStatus(modificationStatus, st); } } } } else if (srcFieldValue instanceof BaseDO) { final Serializable srcFieldValueId = HibernateUtils.getIdentifier((BaseDO<?>) srcFieldValue); if (srcFieldValueId != null) { if (destFieldValue == null || ObjectUtils.equals(srcFieldValueId, ((BaseDO<?>) destFieldValue).getId()) == false) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else { log.error( "Can't get id though can't copy the BaseDO (see error message above about HHH-3502)."); } } else if (srcFieldValue instanceof java.sql.Date) { if (destFieldValue == null) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } else { final DayHolder srcDay = new DayHolder((Date) srcFieldValue); final DayHolder destDay = new DayHolder((Date) destFieldValue); if (srcDay.isSameDay(destDay) == false) { field.set(dest, srcDay.getSQLDate()); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } } else if (srcFieldValue instanceof Date) { if (destFieldValue == null || ((Date) srcFieldValue).getTime() != ((Date) destFieldValue).getTime()) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else if (srcFieldValue instanceof BigDecimal) { if (destFieldValue == null || ((BigDecimal) srcFieldValue).compareTo((BigDecimal) destFieldValue) != 0) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else if (ObjectUtils.equals(destFieldValue, srcFieldValue) == false) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } catch (final IllegalAccessException ex) { throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); } } final Class<?> superClazz = srcClazz.getSuperclass(); if (superClazz != null) { final ModificationStatus st = copyDeclaredFields(superClazz, src, dest, ignoreFields); modificationStatus = getModificationStatus(modificationStatus, st); } return modificationStatus; }
From source file:org.kuali.ext.mm.ObjectUtil.java
/** * Populate the property of the target object with the counterpart of the source object * * @param targetObject the target object * @param sourceObject the source object * @param property the specified propety of the target object * @param skipReferenceFields determine whether the referencing fields need to be populated */// ww w .jav a 2s. c o m public static void setProperty(Object targetObject, Object sourceObject, DynaProperty property, boolean skipReferenceFields) { String propertyName = property.getName(); try { if (skipReferenceFields) { Class propertyType = property.getType(); if (propertyType == null || PersistableBusinessObjectBase.class.isAssignableFrom(propertyType) || List.class.isAssignableFrom(propertyType)) { return; } } if (PropertyUtils.isReadable(sourceObject, propertyName) && PropertyUtils.isWriteable(targetObject, propertyName)) { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); PropertyUtils.setProperty(targetObject, propertyName, propertyValue); } } catch (IllegalAccessException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (InvocationTargetException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (NoSuchMethodException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (IllegalArgumentException e) { LOG.debug(e.getMessage() + ":" + propertyName); } catch (Exception e) { LOG.debug(e.getMessage() + ":" + propertyName); } }
From source file:com.zc.util.refelect.Reflector.java
/** * ?, private/protected, ??getter./*from w w w . j a va 2s.c o m*/ * * @param target * Object * @param fieldName * ?? * * @return Object */ public static <T> T getFieldValue(final Object target, final String fieldName) { Field field = getAccessibleField(target, fieldName); if (field == null) { throw new IllegalArgumentException( "? [" + fieldName + "] [" + target + "] "); } Object result = null; try { result = field.get(target); } catch (IllegalAccessException e) { logger.error("??{}", e.getMessage()); } return (T) result; }
From source file:com.google.code.simplestuff.bean.SimpleBean.java
/** * // w w w . j a va 2s. c o m * Returns a test object with all the {@link BusinessField} annotated fields * set to a test value. TODO At the moment only the String field are * considered and the collection are not considered. * * @param bean The class of the bean to fill. * @param suffix The suffix to append in the string field. * @return The bean with test values. */ public static <T> T getTestBean(Class<T> beanClass, String suffix) { if (beanClass == null) { throw new IllegalArgumentException("The bean class passed is null!!!"); } T testBean = null; try { testBean = beanClass.newInstance(); } catch (InstantiationException e1) { if (log.isDebugEnabled()) { log.debug(e1.getMessage()); } } catch (IllegalAccessException e1) { if (log.isDebugEnabled()) { log.debug(e1.getMessage()); } } BusinessObjectDescriptor businessObjectInfo = BusinessObjectContext.getBusinessObjectDescriptor(beanClass); // We don't need here a not null check since by contract the // getBusinessObjectDescriptor method always returns an abject. if (businessObjectInfo.getNearestBusinessObjectClass() != null) { Collection<Field> annotatedField = businessObjectInfo.getAnnotatedFields(); for (Field field : annotatedField) { final BusinessField fieldAnnotation = field.getAnnotation(BusinessField.class); if (fieldAnnotation != null) { try { if (field.getType().equals(String.class)) { String stringValue = "test" + StringUtils.capitalize(field.getName()) + (suffix == null ? "" : suffix); PropertyUtils.setProperty(testBean, field.getName(), stringValue); } else if ((field.getType().equals(boolean.class)) || (field.getType().equals(Boolean.class))) { PropertyUtils.setProperty(testBean, field.getName(), true); } else if ((field.getType().equals(int.class)) || (field.getType().equals(Integer.class))) { PropertyUtils.setProperty(testBean, field.getName(), 10); } else if ((field.getType().equals(char.class)) || (field.getType().equals(Character.class))) { PropertyUtils.setProperty(testBean, field.getName(), 't'); } else if ((field.getType().equals(long.class)) || (field.getType().equals(Long.class))) { PropertyUtils.setProperty(testBean, field.getName(), 10L); } else if ((field.getType().equals(float.class)) || (field.getType().equals(Float.class))) { PropertyUtils.setProperty(testBean, field.getName(), 10F); } else if ((field.getType().equals(byte.class)) || (field.getType().equals(Byte.class))) { PropertyUtils.setProperty(testBean, field.getName(), (byte) 10); } else if (field.getType().equals(Date.class)) { PropertyUtils.setProperty(testBean, field.getName(), new Date()); } else if (field.getType().equals(Collection.class)) { // TODO: create a test object of the collection // class specified (if one is specified and // recursively call this method. } } catch (IllegalAccessException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage()); } } catch (InvocationTargetException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage()); } } catch (NoSuchMethodException e) { if (log.isDebugEnabled()) { log.debug(e.getMessage()); } } } } } return testBean; }
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * Prepares composite key as a lucene key. * //from w w w.j a va 2 s.c o m * @param m * entity metadata * @param metaModel * meta model. * @param compositeKey * composite key instance * @return redis key */ public static String prepareCompositeKey(final SingularAttribute attribute, final MetamodelImpl metaModel, final Object compositeKey) { Field[] fields = attribute.getBindableJavaType().getDeclaredFields(); EmbeddableType embeddable = metaModel.embeddable(attribute.getBindableJavaType()); StringBuilder stringBuilder = new StringBuilder(); try { for (Field f : fields) { if (!ReflectUtils.isTransientOrStatic(f)) { if (metaModel.isEmbeddable( ((AbstractAttribute) embeddable.getAttribute(f.getName())).getBindableJavaType())) { f.setAccessible(true); stringBuilder.append( prepareCompositeKey((SingularAttribute) embeddable.getAttribute(f.getName()), metaModel, f.get(compositeKey))) .append(LUCENE_COMPOSITE_KEY_SEPERATOR); } else { String fieldValue = PropertyAccessorHelper.getString(compositeKey, f); fieldValue = fieldValue.replaceAll("[^a-zA-Z0-9]", "_"); stringBuilder.append(fieldValue); stringBuilder.append(LUCENE_COMPOSITE_KEY_SEPERATOR); } } } } catch (IllegalAccessException e) { logger.error(e.getMessage()); } catch (IllegalArgumentException e) { logger.error("Error during prepare composite key, Caused by {}.", e); throw new PersistenceException(e); } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(LUCENE_COMPOSITE_KEY_SEPERATOR)); } return stringBuilder.toString(); }
From source file:org.jaffa.presentation.portlet.CustomRequestProcessor.java
/** * <p>Try to locate a multipart request handler for this request. First, look * for a mapping-specific handler stored for us under an attribute. If one * is not present, use the global multipart handler, if there is one.</p> * * @param request The HTTP request for which the multipart handler should * be found./* ww w . ja v a2s. com*/ * @return the multipart handler to use, or null if none is * found. * * @exception ServletException if any exception is thrown while attempting * to locate the multipart handler. */ private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request) throws ServletException { MultipartRequestHandler multipartHandler = null; String multipartClass = (String) request.getAttribute(Globals.MULTIPART_KEY); request.removeAttribute(Globals.MULTIPART_KEY); // Try to initialize the mapping specific request handler if (multipartClass != null) { try { multipartHandler = (MultipartRequestHandler) RequestUtils.applicationInstance(multipartClass); } catch (ClassNotFoundException cnfe) { log.error("MultipartRequestHandler class \"" + multipartClass + "\" in mapping class not found, " + "defaulting to global multipart class"); } catch (InstantiationException ie) { log.error( "InstantiationException when instantiating " + "MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + ie.getMessage()); } catch (IllegalAccessException iae) { log.error( "IllegalAccessException when instantiating " + "MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + iae.getMessage()); } if (multipartHandler != null) { return multipartHandler; } } ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request); multipartClass = moduleConfig.getControllerConfig().getMultipartClass(); // Try to initialize the global request handler if (multipartClass != null) { try { multipartHandler = (MultipartRequestHandler) RequestUtils.applicationInstance(multipartClass); } catch (ClassNotFoundException cnfe) { throw new ServletException("Cannot find multipart class \"" + multipartClass + "\"" + ", exception: " + cnfe.getMessage()); } catch (InstantiationException ie) { throw new ServletException("InstantiationException when instantiating " + "multipart class \"" + multipartClass + "\", exception: " + ie.getMessage()); } catch (IllegalAccessException iae) { throw new ServletException("IllegalAccessException when instantiating " + "multipart class \"" + multipartClass + "\", exception: " + iae.getMessage()); } if (multipartHandler != null) { return multipartHandler; } } return multipartHandler; }
From source file:org.kuali.kfs.sys.ObjectUtil.java
/** * Populate the property of the target object with the counterpart of the source object * /*from w w w . j av a2s. c om*/ * @param targetObject the target object * @param sourceObject the source object * @param property the specified propety of the target object * @param skipReferenceFields determine whether the referencing fields need to be populated */ public static void setProperty(Object targetObject, Object sourceObject, DynaProperty property, boolean skipReferenceFields) { String propertyName = property.getName(); try { if (skipReferenceFields) { @SuppressWarnings("rawtypes") Class propertyType = property.getType(); if (propertyType == null || PersistableBusinessObjectBase.class.isAssignableFrom(propertyType) || List.class.isAssignableFrom(propertyType)) { return; } } if (PropertyUtils.isReadable(sourceObject, propertyName) && PropertyUtils.isWriteable(targetObject, propertyName)) { Object propertyValue = PropertyUtils.getProperty(sourceObject, propertyName); PropertyUtils.setProperty(targetObject, propertyName, propertyValue); } } catch (IllegalAccessException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (InvocationTargetException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (NoSuchMethodException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (IllegalArgumentException e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage() + ":" + propertyName); } } }
From source file:org.alfresco.traitextender.AJExtender.java
/** * Around advice helper that matches the advised method with its * corresponding extension method, sets up aspectJ call contexts (egg. the * local-proceed context) and delegates to the extension method. * /* ww w . j a v a 2 s. co m*/ * @param thisJoinPoint * @param extensible * @param extendAnnotation * @param extension * @return the result of the extended method */ static Object extendAroundAdvice(JoinPoint thisJoinPoint, Extensible extensible, Extend extendAnnotation, Object extension) { MethodSignature ms = (MethodSignature) thisJoinPoint.getSignature(); Method method = ms.getMethod(); try { ajLocalProceedingJoinPoints.get() .push(new ProceedingContext(extendAnnotation, (ProceedingJoinPoint) thisJoinPoint)); Method extensionMethod = extension.getClass().getMethod(method.getName(), method.getParameterTypes()); if (logger.isDebugEnabled()) { oneTimeLiveLog(AJExtender.logger, new ExtensionRoute(extendAnnotation, method, extensionMethod)); } return extensionMethod.invoke(extension, thisJoinPoint.getArgs()); } catch (IllegalAccessException error) { throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error); } catch (IllegalArgumentException error) { throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error); } catch (InvocationTargetException error) { Throwable targetException = error.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } else { throw new ExtensionTargetException(targetException); } } catch (NoSuchMethodException error) { throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error); } catch (SecurityException error) { throw new InvalidExtension("Ivalid extension : " + error.getMessage(), error); } finally { ajLocalProceedingJoinPoints.get().pop(); } }
From source file:com.nerve.commons.repository.utils.reflection.ReflectionUtils.java
/** * , private/protected, ??setter.//from w ww . ja va2 s . c o m */ 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) { e.printStackTrace(); logger.error("??:{}", e.getMessage()); } }
From source file:BrowserLauncher.java
/** * Called by a static initializer to load any classes, fields, and methods required at runtime * to locate the user's web browser./*from w ww . j a va 2 s .co m*/ * @return <code>true</code> if all intialization succeeded * <code>false</code> if any portion of the initialization failed */ private static boolean loadClasses() { switch (jvm) { case MRJ_2_0: try { Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget"); Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils"); Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent"); Class aeClass = Class.forName("com.apple.MacOS.ae"); aeDescClass = Class.forName("com.apple.MacOS.AEDesc"); aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] { int.class }); appleEventConstructor = appleEventClass.getDeclaredConstructor( new Class[] { int.class, int.class, aeTargetClass, int.class, int.class }); aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] { String.class }); makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] { String.class }); putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] { int.class, aeDescClass }); sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[] {}); Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject"); keyDirectObject = (Integer) keyDirectObjectField.get(null); Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID"); kAutoGenerateReturnID = (Integer) autoGenerateReturnIDField.get(null); Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID"); kAnyTransactionID = (Integer) anyTransactionIDField.get(null); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } catch (NoSuchFieldException nsfe) { errorMessage = nsfe.getMessage(); return false; } catch (IllegalAccessException iae) { errorMessage = iae.getMessage(); return false; } break; case MRJ_2_1: try { mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType"); Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType"); kSystemFolderType = systemFolderField.get(null); findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] { mrjOSTypeClass }); getFileCreator = mrjFileUtilsClass.getDeclaredMethod("getFileCreator", new Class[] { File.class }); getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] { File.class }); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchFieldException nsfe) { errorMessage = nsfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } catch (SecurityException se) { errorMessage = se.getMessage(); return false; } catch (IllegalAccessException iae) { errorMessage = iae.getMessage(); return false; } break; case MRJ_3_0: try { Class linker = Class.forName("com.apple.mrj.jdirect.Linker"); Constructor constructor = linker.getConstructor(new Class[] { Class.class }); linkage = constructor.newInstance(new Object[] { BrowserLauncher.class }); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } catch (InvocationTargetException ite) { errorMessage = ite.getMessage(); return false; } catch (InstantiationException ie) { errorMessage = ie.getMessage(); return false; } catch (IllegalAccessException iae) { errorMessage = iae.getMessage(); return false; } break; case MRJ_3_1: try { mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils"); openURL = mrjFileUtilsClass.getDeclaredMethod("openURL", new Class[] { String.class }); } catch (ClassNotFoundException cnfe) { errorMessage = cnfe.getMessage(); return false; } catch (NoSuchMethodException nsme) { errorMessage = nsme.getMessage(); return false; } break; default: break; } return true; }