List of usage examples for org.apache.commons.beanutils MethodUtils invokeExactMethod
public static Object invokeExactMethod(Object object, String methodName, Object[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
Invoke a method whose parameter types match exactly the object types.
This uses reflection to invoke the method obtained from a call to #getAccessibleMethod .
From source file:com.googlecode.wicketwebbeans.model.BeanMetaData.java
/** * Invokes an annotation method to get a value, possibly returning null if no value or if the method doesn't exist. *///from ww w .ja v a2 s. com private Object invokeAnnotationMethod(Annotation annotation, String methodName) { try { return MethodUtils.invokeExactMethod(annotation, methodName, null); } catch (Exception e) { // Ignore. return null; } }
From source file:org.apache.struts.upload.MultipartRequestWrapper.java
/** * Convenience method which uses reflection to invoke a method * on the Request.// w w w . j a va 2s . c om */ private Object invokeRequestMethod(String name, Object[] args) { try { return MethodUtils.invokeExactMethod(request, name, args); } catch (NoSuchMethodException e) { if (log.isDebugEnabled()) { log.debug("Method '" + name + "' not defined for javax.servlet.http.HttpServletRequest"); } } catch (InvocationTargetException e) { log.error("Error invoking method '" + name + "' ", e.getTargetException()); } catch (IllegalAccessException e) { log.error("Error invoking method '" + name + "' ", e); } return null; }
From source file:org.diffkit.diff.conf.DKTestBridge.java
public static void loadTestCaseData(File testcaseDir_) throws Exception { Object testCaseRunner = getTestCaseRunner(null, null); MethodUtils.invokeExactMethod(testCaseRunner, "setupDB", new Object[] { testcaseDir_, DKDBFlavor.H2 }); }
From source file:org.extremecomponents.table.view.html.CalcBuilder.java
public void defaultCalcLayout() { Column calcColumn = model.getColumnHandler().getFirstCalcColumn(); if (calcColumn == null) { return;/*w w w .j a v a2s.c o m*/ } String layout = model.getPreferences().getPreference(PreferencesConstants.DEFAULT_CALC_LAYOUT); try { MethodUtils.invokeExactMethod(this, layout, null); } catch (Exception e) { logger.error("There is no method with the layout [" + layout + "].", e); } }
From source file:org.kuali.rice.krad.bo.ModuleConfiguration.java
/** * This method is deprecated and won't do anything if the database repository file paths are null or empty. * * We use reflection here to avoid having to reference PersistenceService directly since it may or may not be on * our classpath depending on whether or not KSB is in use. *//*www . j a v a2s.c om*/ @Deprecated protected void loadOjbRepositoryFiles() { String persistenceServiceOjbName = "persistenceServiceOjb"; if (getDatabaseRepositoryFilePaths() != null) { for (String repositoryLocation : getDatabaseRepositoryFilePaths()) { // Need the OJB persistence service because it is the only one ever using the database repository files if (getPersistenceService() == null) { setPersistenceService(GlobalResourceLoader.getService(persistenceServiceOjbName)); } if (persistenceService == null) { setPersistenceService(applicationContext.getBean(persistenceServiceOjbName)); } LOG.warn("Loading OJB Configuration in " + getNamespaceCode() + " module. OJB is deprecated as of Rice 2.4: " + repositoryLocation); try { MethodUtils.invokeExactMethod(persistenceService, "loadRepositoryDescriptor", repositoryLocation); } catch (Exception e) { throw new RuntimeException(e); } } } }
From source file:org.molasdin.wbase.ReflectionHelper.java
public static Object functionValue(String name, Object object) { try {/*from w w w. jav a2 s . c o m*/ return MethodUtils.invokeExactMethod(object, name, new Object[0]); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.mule.module.fws.api.FwsPaginatedIterable.java
@Override protected final boolean hasNextPage(Page page) { try {/*from w w w . j a va 2s .c o m*/ return (Boolean) MethodUtils.invokeExactMethod(page, "isHasNext", EMPTY); } catch (Exception e) { throw new AssertionError(e); } }
From source file:org.neuro4j.studio.core.util.ParameterDefinitionLoader.java
private ParameterDefinitionList getParameterDefinitionListAnnotation(Class<?> aClass) { Annotation[] ans = aClass.getAnnotations(); for (Annotation an : ans) { if (an.annotationType().toString().endsWith("ParameterDefinitionList")) { final Object obj = aClass.getAnnotation(an.annotationType()); ParameterDefinitionList list = new ParameterDefinitionList() { @Override/* w w w. j a v a 2s.c om*/ public Class<? extends Annotation> annotationType() { return org.neuro4j.workflow.common.ParameterDefinitionList.class; } @Override public ParameterDefinition[] input() { Object[] parameterDefArray = null; try { parameterDefArray = (Object[]) MethodUtils.invokeExactMethod(obj, "input", null); if (parameterDefArray == null) { return EMPTY; } } catch (Exception e) { e.printStackTrace(); return EMPTY; } List<ParameterDefinition> list = new ArrayList<ParameterDefinition>(5); for (Object ob : parameterDefArray) { try { ParameterDefinition pd1 = getParameterDefinition(ob); list.add(pd1); } catch (Exception e) { e.printStackTrace(); return EMPTY; } } return list.toArray(new ParameterDefinition[list.size()]); } @Override public ParameterDefinition[] output() { Object[] parameterDefArray = null; try { parameterDefArray = (Object[]) MethodUtils.invokeExactMethod(obj, "output", null); if (parameterDefArray == null) { return EMPTY; } } catch (Exception e) { e.printStackTrace(); return EMPTY; } List<ParameterDefinition> list = new ArrayList<ParameterDefinition>(5); for (Object ob : parameterDefArray) { try { ParameterDefinition pd1 = getParameterDefinition(ob); list.add(pd1); } catch (Exception e) { e.printStackTrace(); return EMPTY; } } return list.toArray(new ParameterDefinition[list.size()]); } }; try { } catch (Exception e) { e.printStackTrace(); } return list; } } return null; }
From source file:org.neuro4j.studio.core.util.ParameterDefinitionLoader.java
private final ParameterDefinition getParameterDefinition(Object obj) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { final String name = (String) MethodUtils.invokeExactMethod(obj, "name", null); if (name == null || "".equals(name.trim())) { return null; }/*w w w. j a v a 2 s.c o m*/ final String type = (String) MethodUtils.invokeExactMethod(obj, "type", null); final Boolean isOptional = (Boolean) MethodUtils.invokeExactMethod(obj, "isOptional", null); ParameterDefinition pd = new ParameterDefinition() { @Override public Class<? extends Annotation> annotationType() { return org.neuro4j.workflow.common.ParameterDefinition.class; } @Override public String type() { return type; } @Override public String name() { return name; } @Override public boolean isOptional() { return isOptional; } }; return pd; }
From source file:org.openmrs.OrderTest.java
protected static void assertThatAllFieldsAreCopied(Order original, String methodName, String... otherfieldsToExclude) throws Exception { if (methodName == null) { methodName = "copy"; }//from w w w . j a v a 2 s .c o m List<String> fieldsToExclude = new ArrayList<String>(); fieldsToExclude.addAll(Arrays.asList("log", "serialVersionUID", "orderId", "uuid")); if (otherfieldsToExclude != null) { fieldsToExclude.addAll(Arrays.asList(otherfieldsToExclude)); } List<Field> fields = Reflect.getAllFields(original.getClass()); for (Field field : fields) { if (fieldsToExclude.contains(field.getName())) { continue; } field.setAccessible(true); Object fieldValue = field.get(original); if (fieldValue == null) { if (field.getType().isEnum()) { fieldValue = field.getType().getEnumConstants()[0]; } else if (field.getType().equals(Boolean.class)) { fieldValue = true; } else if (field.getType().equals(Integer.class)) { fieldValue = 10; } else if (field.getType().equals(Double.class)) { fieldValue = 5.0; } else { fieldValue = field.getType().newInstance(); } field.set(original, fieldValue); } } Order copy = (Order) MethodUtils.invokeExactMethod(original, methodName, null); for (Field field : fields) { Object copyValue = field.get(copy); if (fieldsToExclude.contains(field.getName())) { continue; } assertNotNull("Order." + methodName + " should set " + field.getName() + " on the new Order", copyValue); assertEquals("Order." + methodName + " should set " + field.getName() + " on the new Order", field.get(original), copyValue); } }