org.milyn.container.ExecutionContext.setEventListener()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(15.9k)|赞(0)|评价(0)|浏览(89)

本文整理了Java中org.milyn.container.ExecutionContext.setEventListener()方法的一些代码示例,展示了ExecutionContext.setEventListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExecutionContext.setEventListener()方法的具体详情如下:
包路径:org.milyn.container.ExecutionContext
类名称:ExecutionContext
方法名:setEventListener

ExecutionContext.setEventListener介绍

[英]Set the ExecutionEventListener for the ExecutionContext.

Allows calling code to listen to (and capture data on) specific context execution events e.g. the targeting of resources.

Note, this is not a logging facility and should be used with care. It's overuse should be avoided as it can have a serious negative effect on performance. By default, no listenrs are applied and so no overhead is incured.
[中]为ExecutionContext设置ExecutionEventListener。
允许调用代码侦听(并捕获)特定上下文执行事件的数据,例如资源目标。
注意,这不是日志记录设施,应小心使用。它的过度使用应该避免,因为它会对性能产生严重的负面影响。默认情况下,不应用listenrs,因此不会产生开销。

代码示例

代码示例来源:origin: org.milyn/milyn-smooks-all

private void setupSmooksReporting(final ExecutionContext executionContext)
{
  if (reportPath != null)
  {
    try
    {
      executionContext.setEventListener(new HtmlReportGenerator(reportPath));
    } 
    catch (final IOException e)
    {
      log.info("Could not generate Smooks Report. The reportPath specified was [" + reportPath + "].", e);
    }
  }
}

代码示例来源:origin: org.milyn/milyn-smooks-javabean

public <T> Model<T> readModel(Reader message, Class<T> modelRoot) throws SAXException, IOException {
  AssertArgument.isNotNull(message, "message");
  AssertArgument.isNotNull(modelRoot, "modelRoot");
  JavaResult result = new JavaResult();
  ExecutionContext executionContext = descriptor.getSmooks().createExecutionContext();
  Map<Class<?>, Map<String, BeanWriter>> beanWriters = descriptor.getBeanWriters();
  BeanTracker beanTracker = new BeanTracker(beanWriters);
  if(reportPath != null) {
    executionContext.setEventListener(new HtmlReportGenerator(reportPath));            
  }
  executionContext.getBeanContext().addObserver(beanTracker);
  
  if(validate && descriptor.getSchema() != null) {
    // Validate the message against the schemas...
    Document messageDoc = toDocument(message);
    // Validate the document and then filter it through smooks...
    descriptor.getSchema().newValidator().validate(new DOMSource(messageDoc));
    descriptor.getSmooks().filterSource(executionContext, new DOMSource(messageDoc), result);
  } else {
    descriptor.getSmooks().filterSource(executionContext, new StreamSource(message), result);
  }
  Model<T> model;
  if(modelRoot == JavaResult.class) {
    model = new Model<T>(modelRoot.cast(result), beanTracker.beans, beanWriters, NamespaceReaper.getNamespacePrefixMappings(executionContext));
  } else {
    model = new Model<T>(modelRoot.cast(result.getBean(modelRoot)), beanTracker.beans, beanWriters, NamespaceReaper.getNamespacePrefixMappings(executionContext));
  }
  return model;
}

代码示例来源:origin: smooks/smooks

public <T> Model<T> readModel(Reader message, Class<T> modelRoot) throws SAXException, IOException {
  AssertArgument.isNotNull(message, "message");
  AssertArgument.isNotNull(modelRoot, "modelRoot");
  JavaResult result = new JavaResult();
  ExecutionContext executionContext = descriptor.getSmooks().createExecutionContext();
  Map<Class<?>, Map<String, BeanWriter>> beanWriters = descriptor.getBeanWriters();
  BeanTracker beanTracker = new BeanTracker(beanWriters);
  if(reportPath != null) {
    executionContext.setEventListener(new HtmlReportGenerator(reportPath));            
  }
  executionContext.getBeanContext().addObserver(beanTracker);
  
  if(validate && descriptor.getSchema() != null) {
    // Validate the message against the schemas...
    Document messageDoc = toDocument(message);
    // Validate the document and then filter it through smooks...
    descriptor.getSchema().newValidator().validate(new DOMSource(messageDoc));
    descriptor.getSmooks().filterSource(executionContext, new DOMSource(messageDoc), result);
  } else {
    descriptor.getSmooks().filterSource(executionContext, new StreamSource(message), result);
  }
  Model<T> model;
  if(modelRoot == JavaResult.class) {
    model = new Model<T>(modelRoot.cast(result), beanTracker.beans, beanWriters, NamespaceReaper.getNamespacePrefixMappings(executionContext));
  } else {
    model = new Model<T>(modelRoot.cast(result.getBean(modelRoot)), beanTracker.beans, beanWriters, NamespaceReaper.getNamespacePrefixMappings(executionContext));
  }
  return model;
}

