Exemplo n.º 1
0
 private static Optional<StepFunction> mvel(String source) {
   try {
     final Serializable mvel = MVEL.compileExpression(source);
     MVEL.executeExpression(mvel, ImmutableMap.of("c", 1));
     StepFunction step =
         new StepFunction() {
           public int step(int from) {
             return (Integer) MVEL.executeExpression(mvel, ImmutableMap.of("c", from));
           }
         };
     return Optional.of(step);
   } catch (Exception e) {
     return Optional.absent();
   }
 }
  public Map insertFilter(Source source) {
    JavaResult result = new JavaResult();

    // preserve the previous classloader, While we make Smooks aware of the Drools classloader
    ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread()
        .setContextClassLoader(
            ((InternalRuleBase) this.session.getRuleBase()).getRootClassLoader());

    ExecutionContext executionContext = this.smooks.createExecutionContext();

    // Filter the input message to extract, using the execution context...
    smooks.filter(source, result, executionContext);

    Thread.currentThread().setContextClassLoader(previousClassLoader);

    Map handles = new HashMap<FactHandle, Object>();

    Object object = result.getBean(this.configuration.getRoodId());
    if (object == null) {
      return handles;
    }

    if (this.getterExpr != null) {
      Iterable it = (Iterable) MVEL.executeExpression(this.getterExpr, object);
      if (it != null) {
        for (Object item : it) {
          FactHandle handle = this.session.insert(item);
          handles.put(handle, object);
        }
      }
    } else {
      FactHandle handle = this.session.insert(object);
      handles.put(handle, object);
    }

    return handles;
  }