public void test_filtering() throws IOException, SAXException {
    Smooks smooks = new Smooks();
    BasicExecutionEventListener eventListener = new BasicExecutionEventListener();

    smooks.addConfigurations("config2.xml", getClass().getResourceAsStream("config2.xml"));
    // Create an exec context - no profiles....
    ExecutionContext executionContext = smooks.createExecutionContext();
    CharArrayWriter outputWriter = new CharArrayWriter();

    // Filter the input message to the outputWriter, using the execution context...
    executionContext.setEventListener(eventListener);
    smooks.filterSource(
        executionContext,
        new StreamSource(getClass().getResourceAsStream("testxml1.xml")),
        new StreamResult(outputWriter));

    log.debug(outputWriter.toString());
    byte[] expected =
        StreamUtils.readStream(getClass().getResourceAsStream("testxml1-expected.xml"));
    assertTrue(
        StreamUtils.compareCharStreams(
            new ByteArrayInputStream(expected),
            new ByteArrayInputStream(outputWriter.toString().getBytes())));
    assertEquals(32, eventListener.getEvents().size());
  }
  @SuppressWarnings("unchecked")
  protected static List runSmooksTransform() throws IOException, SAXException, SmooksException {

    Smooks smooks = new Smooks();

    try {
      // ****
      // And here's the configuration... configuring the CSV reader and
      // the direct
      // binding config to create a List of Person objects
      // (List<Person>)...
      // ****
      smooks.setReaderConfig(
          new CSVReaderConfigurator("firstName,lastName,gender,age,country")
              .setBinding(new CSVBinding("customerList", Customer.class, CSVBindingType.LIST)));

      // Configure the execution context to generate a report...
      ExecutionContext executionContext = smooks.createExecutionContext();
      executionContext.setEventListener(new HtmlReportGenerator("target/report/report.html"));

      JavaResult javaResult = new JavaResult();
      smooks.filterSource(executionContext, new StringSource(messageIn), javaResult);

      return (List) javaResult.getBean("customerList");
    } finally {
      smooks.close();
    }
  }
  public void test_phase_selection() throws IOException, SAXException {
    Smooks smooks = new Smooks();
    ExecutionContext execContext;
    DOMContentDeliveryConfig config;

    smooks.addConfigurations("config1.xml", getClass().getResourceAsStream("config1.xml"));
    execContext = smooks.createExecutionContext();
    config = (DOMContentDeliveryConfig) execContext.getDeliveryConfig();

    // Check the assembly units...
    List<ContentHandlerConfigMap<DOMVisitBefore>> assemblyVBs =
        config.getAssemblyVisitBefores().getMappings("a");
    List<ContentHandlerConfigMap<DOMVisitAfter>> assemblyVAs =
        config.getAssemblyVisitAfters().getMappings("a");
    assertEquals(2, assemblyVBs.size());
    assertTrue(assemblyVBs.get(0).getContentHandler() instanceof AssemblyVisitor1);
    assertTrue(assemblyVBs.get(1).getContentHandler() instanceof ConfigurableVisitor);
    assertEquals(2, assemblyVAs.size());
    assertTrue(assemblyVAs.get(0).getContentHandler() instanceof ConfigurableVisitor);
    assertTrue(assemblyVAs.get(1).getContentHandler() instanceof AssemblyVisitor1);

    List<ContentHandlerConfigMap<DOMVisitBefore>> processingVBs =
        config.getProcessingVisitBefores().getMappings("a");
    List<ContentHandlerConfigMap<DOMVisitAfter>> processingVAs =
        config.getProcessingVisitAfters().getMappings("a");
    assertEquals(2, processingVBs.size());
    assertTrue(processingVBs.get(0).getContentHandler() instanceof ProcessorVisitor1);
    assertTrue(processingVBs.get(1).getContentHandler() instanceof ConfigurableVisitor);
    assertEquals(2, processingVAs.size());
    assertTrue(processingVAs.get(0).getContentHandler() instanceof ConfigurableVisitor);
    assertTrue(processingVAs.get(1).getContentHandler() instanceof ProcessorVisitor1);
  }
 public SmooksSAXFilter(ExecutionContext executionContext) {
   this.executionContext = executionContext;
   closeSource =
       ParameterAccessor.getBoolParameter(
           Filter.CLOSE_SOURCE, true, executionContext.getDeliveryConfig());
   closeResult =
       ParameterAccessor.getBoolParameter(
           Filter.CLOSE_RESULT, true, executionContext.getDeliveryConfig());
   parser = new SAXParser(executionContext);
 }
  private void bindExpressionValue(ExecutionContext executionContext) {
    Map<String, Object> beanMap = executionContext.getBeanContext().getBeanMap();
    Object dataObject = expression.getValue(beanMap);

    if (dataObject instanceof String) {
      populateAndSetPropertyValue((String) dataObject, executionContext);
    } else {
      populateAndSetPropertyValue(dataObject, executionContext);
    }
  }
    private void wireObject(ExecutionContext executionContext) {
      BeanContext beanContext = executionContext.getBeanContext();
      Map<String, Object> beanMap = beanContext.getBeanMap();
      Object key = keyExtractor.getValue(beanMap);

      @SuppressWarnings("unchecked") // TODO: Optimize to use the BeanId object
      Map<Object, Object> map = (Map<Object, Object>) beanContext.getBean(mapBindingKey);
      Object record = beanContext.getBean(RECORD_BEAN);

      map.put(key, record);
    }
  private void bindBeanValue(final ExecutionContext executionContext) {
    final BeanContext beanContext = executionContext.getBeanContext();

    Object bean = beanContext.getBean(wireBeanId);
    if (bean == null) {

      // Register the observer which looks for the creation of the selected bean via its beanIdName.
      // When this observer is triggered then
      // we look if we got something we can set immediately or that we got an array collection. For
      // an array collection we need the array representation
      // and not the list representation. So we register and observer who looks for the change from
      // the list to the array
      BeanRuntimeInfo wiredBeanRI = getWiredBeanRuntimeInfo();
      beanContext.addObserver(new BeanCreateLifecycleObserver(wireBeanId, this, wiredBeanRI));
    } else {
      populateAndSetPropertyValue(bean, executionContext);
    }
  }
  private DataDecoder getDecoder(ExecutionContext executionContext) throws DataDecodeException {
    @SuppressWarnings("unchecked")
    List decoders = executionContext.getDeliveryConfig().getObjects("decoder:" + typeAlias);

    if (decoders == null || decoders.isEmpty()) {
      decoder = DataDecoder.Factory.create(typeAlias);
    } else if (!(decoders.get(0) instanceof DataDecoder)) {
      throw new DataDecodeException(
          "Configured decoder '"
              + typeAlias
              + ":"
              + decoders.get(0).getClass().getName()
              + "' is not an instance of "
              + DataDecoder.class.getName());
    } else {
      decoder = (DataDecoder) decoders.get(0);
    }

    return decoder;
  }