private Boolean callMethod(String attributeName, Object parentObj, Map<String, String> values) { if (logger.isTraceEnabled()) { logger.trace( ">>> callMethod attributeName=" + attributeName + ", parentObj=" + parentObj + ", values=" + values); } if (attributeName == null || parentObj == null || values == null) return null; String methodName = values.get(MODIFIER_CALL); if (methodName == null) return null; Object result = null; try { result = MethodUtils.invokeMethod(parentObj, methodName, attributeName); } catch (NoSuchMethodException e) { return null; } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } if (result == null || !(result instanceof Boolean)) { return null; } return (Boolean) result; }
public BufferedImage decodeAsBufferedImage(InputStream input) throws Exception { if (jpegCodecClazz == null) { jpegCodecClazz = Class.forName("com.sun.image.codec.jpeg.JPEGCodec"); } Object decoder = MethodUtils.invokeStaticMethod(jpegCodecClazz, "createJPEGDecoder", input); return (BufferedImage) MethodUtils.invokeMethod(decoder, "decodeAsBufferedImage", null); }
/** * Used for the evaluation of the emptiness in the META SQL fragments. * * @param attributeName the name of the input value * @param obj the input value * @param parentObj the parent of the input value * @param sqlMetaType the internal type (= META type) devoted for the special processing of the * input values * @param inOutModifier the input/output value modifier devoted to extend the processing of the * input/output values * @param inSqlSetOrInsert an indicator the input value is evaluated in the CRUD statement (INSERT * or SET) * @param values values for a special identifier handling, for example a sequence for an identity * @param features the optional features in the statement coontext * @return the non-emptiness of the input value */ protected boolean isNotEmptyInternal( String attributeName, Object obj, Object parentObj, SqlMetaType sqlMetaType, String inOutModifier, boolean inSqlSetOrInsert, Map<String, String> values, Map<String, Object> features) throws IllegalArgumentException { if (MODIFIER_NOTNULL.equalsIgnoreCase(inOutModifier)) { if (obj == null) throw new IllegalArgumentException(MODIFIER_NOTNULL); } if (inSqlSetOrInsert) { boolean isEmptyUseMethodIsNull = false; if (obj == null && attributeName != null && parentObj != null) { Object o = features.get(SqlFeature.EMPTY_USE_METHOD_IS_NULL); if (o != null && o instanceof Boolean && ((Boolean) o)) isEmptyUseMethodIsNull = true; } Object isNullObj = null; if (isEmptyUseMethodIsNull) { try { isNullObj = MethodUtils.invokeMethod(parentObj, "isNull", attributeName); } catch (NoSuchMethodException e) { } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } if (isNullObj != null && isNullObj instanceof Boolean && ((Boolean) isNullObj)) { return true; } boolean isEmptyForNull = isEmptyUseMethodIsNull; if (isEmpty(obj, values)) { Object o = features.get(SqlFeature.EMPTY_FOR_NULL); if (o != null && o instanceof Boolean && ((Boolean) o)) isEmptyForNull = true; if (!isEmptyForNull) return true; } } if (MODIFIER_ANY.equalsIgnoreCase(inOutModifier)) { return true; } else if (MODIFIER_NULL.equalsIgnoreCase(inOutModifier)) { if (obj == null) return true; else return false; } else { return !isEmpty(obj, values); } }
public void invoke(String method) { if (method != null && method.trim().length() > 0) { try { Object o = MethodUtils.invokeMethod(getController(), method, null); if (o != null) { if (o instanceof String) { String p = (String) o; setCurrentPage(p); } } if (getCurrentPage() == null) { setCurrentPage("default"); } } catch (Exception ex) { throw new IllegalStateException(ex.getMessage(), ex); } } }
protected void populateDataFromManager( Object executionClass, WebDropDownListIF methodName, ModelAndView modelview, Map extraParams) throws ApplicationCoreException { StringBuilder methodNameStr = new StringBuilder(); methodNameStr.append(REF_DATA_PREFIX); methodNameStr.append(StringUtil.makeFirstLetterUpperCase(methodName.toString())); Object[] params = {methodName.toString(), modelview, extraParams}; try { Map returnValues = (Map) MethodUtils.invokeMethod(executionClass, methodNameStr.toString(), params); modelview.addObject(methodName.toString(), returnValues); } catch (NoSuchMethodException e) { logger.warn("Invalid method on the web data source during population."); } catch (IllegalAccessException e) { throw new ApplicationCoreException(e); } catch (InvocationTargetException e) { logger.warn("Invalid method on the web data source during population."); } }
/** {@inheritDoc} */ @Override public Requisition deletePath(final String groupName, final String pathToDelete) { m_writeLock.lock(); try { final Requisition group = getProvisioningGroup(groupName); final PropertyPath path = new PropertyPath(pathToDelete); final Object objToDelete = path.getValue(group); final Object parentObject = path.getParent() == null ? group : path.getParent().getValue(group); final String propName = path.getPropertyName(); final String methodSuffix = Character.toUpperCase(propName.charAt(0)) + propName.substring(1); final String methodName = "delete" + methodSuffix; try { MethodUtils.invokeMethod(parentObject, methodName, new Object[] {objToDelete}); } catch (final NoSuchMethodException e) { throw new IllegalArgumentException( "Unable to find method " + methodName + " on object of type " + parentObject.getClass(), e); } catch (final IllegalAccessException e) { throw new IllegalArgumentException("unable to access property " + pathToDelete, e); } catch (final InvocationTargetException e) { throw new IllegalArgumentException("an execption occurred deleting " + pathToDelete, e); } m_pendingForeignSourceRepository.save(group); m_pendingForeignSourceRepository.flush(); return m_pendingForeignSourceRepository.getRequisition(groupName); } finally { m_writeLock.unlock(); } }
/** * Invoke the method. NOTE: MethodUtils doesn't support primitive arguments. e.g) echo(long[] v) */ public static Object invokeMethod(Object obj, String methodName, Object[] arguments) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { return MethodUtils.invokeMethod(obj, methodName, arguments); }