代码示例来源:origin: org.milyn/milyn-smooks-all

public <T> Model<T> readModel(Reader message, Class<T> modelRoot) throws SAXException, IOException {
  AssertArgument.isNotNull(message, "message");
  AssertArgument.isNotNull(modelRoot, "modelRoot");
  JavaResult result = new JavaResult();
  ExecutionContext executionContext = descriptor.getSmooks().createExecutionContext();
  Map<Class<?>, Map<String, BeanWriter>> beanWriters = descriptor.getBeanWriters();
  BeanTracker beanTracker = new BeanTracker(beanWriters);
  if(reportPath != null) {
    executionContext.setEventListener(new HtmlReportGenerator(reportPath));            
  }
  executionContext.getBeanContext().addObserver(beanTracker);
  
  if(validate && descriptor.getSchema() != null) {
    // Validate the message against the schemas...
    Document messageDoc = toDocument(message);
    // Validate the document and then filter it through smooks...
    descriptor.getSchema().newValidator().validate(new DOMSource(messageDoc));
    descriptor.getSmooks().filterSource(executionContext, new DOMSource(messageDoc), result);
  } else {
    descriptor.getSmooks().filterSource(executionContext, new StreamSource(message), result);
  }
  Model<T> model;
  if(modelRoot == JavaResult.class) {
    model = new Model<T>(modelRoot.cast(result), beanTracker.beans, beanWriters, NamespaceReaper.getNamespacePrefixMappings(executionContext));
  } else {
    model = new Model<T>(modelRoot.cast(result.getBean(modelRoot)), beanTracker.beans, beanWriters, NamespaceReaper.getNamespacePrefixMappings(executionContext));
  }
  return model;
}

代码示例来源:origin: org.milyn/milyn-smooks-all

/**
 * Bind the input source to the specified type.
 * <p/>
 * In order to make a cleaner API, implementing classes should create a more
 * appropriately named method based on the target binding format, that just
 * delegates to this method e.g. {@link org.milyn.javabean.binding.xml.XMLBinding#fromXML(javax.xml.transform.Source, Class)}
 * and {@link org.milyn.javabean.binding.xml.XMLBinding#toXML(Object, java.io.Writer)}.
 *
 * @param inputSource The input source.
 * @param toType      The target type.
 * @return The target binding type instance.
 * @throws IOException Error binding source to target type.
 */
protected <T> T bind(Source inputSource, Class<T> toType) throws IOException {
  AssertArgument.isNotNull(inputSource, "inputSource");
  AssertArgument.isNotNull(toType, "toType");
  assertInitialized();
  JavaResult javaResult = new JavaResult();
  ExecutionContext executionContext = smooks.createExecutionContext();
  if (reportPath != null) {
    executionContext.setEventListener(new HtmlReportGenerator(reportPath));
  }
  smooks.filterSource(executionContext, inputSource, javaResult);
  return javaResult.getBean(toType);
}

代码示例来源:origin: smooks/smooks

/**
 * Bind the input source to the specified type.
 * <p/>
 * In order to make a cleaner API, implementing classes should create a more
 * appropriately named method based on the target binding format, that just
 * delegates to this method e.g. {@link org.milyn.javabean.binding.xml.XMLBinding#fromXML(javax.xml.transform.Source, Class)}
 * and {@link org.milyn.javabean.binding.xml.XMLBinding#toXML(Object, java.io.Writer)}.
 *
 * @param inputSource The input source.
 * @param toType      The target type.
 * @return The target binding type instance.
 * @throws IOException Error binding source to target type.
 */
protected <T> T bind(Source inputSource, Class<T> toType) throws IOException {
  AssertArgument.isNotNull(inputSource, "inputSource");
  AssertArgument.isNotNull(toType, "toType");
  assertInitialized();
  JavaResult javaResult = new JavaResult();
  ExecutionContext executionContext = smooks.createExecutionContext();
  if (reportPath != null) {
    executionContext.setEventListener(new HtmlReportGenerator(reportPath));
  }
  smooks.filterSource(executionContext, inputSource, javaResult);
  return javaResult.getBean(toType);
}

