/** * Performs the injection. * * @param context * The current valid {@link ExecutionContext} * @throws RuleExecutionException * If injection fails. * @see ExecutionContext Throws: RuleExecutionException if an exception soccurs */ public void execute(ExecutionContext context) throws RuleExecutionException { Object toInject = determineValueToInject(context); try { getInjectee().set(context.getInstance(), toInject); } catch (IllegalAccessException e) { throw new RuleExecutionException("Failed to injected \'" + toInject + "\' to \'" + getInjectee().getName() + "\'", context, e); } }
/** * {@inheritDoc} */ @Override public Object determineValueToInject(ExecutionContext context) throws RuleExecutionException { // Fail fast if value is missing completely and not optional. if (!isOptional() && !context.getSessionParameters().containsKey(getVariableName())) { throw new RuleExecutionException("Non optional session variable \'" + getVariableName() + "\' not available.", context); } // This might return null if a null value is available for a certain key. // Needs to be discussed how to handle this. return context.getSessionParameters().get(getVariableName()); }
/** * Executes the action. Throws: RuleExecutionException in case of any error * * @param context * The current executing {@link ExecutionContext} * @return A collection of {@link Tags}s * @throws RuleExecutionException * If rule execution fails with an exception. * @see ExecutionContext * @see Tag */ public Collection<Tag> execute(ExecutionContext context) throws RuleExecutionException { try { Object result = ReflectionUtils.invokeMethod(getMethod(), context.getInstance()); return transform(result, context); } catch (Exception e) { throw new RuleExecutionException("Failed to invoke action method (" + getMethod().getName() + ")", context, e); } }
values = Iterables.toArray((Iterable<?>) result, Object.class); } else { throw new RuleExecutionException("If resultQuantity is MULTIPLE ensure that either an Array or a Collection is defined as return value", context);
/** * {@inheritDoc} * * @throws RuleExecutionException * If tag injection fails. */ @Override public Object determineValueToInject(ExecutionContext context) throws RuleExecutionException { // extract the required type form the unraveled list of input Tags for (Tag tag : context.getRuleInput().getUnraveled()) { if (tag.getType().equals(getType())) { return InjectionStrategy.BY_VALUE.equals(getInjectionStrategy()) ? tag.getValue() : tag; } } throw new RuleExecutionException("Unable to find Tag: " + getType() + " in RuleInput.", context); }
/** * Executes this {@link ConditionMethod}. If the #method does not succeed a * {@link ConditionFailure} is returned. Otherwise null is returned. * * @param context * The current executing {@link ExecutionContext} * @return A {@link ConditionFailure} if condition fails, null otherwise * @throws RuleExecutionException * If execution of the condition method fails with an exception. * @see ExecutionContext * @see ConditionFailure */ public ConditionFailure execute(ExecutionContext context) throws RuleExecutionException { try { boolean valid = (boolean) ReflectionUtils.invokeMethod(getMethod(), context.getInstance()); if (!valid) { // Store information about the failed condition for later usage return new ConditionFailure(getName(), getHint()); } return null; } catch (Exception e) { throw new RuleExecutionException("Invocation of condition method failed.", context, e); } }