List of usage examples for org.apache.commons.lang3.reflect MethodUtils invokeExactMethod
public static Object invokeExactMethod(final Object object, final String methodName, Object... args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
Invokes a method with no parameters.
This uses reflection to invoke the method obtained from a call to #getAccessibleMethod (Class,String,Class[])}.
From source file:io.github.moosbusch.lumpi.gui.form.editor.validator.spi.AbstractFormValidator.java
@Override public boolean isValid(String input) { Boolean result = Boolean.FALSE; V validator = getValidator();/*from w w w . ja v a 2 s.c o m*/ try { result = (Boolean) MethodUtils.invokeExactMethod(validator, IS_VALID_METHOD_NAME, input); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { Logger.getLogger(AbstractFormValidator.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:io.github.moosbusch.lumpi.gui.form.editor.validator.spi.AbstractFormValidator.java
@Override public T validate(String input) { Object result = null;//w w w. j a v a2 s.co m V validator = getValidator(); try { result = (Boolean) MethodUtils.invokeExactMethod(validator, VALIDATE_METHOD_NAME, input); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { Logger.getLogger(AbstractFormValidator.class.getName()).log(Level.SEVERE, null, ex); } if (result != null) { return (T) result; } return null; }
From source file:net.kamhon.ieagle.util.CollectionUtil.java
/** * This function used to convert particular properties in Object to array. This function mainly used to response * Client in JSON object/* www .j a va2 s.co m*/ * * * @param locale * @param objects * @param propertiesNames * @param isSetNullToEmptyString * @return */ public static Object[][] to2DArrayForStruts(Locale locale, List<?> objects, String[] propertiesNames, boolean isSetNullToEmptyString) { String dateTimeFormat = ""; if (isEmpty(objects)) { return new Object[0][0]; } List<Object[]> result = new ArrayList<Object[]>(); for (Object object : objects) { List<Object> record = new ArrayList<Object>(); for (String propertyName : propertiesNames) { boolean hasResult = false; Object propValue = null; try { propValue = PropertyUtils.getProperty(object, propertyName); processPropertiesForStruts(object, record, propertyName, propValue); hasResult = true; } catch (NestedNullException ex) { // if nested bean referenced is null record.add(""); hasResult = true; } catch (Exception ex) { if (locale == null) throw new DataException(ex); } if (hasResult == false && propValue == null && locale != null) { try { String methodName = "get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); propValue = MethodUtils.invokeExactMethod(object, methodName, locale); processPropertiesForStruts(object, record, propertyName, propValue); } catch (Exception ex) { throw new DataException(ex); } } } result.add(record.toArray(new Object[0])); } return result.toArray(new Object[1][1]); }
From source file:com.norconex.collector.http.url.impl.GenericURLNormalizer.java
@Override public String normalizeURL(String url) { URLNormalizer normalizer = new URLNormalizer(url); for (Normalization n : normalizations) { try {//from www . j a va2 s. co m MethodUtils.invokeExactMethod(normalizer, n.toString(), (Object[]) null); } catch (Exception e) { LOG.error("Could not apply normalization \"" + n + "\".", e); } } String normedURL = normalizer.toString(); for (Replace replace : replaces) { if (replace == null || StringUtils.isBlank(replace.getMatch())) { continue; } String replacement = replace.getReplacement(); if (StringUtils.isBlank(replacement)) { replacement = StringUtils.EMPTY; } normedURL = normedURL.replaceAll(replace.getMatch(), replacement); } return normedURL; }
From source file:ch.sdi.plugins.oxwall.job.OxSqlJob.java
/** * @param dbEntities/* ww w . jav a 2 s . c om*/ * @param aEntity * @throws SdiException */ private void saveEntity(List<Object> dbEntities, Object aEntity) throws SdiException { if (myDryRun) { myLog.trace("DryRun: Going to save entity: " + aEntity); try { MethodUtils.invokeExactMethod(aEntity, "setId", new Object[] { Long.valueOf(myDummyId) }); } catch (Throwable t) { throw new SdiException("Entity has no 'setId( Long )' method", t, SdiException.EXIT_CODE_UNKNOWN_ERROR); } myDummyId++; } else { myLog.trace("Going to save entity: " + aEntity); myEntityManager.persist(aEntity); } // if..else myDryRun dbEntities.add(aEntity); }
From source file:com.norconex.jef4.suite.JobSuite.java
private void fire(List<?> listeners, String methodName, Object argument) { for (Object l : listeners) { try {//w ww . j a v a 2 s . co m MethodUtils.invokeExactMethod(l, methodName, argument); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new JobException("Could not fire event \"" + methodName + "\".", e); } } }
From source file:org.force66.cxfutils.reflect.ReflectUtils.java
public static Object safeInvokeExactMethod(final Object object, final String methodName, Object... args) { try {// ww w . j a v a2s. c o m return MethodUtils.invokeExactMethod(object, methodName, args); } catch (Exception e) { ContextedRuntimeException ce = new ContextedRuntimeException("Error invoking method", e) .addContextValue("methodName", methodName).addContextValue("object", object); if (args != null) { for (int offset = 0; offset < args.length; offset++) { ce.addContextValue("arg " + offset, args[offset]); } } throw ce; } }