代码示例来源:origin: org.milyn/milyn-smooks-javabean

/**
 * Bind the input source to the specified type.
 * <p/>
 * In order to make a cleaner API, implementing classes should create a more
 * appropriately named method based on the target binding format, that just
 * delegates to this method e.g. {@link org.milyn.javabean.binding.xml.XMLBinding#fromXML(javax.xml.transform.Source, Class)}
 * and {@link org.milyn.javabean.binding.xml.XMLBinding#toXML(Object, java.io.Writer)}.
 *
 * @param inputSource The input source.
 * @param toType      The target type.
 * @return The target binding type instance.
 * @throws IOException Error binding source to target type.
 */
protected <T> T bind(Source inputSource, Class<T> toType) throws IOException {
  AssertArgument.isNotNull(inputSource, "inputSource");
  AssertArgument.isNotNull(toType, "toType");
  assertInitialized();
  JavaResult javaResult = new JavaResult();
  ExecutionContext executionContext = smooks.createExecutionContext();
  if (reportPath != null) {
    executionContext.setEventListener(new HtmlReportGenerator(reportPath));
  }
  smooks.filterSource(executionContext, inputSource, javaResult);
  return javaResult.getBean(toType);
}

代码示例来源:origin: smooks/smooks

public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException {
  Smooks smooks = getSmooksInstance();
  ExecutionContext nestedExecutionContext = smooks.createExecutionContext();
  // In case there's an attached event listener...
  nestedExecutionContext.setEventListener(executionContext.getEventListener());
  // Copy over the XMLReader stack...
  AbstractParser.setReaders(AbstractParser.getReaders(executionContext), nestedExecutionContext);
  // Attach the NamespaceDeclarationStack to the nested execution context...
  NamespaceDeclarationStack nsStack = NamespaceMappings.getNamespaceDeclarationStack(executionContext);
  NamespaceMappings.setNamespaceDeclarationStack(nsStack, nestedExecutionContext);
  SmooksContentHandler parentContentHandler = SmooksContentHandler.getHandler(executionContext);
  if(parentContentHandler.getNestedContentHandler() != null) {
    throw new SmooksException("Illegal use of more than one nested content handler fired on the same element.");
  }
  SmooksContentHandler nestedContentHandler = new SAXHandler(nestedExecutionContext, element.getWriter(this), parentContentHandler);
  DynamicSAXElementVisitorList.propogateDynamicVisitors(executionContext, nestedExecutionContext);
  // Attach the XMLReader instance to the nested ExecutionContext and then swap the content handler on
  // the XMLReader to be the nested handler created here.  All events wll be forwarded to the ..
  XMLReader xmlReader = AbstractParser.getXMLReader(executionContext);
  AbstractParser.attachXMLReader(xmlReader, nestedExecutionContext);
  xmlReader.setContentHandler(nestedContentHandler);
  executionContext.setAttribute(NestedExecutionVisitor.class, nestedExecutionContext);
  // Note we do not execute the Smooks filterSource methods for a nested instance... we just install
  // the content handler and redirect the reader events to it...
}

代码示例来源:origin: org.virtuslab/milyn-smooks-core

public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException {
  Smooks smooks = getSmooksInstance();
  ExecutionContext nestedExecutionContext = smooks.createExecutionContext();
  // In case there's an attached event listener...
  nestedExecutionContext.setEventListener(executionContext.getEventListener());
  // Copy over the XMLReader stack...
  AbstractParser.setReaders(AbstractParser.getReaders(executionContext), nestedExecutionContext);
  // Attach the NamespaceDeclarationStack to the nested execution context...
  NamespaceDeclarationStack nsStack = NamespaceMappings.getNamespaceDeclarationStack(executionContext);
  NamespaceMappings.setNamespaceDeclarationStack(nsStack, nestedExecutionContext);
  SmooksContentHandler parentContentHandler = SmooksContentHandler.getHandler(executionContext);
  if(parentContentHandler.getNestedContentHandler() != null) {
    throw new SmooksException("Illegal use of more than one nested content handler fired on the same element.");
  }
  SmooksContentHandler nestedContentHandler = new SAXHandler(nestedExecutionContext, element.getWriter(this), parentContentHandler);
  DynamicSAXElementVisitorList.propogateDynamicVisitors(executionContext, nestedExecutionContext);
  // Attach the XMLReader instance to the nested ExecutionContext and then swap the content handler on
  // the XMLReader to be the nested handler created here.  All events wll be forwarded to the ..
  XMLReader xmlReader = AbstractParser.getXMLReader(executionContext);
  AbstractParser.attachXMLReader(xmlReader, nestedExecutionContext);
  xmlReader.setContentHandler(nestedContentHandler);
  executionContext.setAttribute(NestedExecutionVisitor.class, nestedExecutionContext);
  // Note we do not execute the Smooks filterSource methods for a nested instance... we just install
  // the content handler and redirect the reader events to it...
}

