List of usage examples for java.lang IllegalAccessException getMessage
public String getMessage()
From source file:org.jaffa.soa.dataaccess.TransformerUtils.java
/** * Pass in an empty map and it fills it with Key = Value for the source * object. It returns false if one or more key values are null, or if this * object has no keys defined//from w w w. j a va 2 s.co m */ static boolean fillInKeys(String path, GraphDataObject source, GraphMapping mapping, Map map) throws InvocationTargetException, TransformException { try { Set keys = mapping.getKeyFields(); boolean nullKey = false; if (keys == null || keys.size() == 0) { if (log.isDebugEnabled()) log.debug("Object Has No KEYS! - " + source.getClass().getName()); return false; } // Loop through all the keys get het the values for (Iterator k = keys.iterator(); k.hasNext();) { String keyField = (String) k.next(); PropertyDescriptor pd = mapping.getDataFieldDescriptor(keyField); if (pd != null && pd.getReadMethod() != null) { Method m = pd.getReadMethod(); if (!m.isAccessible()) m.setAccessible(true); Object value = m.invoke(source, new Object[] {}); map.put(keyField, value); if (log.isDebugEnabled()) log.debug("Key " + keyField + "='" + value + "' on object '" + source.getClass().getName() + '\''); if (value == null) { nullKey = true; } } else { TransformException me = new TransformException(TransformException.NO_KEY_ON_OBJECT, path, keyField, source.getClass().getName()); log.error(me.getLocalizedMessage()); throw me; } } return !nullKey; } catch (IllegalAccessException e) { TransformException me = new TransformException(TransformException.ACCESS_ERROR, path, e.getMessage()); log.error(me.getLocalizedMessage(), e); throw me; // } catch (InvocationTargetException e) { // TransformException me = new TransformException(TransformException.INVOCATION_ERROR, path, e ); // log.error(me.getLocalizedMessage(),me.getCause()); // throw me; } }
From source file:com.sm.query.PredicateVisitorImpl.java
@Override public Result visitObjectField(@NotNull PredicateParser.ObjectFieldContext ctx) { //first is object, second is field Pair<Object, FieldInfo> pair = findObjectId(ctx.getText(), source, classInfoMap); idMap.put(ctx.getText(), pair.getSecond()); try {//from w w w . j av a 2 s. c o m if (pair.getFirst() == null) return new Result(null); else { Object object = pair.getSecond().getField().get(pair.getFirst()); return new Result(object); } } catch (IllegalAccessException e) { throw new ObjectIdException(e.getMessage(), e); } }
From source file:org.jaffa.soa.dataaccess.TransformerUtils.java
/** * Display the properties of this JavaBean in XML format. * * @param source Javabean who's contents should be printed * @return XML formatted string of this beans properties and their values *///w ww .j a va 2 s.c o m public static String printXMLGraph(Object source) { StringBuffer out = new StringBuffer(); out.append("<" + source.getClass().getSimpleName() + ">"); try { BeanInfo sInfo = Introspector.getBeanInfo(source.getClass()); PropertyDescriptor[] sDescriptors = sInfo.getPropertyDescriptors(); if (sDescriptors != null && sDescriptors.length != 0) { for (int i = 0; i < sDescriptors.length; i++) { PropertyDescriptor sDesc = sDescriptors[i]; Method sm = sDesc.getReadMethod(); if (sm != null && sDesc.getWriteMethod() != null) { if (!sm.isAccessible()) sm.setAccessible(true); Object sValue = sm.invoke(source, (Object[]) null); out.append("<" + sDesc.getName() + ">"); if (sValue != null && !sm.getReturnType().isArray() && !GraphDataObject.class.isAssignableFrom(sValue.getClass())) { out.append(sValue.toString().trim()); } out.append("</" + sDesc.getName() + ">"); } } } } catch (IllegalAccessException e) { TransformException me = new TransformException(TransformException.ACCESS_ERROR, "???", e.getMessage()); log.error(me.getLocalizedMessage(), e); //throw me; } catch (InvocationTargetException e) { TransformException me = new TransformException(TransformException.INVOCATION_ERROR, "???", e); log.error(me.getLocalizedMessage(), me.getCause()); //throw me; } catch (IntrospectionException e) { TransformException me = new TransformException(TransformException.INTROSPECT_ERROR, "???", e.getMessage()); log.error(me.getLocalizedMessage(), e); //throw me; } out.append("</" + source.getClass().getSimpleName() + ">"); return out.toString(); }
From source file:com.krawler.common.notification.handlers.NotificationExtractorManager.java
public void replacePlaceholders(StringBuffer htmlMsg, NotificationRequest notificationReqObj, User recipientUser, DateFormat df) { try {/* w ww . j av a2s .co m*/ // e.g // First Type of placeholder => #reftype1:oppmainowner.firstName# // Second Type of placeholder => #reftype1:oppname# java.lang.reflect.Method objMethod; String expr = "[#]{1}[a-zA-Z0-9]+[:]{1}[a-zA-Z0-9]+(\\.){0,1}[a-zA-Z0-9]*[#]{1}"; Pattern p = Pattern.compile(expr); Matcher m = p.matcher(htmlMsg); while (m.find()) { String table = m.group(); String woHash = table.substring(1, table.length() - 1); String[] sp = woHash.split(":"); if (!StringUtil.isNullOrEmpty(sp[0])) { // sp[0] having reftype1 which holds placeholder class path Class cl = notificationReqObj.getClass(); String methodStr = sp[0].substring(0, 1).toUpperCase() + sp[0].substring(1); // Make first letter of operand capital. String methodGetIdStr = methodStr.replace("type", "id"); objMethod = cl.getMethod("get" + methodStr + ""); // Gets the value of the operand String classPath = (String) objMethod.invoke(notificationReqObj); objMethod = cl.getMethod("get" + methodGetIdStr + ""); //refid1 which holds placeholder class object primary id String classObjectId = (String) objMethod.invoke(notificationReqObj); // Placeholder Class String value = "-"; Object invoker = commonTablesDAOObj.getObject(classPath, classObjectId); // load placeholder class Class placeHolderClass = invoker.getClass(); String[] operator = sp[1].split("\\."); // if (operator.length > 1) { // if having oppmainowner.firstName methodStr = operator[0].substring(0, 1).toUpperCase() + operator[0].substring(1); // Make first letter of operand capital. objMethod = placeHolderClass.getMethod("get" + methodStr + ""); Object innerClassObject = objMethod.invoke(invoker); // get oppmainowner object if (!StringUtil.isNullObject(innerClassObject)) { placeHolderClass = innerClassObject.getClass(); methodStr = operator[1].substring(0, 1).toUpperCase() + operator[1].substring(1); // Make first letter of operand capital. objMethod = placeHolderClass.getMethod("get" + methodStr + "");// get oppmainowner's firstName field value = String.valueOf(objMethod.invoke(innerClassObject)); } } else if (operator.length == 1) { // if having oppname methodStr = operator[0].substring(0, 1).toUpperCase() + operator[0].substring(1); // Make first letter of operand capital. objMethod = placeHolderClass.getMethod("get" + methodStr + ""); java.util.Date.class.isAssignableFrom(objMethod.getReturnType()); if (java.util.Date.class.isAssignableFrom(objMethod.getReturnType())) value = df.format(((java.util.Date) objMethod.invoke(invoker))); else if ((methodStr.equals("Startdate") && java.lang.Long.class.isAssignableFrom(objMethod.getReturnType())) || (methodStr.equals("Enddate") && java.lang.Long.class.isAssignableFrom(objMethod.getReturnType()))) { value = df.format(new java.util.Date((java.lang.Long) objMethod.invoke(invoker))); } else value = String.valueOf(objMethod.invoke(invoker)); } else { value = table.replaceAll("#", "@~@~"); } int i1 = htmlMsg.indexOf(table); int i2 = htmlMsg.indexOf(table) + table.length(); if (StringUtil.isNullOrEmpty(value)) { value = ""; } if (i1 >= 0) { htmlMsg.replace(i1, i2, value); } } m = p.matcher(htmlMsg); } // replace receiver placeholders expr = "[$]{1}recipient[:]{1}[a-zA-Z0-9]+(\\.){0,1}[a-zA-Z0-9]*[$]{1}"; //$recipient:firstName$ $recipient:lastName$ p = Pattern.compile(expr); m = p.matcher(htmlMsg); while (m.find()) { String table = m.group(); String woHash = table.substring(1, table.length() - 1); String[] sp = woHash.split(":"); String value = "-"; if (!StringUtil.isNullOrEmpty(sp[0])) { // sp[0] having recipient which holds placeholder class path Class placeHolderClass = recipientUser.getClass(); String[] operator = sp[1].split("\\."); if (operator.length > 1) { // if having oppmainowner.firstName String methodStr = operator[0].substring(0, 1).toUpperCase() + operator[0].substring(1); // Make first letter of operand capital. objMethod = placeHolderClass.getMethod("get" + methodStr + ""); Object innerClassObject = objMethod.invoke(recipientUser); // get oppmainowner object if (!StringUtil.isNullObject(innerClassObject)) { placeHolderClass = innerClassObject.getClass(); methodStr = operator[1].substring(0, 1).toUpperCase() + operator[1].substring(1); // Make first letter of operand capital. objMethod = placeHolderClass.getMethod("get" + methodStr + "");// get oppmainowner's firstName field value = (String) objMethod.invoke(innerClassObject); } } else if (operator.length == 1) { // if having oppname String methodStr = operator[0].substring(0, 1).toUpperCase() + operator[0].substring(1); // Make first letter of operand capital. objMethod = placeHolderClass.getMethod("get" + methodStr + ""); java.util.Date.class.isAssignableFrom(objMethod.getReturnType()); if (java.util.Date.class.isAssignableFrom(objMethod.getReturnType())) value = df.format(((java.util.Date) objMethod.invoke(recipientUser))); else value = (String) objMethod.invoke(recipientUser); } else { value = table.replaceAll("$", "@~@~"); } int i1 = htmlMsg.indexOf(table); int i2 = htmlMsg.indexOf(table) + table.length(); if (StringUtil.isNullOrEmpty(value)) { value = ""; } if (i1 >= 0) { htmlMsg.replace(i1, i2, value); } } m = p.matcher(htmlMsg); } } catch (IllegalAccessException ex) { LOG.info(ex.getMessage(), ex); ex.printStackTrace(); } catch (IllegalArgumentException ex) { LOG.info(ex.getMessage(), ex); ex.printStackTrace(); } catch (InvocationTargetException ex) { LOG.info(ex.getMessage(), ex); ex.printStackTrace(); } catch (NoSuchMethodException ex) { LOG.info(ex.getMessage(), ex); ex.printStackTrace(); } catch (ServiceException ex) { LOG.info(ex.getMessage(), ex); ex.printStackTrace(); } }
From source file:org.apache.chemistry.opencmis.server.shared.Dispatcher.java
/** * Find the appropriate method an call it. * * @return//from ww w . j a v a 2 s . c o m * <code>true</code> if the method was found, * <code>false</code> otherwise. */ public boolean dispatch(String resource, String httpMethod, CallContext context, CmisService service, String repositoryId, HttpServletRequest request, HttpServletResponse response) { Method m = methodMap.get(getKey(resource, httpMethod)); if (m == null) { return false; } if (LOG.isDebugEnabled()) { LOG.debug(repositoryId + " / " + resource + ", " + httpMethod + " -> " + m.getName()); } try { m.invoke(null, context, service, repositoryId, request, response); } catch (IllegalAccessException e) { throw new CmisRuntimeException("Internal error!", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof CmisBaseException) { throw (CmisBaseException) e.getCause(); } else { throw new CmisRuntimeException(e.getMessage(), e); } } return true; }
From source file:com.taobao.android.builder.tasks.awo.AwoPackageConfigAction.java
/** * ??task/*from w w w . j a v a 2 s . c o m*/ * * @param packageApp * @param fieldName * @param value */ private void setFieldValueByReflection(PackageApplication packageApp, String fieldName, Object value) { Field field = FieldUtils.getField(packageApp.getClass(), fieldName, true); if (null == field) { throw new StopExecutionException("The field with name:" + fieldName + " does not existed in class:" + packageApp.getClass().getName()); } try { FieldUtils.writeField(field, packageApp, value, true); } catch (IllegalAccessException e) { throw new StopExecutionException(e.getMessage()); } }
From source file:io.haze.core.ServiceFactory.java
/** * Retrieve a class instance from the configuration file. * * @param configuration The configuration. * @param namespace The configuration namespace. * @param clazz The expected class type. * @param defaultValue The default value. * * @throws FactoryException If the class is invalid, the class cannot be found, the class cannot be cast to the * expected type, the constructor could not be called, or the constructor threw an * exception./*from w w w.ja v a2 s .c o m*/ */ protected <T> T getClassElementInstance(XMLConfiguration configuration, String namespace, Class<T> clazz, String defaultValue) throws FactoryException { Class<T> result = null; try { result = getClassElement(configuration, namespace, clazz, defaultValue); return result.newInstance(); } catch (IllegalAccessException e) { throw new FactoryException( String.format("%s class '%s' constructor is inaccessible", namespace, result.getName())); } catch (InstantiationException e) { if (e.getMessage() == null) { throw new FactoryException( String.format("%s class '%s' has no suitable constructor, " + "or is an abstract class", namespace, result.getName())); } throw new FactoryException(String.format("%s class '%s' constructor threw an exception: %s", namespace, result.getName(), e.getMessage())); } }
From source file:com.intuit.tank.PropertyComparer.java
/** * @{inheritDoc//ww w. jav a2 s.co m */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public int compare(T src, T tgt) { int retVal = 0; if (src == null && tgt == null) { retVal = 0; } else if (src != null && tgt == null) { retVal = 1; } else if (src == null && tgt != null) { retVal = -1; } else { try { Object property = PropertyUtils.getProperty(src, propertyName); Object property2 = PropertyUtils.getProperty(tgt, propertyName); if (property == null && property2 == null) { retVal = 0; } else if (property == null && property2 != null) { retVal = -1; } else if (property != null && property2 == null) { retVal = 1; } else if (Comparable.class.isAssignableFrom(property.getClass())) { Comparable c1 = (Comparable) property; Comparable c2 = (Comparable) property2; retVal = c1.compareTo(c2); } else { retVal = property.toString().compareTo(property2.toString()); } } catch (IllegalAccessException e) { throw new RuntimeException( "Cannot access the method. Possible error in setting the access type for the getter setters of " + propertyName); } catch (InvocationTargetException e) { throw new RuntimeException(e.getMessage()); } catch (NoSuchMethodException e) { throw new RuntimeException("No getter/setter method found for " + propertyName); } } if (sortOrder == SortOrder.DESCENDING) { retVal = retVal * -1; } return retVal; }
From source file:org.opennms.features.reporting.repository.local.LegacyLocalReportRepository.java
/** * {@inheritDoc}//from w ww . j a v a2 s . co m */ @Override public List<BasicReportDefinition> getReports() { List<BasicReportDefinition> resultList = new ArrayList<BasicReportDefinition>(); for (BasicReportDefinition report : m_localReportsDao.getReports()) { BasicReportDefinition resultReport = new LegacyLocalReportDefinition(); try { BeanUtils.copyProperties(resultReport, report); resultReport.setId(REPOSITORY_ID + "_" + report.getId()); // Community reports are allowed by default, no permission restriction resultReport.setAllowAccess(true); } catch (IllegalAccessException e) { logger.error("IllegalAccessException during BeanUtils.copyProperties for BasicReportDefinion '{}'", e.getMessage()); e.printStackTrace(); } catch (InvocationTargetException e) { logger.error( "InvocationTargetException during BeanUtils.copyProperties for BasicReportDefinion '{}'", e.getMessage()); e.printStackTrace(); } resultList.add(resultReport); } return resultList; }
From source file:org.opennms.features.reporting.repository.local.LegacyLocalReportRepository.java
/** * {@inheritDoc}//from w w w .j a v a 2 s . c o m */ @Override public List<BasicReportDefinition> getOnlineReports() { List<BasicReportDefinition> resultList = new ArrayList<BasicReportDefinition>(); for (BasicReportDefinition report : m_localReportsDao.getOnlineReports()) { BasicReportDefinition resultReport = new LegacyLocalReportDefinition(); try { BeanUtils.copyProperties(resultReport, report); resultReport.setId(REPOSITORY_ID + "_" + report.getId()); // Community reports are allowed by default, no permission restriction resultReport.setAllowAccess(true); } catch (IllegalAccessException e) { logger.error("IllegalAccessException during BeanUtils.copyProperties for BasicReportDefinion '{}'", e.getMessage()); e.printStackTrace(); } catch (InvocationTargetException e) { logger.error( "InvocationTargetException during BeanUtils.copyProperties for BasicReportDefinion '{}'", e.getMessage()); e.printStackTrace(); } resultList.add(resultReport); } return resultList; }