List of usage examples for java.lang.reflect InvocationTargetException getTargetException
public Throwable getTargetException()
From source file:org.kaleidofoundry.spring.context.BeanContextPostProcessor.java
@Override public Object postProcessBeforeInitialization(final Object beanInstance, final String beanName) throws BeansException { Set<Field> fields = ReflectionHelper.getAllDeclaredFields(beanInstance.getClass()); for (Field field : fields) { // @Autowired is injected using spring bean if (field.isAnnotationPresent(Context.class) && !field.isAnnotationPresent(Autowired.class) && !field.isAnnotationPresent(Inject.class)) { final Context context = field.getAnnotation(Context.class); // do field is a runtime context class if (field.getType().isAssignableFrom(RuntimeContext.class)) { ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, beanInstance, RuntimeContext.createFrom(context, field.getName(), field.getDeclaringClass())); }//from w w w . j ava 2 s .c om // does the plugin interface have a provider specify else if (field.getType().isAnnotationPresent(Provider.class)) { try { ReflectionUtils.makeAccessible(field); Object fieldValue = field.get(beanInstance); if (fieldValue == null) { // create provider using annotation meta-information final Provider provideInfo = field.getType().getAnnotation(Provider.class); final Constructor<? extends ProviderService<?>> providerConstructor = provideInfo .value().getConstructor(Class.class); final ProviderService<?> fieldProviderInstance = providerConstructor .newInstance(field.getType()); // invoke provides method with Context annotation meta-informations final Method providesMethod = ReflectionUtils.findMethod(provideInfo.value(), ProviderService.PROVIDES_METHOD, Context.class, String.class, Class.class); // get the provider result fieldValue = ReflectionUtils.invokeMethod(providesMethod, fieldProviderInstance, context, field.getName(), field.getType()); // set the field that was not yet injected ReflectionUtils.setField(field, beanInstance, fieldValue); } } catch (IllegalArgumentException e) { throw new BeanCreationException("Unexpected error during injection", e); } catch (IllegalAccessException e) { throw new BeanCreationException("Unexpected error during injection", e); } catch (SecurityException e) { throw new BeanCreationException("Unexpected error during injection", e); } catch (NoSuchMethodException e) { throw new BeanCreationException("Unexpected error during injection", e); } catch (InstantiationException e) { throw new BeanCreationException("Unexpected error during injection", e); } catch (InvocationTargetException ite) { throw new BeanCreationException("", ite.getCause() != null ? ite.getCause() : (ite.getTargetException() != null ? ite.getTargetException() : ite)); } finally { } } } } return beanInstance; }
From source file:com.espertech.esper.core.context.mgr.ContextControllerHashedGetterSingleRow.java
public Object get(EventBean eventBean) throws PropertyAccessException { EventBean[] events = new EventBean[] { eventBean }; Object[] parameters = new Object[evaluators.length]; for (int i = 0; i < evaluators.length; i++) { parameters[i] = evaluators[i].evaluate(events, true, null); }/*from w w w . jav a 2s . c o m*/ try { Object result = fastMethod.invoke(null, parameters); if (result == null) { return 0; } int value = ((Number) result).intValue(); if (value >= 0) { return value % granularity; } return -value % granularity; } catch (InvocationTargetException e) { String message = JavaClassHelper.getMessageInvocationTarget(statementName, fastMethod.getJavaMethod(), fastMethod.getDeclaringClass().getName(), parameters, e); log.error(message, e.getTargetException()); } return 0; }
From source file:com.espertech.esper.epl.expression.dot.ExprDotMethodEvalDuck.java
public Object evaluate(Object target, EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext) { if (target == null) { return null; }/*from w w w . java2 s . c o m*/ FastMethod method; if (cache.containsKey(target.getClass())) { method = cache.get(target.getClass()); } else { method = getFastMethod(target.getClass()); cache.put(target.getClass(), method); } if (method == null) { return null; } Object[] args = new Object[parameters.length]; for (int i = 0; i < args.length; i++) { args[i] = parameters[i].evaluate(eventsPerStream, isNewData, exprEvaluatorContext); } try { return method.invoke(target, args); } catch (InvocationTargetException e) { String message = JavaClassHelper.getMessageInvocationTarget(statementName, method.getJavaMethod(), target.getClass().getName(), args, e); log.error(message, e.getTargetException()); } return null; }
From source file:com.espertech.esper.epl.core.MethodPollingExecStrategyBase.java
private List<EventBean> invokeInternal(Object[] lookupValues, Object invocationTarget) { try {//from w w w . ja va 2s . c o m Object invocationResult = method.invoke(invocationTarget, lookupValues); if (invocationResult != null) { return handleResult(invocationResult); } return null; } catch (InvocationTargetException ex) { throw new EPException("Method '" + method.getName() + "' of class '" + method.getJavaMethod().getDeclaringClass().getName() + "' reported an exception: " + ex.getTargetException(), ex.getTargetException()); } }
From source file:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java
public void updateCellEditor() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (propertyTable.getColumnModel().getColumnCount() > 0) { final TableColumn propertyNameColumn = propertyTable.getColumnModel().getColumn(0); propertySelectionComboBox = new JComboBox(); boolean isJNDI = false; try {/*from www .j ava2 s.com*/ Map properties = BeanUtils.describe(bean); log.debug("bean= " + properties); for (Iterator iter = propertyTableModel.getValidProperties().iterator(); iter.hasNext();) { String name = (String) iter.next(); propertySelectionComboBox.addItem(name); } } catch (InvocationTargetException e) { cat.error(e.getTargetException().getMessage(), e.getTargetException()); } propertyNameColumn.setCellEditor(new DefaultCellEditor(propertySelectionComboBox)); } }
From source file:com.espertech.esper.epl.expression.dot.ExprDotEvalStaticMethod.java
public Object get(EventBean eventBean) throws PropertyAccessException { Object[] args = new Object[childEvals.length]; for (int i = 0; i < args.length; i++) { args[i] = childEvals[i].evaluate(new EventBean[] { eventBean }, false, null); }// ww w . ja v a 2 s. c om // The method is static so the object it is invoked on // can be null try { return staticMethod.invoke(targetObject, args); } catch (InvocationTargetException e) { String message = JavaClassHelper.getMessageInvocationTarget(statementName, staticMethod.getJavaMethod(), classOrPropertyName, args, e); log.error(message, e.getTargetException()); if (rethrowExceptions) { throw new EPException(message, e.getTargetException()); } } return null; }
From source file:com.espertech.esper.epl.expression.ExprDotEvalStaticMethod.java
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext) { if ((isConstantParameters) && (isCachedResult)) { return cachedResult; }//w w w . ja va2s. co m Object[] args = new Object[childEvals.length]; for (int i = 0; i < args.length; i++) { args[i] = childEvals[i].evaluate(eventsPerStream, isNewData, exprEvaluatorContext); } // The method is static so the object it is invoked on // can be null try { Object result = staticMethod.invoke(targetObject, args); if (resultWrapLambda != null) { result = resultWrapLambda.convert(result); } for (int i = 0; i < chainEval.length; i++) { result = chainEval[i].evaluate(result, eventsPerStream, isNewData, exprEvaluatorContext); if (result == null) { return result; } } if (isConstantParameters) { cachedResult = result; isCachedResult = true; } return result; } catch (InvocationTargetException e) { String message = JavaClassHelper.getMessageInvocationTarget(statementName, staticMethod.getJavaMethod(), classOrPropertyName, args, e); log.error(message, e.getTargetException()); if (rethrowExceptions) { throw new EPException(message, e.getTargetException()); } } return null; }
From source file:com.espertech.esper.event.bean.EventBeanManufacturerBean.java
private void handle(InvocationTargetException ex, String methodName) { String message = "Unexpected exception encountered invoking setter-method '" + methodName + "' on class '" + beanEventType.getUnderlyingType().getName() + "' : " + ex.getTargetException().getMessage(); log.error(message, ex);//from ww w.j a v a 2s . co m }
From source file:com.espertech.esper.epl.expression.dot.ExprDotEvalStaticMethod.java
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qExprPlugInSingleRow(staticMethod.getJavaMethod()); }// w w w . j a v a 2 s.co m if ((isConstantParameters) && (isCachedResult)) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aExprPlugInSingleRow(cachedResult); } return cachedResult; } Object[] args = new Object[childEvals.length]; for (int i = 0; i < args.length; i++) { args[i] = childEvals[i].evaluate(eventsPerStream, isNewData, exprEvaluatorContext); } // The method is static so the object it is invoked on // can be null try { Object result = staticMethod.invoke(targetObject, args); result = ExprDotNodeUtility.evaluateChainWithWrap(resultWrapLambda, result, null, staticMethod.getReturnType(), chainEval, eventsPerStream, isNewData, exprEvaluatorContext); if (isConstantParameters) { cachedResult = result; isCachedResult = true; } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aExprPlugInSingleRow(result); } return result; } catch (InvocationTargetException e) { String message = JavaClassHelper.getMessageInvocationTarget(statementName, staticMethod.getJavaMethod(), classOrPropertyName, args, e); log.error(message, e.getTargetException()); if (rethrowExceptions) { throw new EPException(message, e.getTargetException()); } } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aExprPlugInSingleRow(null); } return null; }
From source file:com.espertech.esper.epl.core.MethodPollingExecStrategy.java
public List<EventBean> poll(Object[] lookupValues) { List<EventBean> rowResult = null; try {// ww w .j a v a2 s. c o m Object invocationResult = method.invoke(null, lookupValues); if (invocationResult != null) { if (isArray) { int length = Array.getLength(invocationResult); if (length > 0) { rowResult = new ArrayList<EventBean>(); for (int i = 0; i < length; i++) { Object value = Array.get(invocationResult, i); if (value == null) { log.warn("Expected non-null return result from method '" + method.getName() + "', but received null value"); continue; } EventBean theEvent; if (useMapType) { if (!(value instanceof Map)) { log.warn("Expected Map-type return result from method '" + method.getName() + "', but received type '" + value.getClass() + "'"); continue; } Map mapValues = (Map) value; theEvent = eventAdapterService.adapterForTypedMap(mapValues, eventType); } else { theEvent = eventAdapterService.adapterForBean(value); } rowResult.add(theEvent); } } } else { rowResult = new LinkedList<EventBean>(); EventBean theEvent; if (useMapType) { if (!(invocationResult instanceof Map)) { log.warn("Expected Map-type return result from method '" + method.getName() + "', but received type '" + invocationResult.getClass() + "'"); } else { Map mapValues = (Map) invocationResult; theEvent = eventAdapterService.adapterForTypedMap(mapValues, eventType); rowResult.add(theEvent); } } else { theEvent = eventAdapterService.adapterForBean(invocationResult); rowResult.add(theEvent); } } } } catch (InvocationTargetException ex) { throw new EPException("Method '" + method.getName() + "' of class '" + method.getJavaMethod().getDeclaringClass().getName() + "' reported an exception: " + ex.getTargetException(), ex.getTargetException()); } return rowResult; }