代码示例来源:origin: org.milyn/milyn-smooks-core

public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException {
  Smooks smooks = getSmooksInstance();
  ExecutionContext nestedExecutionContext = smooks.createExecutionContext();
  // In case there's an attached event listener...
  nestedExecutionContext.setEventListener(executionContext.getEventListener());
  // Copy over the XMLReader stack...
  AbstractParser.setReaders(AbstractParser.getReaders(executionContext), nestedExecutionContext);
  // Attach the NamespaceDeclarationStack to the nested execution context...
  NamespaceDeclarationStack nsStack = NamespaceMappings.getNamespaceDeclarationStack(executionContext);
  NamespaceMappings.setNamespaceDeclarationStack(nsStack, nestedExecutionContext);
  SmooksContentHandler parentContentHandler = SmooksContentHandler.getHandler(executionContext);
  if(parentContentHandler.getNestedContentHandler() != null) {
    throw new SmooksException("Illegal use of more than one nested content handler fired on the same element.");
  }
  SmooksContentHandler nestedContentHandler = new SAXHandler(nestedExecutionContext, element.getWriter(this), parentContentHandler);
  DynamicSAXElementVisitorList.propogateDynamicVisitors(executionContext, nestedExecutionContext);
  // Attach the XMLReader instance to the nested ExecutionContext and then swap the content handler on
  // the XMLReader to be the nested handler created here.  All events wll be forwarded to the ..
  XMLReader xmlReader = AbstractParser.getXMLReader(executionContext);
  AbstractParser.attachXMLReader(xmlReader, nestedExecutionContext);
  xmlReader.setContentHandler(nestedContentHandler);
  executionContext.setAttribute(NestedExecutionVisitor.class, nestedExecutionContext);
  // Note we do not execute the Smooks filterSource methods for a nested instance... we just install
  // the content handler and redirect the reader events to it...
}

代码示例来源:origin: org.milyn/milyn-smooks-all

public void visitBefore(SAXElement element, ExecutionContext executionContext) throws SmooksException, IOException {
  Smooks smooks = getSmooksInstance();
  ExecutionContext nestedExecutionContext = smooks.createExecutionContext();
  // In case there's an attached event listener...
  nestedExecutionContext.setEventListener(executionContext.getEventListener());
  // Copy over the XMLReader stack...
  AbstractParser.setReaders(AbstractParser.getReaders(executionContext), nestedExecutionContext);
  // Attach the NamespaceDeclarationStack to the nested execution context...
  NamespaceDeclarationStack nsStack = NamespaceMappings.getNamespaceDeclarationStack(executionContext);
  NamespaceMappings.setNamespaceDeclarationStack(nsStack, nestedExecutionContext);
  SmooksContentHandler parentContentHandler = SmooksContentHandler.getHandler(executionContext);
  if(parentContentHandler.getNestedContentHandler() != null) {
    throw new SmooksException("Illegal use of more than one nested content handler fired on the same element.");
  }
  SmooksContentHandler nestedContentHandler = new SAXHandler(nestedExecutionContext, element.getWriter(this), parentContentHandler);
  DynamicSAXElementVisitorList.propogateDynamicVisitors(executionContext, nestedExecutionContext);
  // Attach the XMLReader instance to the nested ExecutionContext and then swap the content handler on
  // the XMLReader to be the nested handler created here.  All events wll be forwarded to the ..
  XMLReader xmlReader = AbstractParser.getXMLReader(executionContext);
  AbstractParser.attachXMLReader(xmlReader, nestedExecutionContext);
  xmlReader.setContentHandler(nestedContentHandler);
  executionContext.setAttribute(NestedExecutionVisitor.class, nestedExecutionContext);
  // Note we do not execute the Smooks filterSource methods for a nested instance... we just install
  // the content handler and redirect the reader events to it...
}

相关文章