このコンテンツは選択した言語では利用できません。

1.20. Configuring Bean Contexts


  1. To have the contents of the bean context returned at the end of a Smooks.filterSource process, supply a org.milyn.delivery.java.JavaResult object in the call to the Smooks.filterSource method.

    Example 1.1. 

    // Get the data to filter
    StreamSource source = new StreamSource(getClass().getResourceAsStream("data.xml"));
    
    // Create a Smooks instance (cachable)
    Smooks smooks = new Smooks("smooks-config.xml");
    
    // Create the JavaResult, which will contain the filter result after filtering
    JavaResult result = new JavaResult();
    
    // Filter the data from the source, putting the result into the JavaResult
    smooks.filterSource(source, result);
    
    // Getting the Order bean which was created by the Javabean cartridge
    Order order = (Order)result.getBean("order");
    
  2. To access the bean contexts at start-up, specify this in the BeanContext object. You can retrieve it from the ExecutionContext via the getBeanContext() method.

    Example 1.2. 

    // Create a bean to pass on to the Smooks execution context
    HashMap<String,Object> transformConfig = new HashMap<String,Object>();
    transformConfig.put("Version", new Integer(1));    
    
    // Get the data to filter
    StreamSource source = new StreamSource(getClass().getResourceAsStream("data.xml"));
     
    // Create a Smooks instance (cachable)
    Smooks smooks = new Smooks("smooks-config.xml");
     
    // Create the JavaResult, which will contain the filter result after filtering
    JavaResult result = new JavaResult();
    
    // Add bean to Smooks execution context
    executionContext.getBeanContext().addBean("transformConfig", transformConfig);
    
    // Filter the data from the source, putting the result into the JavaResult
    smooks.filterSource(source, result);
     
    // Getting the Order bean which was created by the JavaBean cartridge
    Order order = (Order)result.getBean("order");
    
  3. When adding or retrieving objects from the BeanContext make sure you first retrieve a beanId object from the beanIdStore. The beanId object is a special key that ensures higher performance than string keys, although string keys are also supported.
  4. You must retrieve the beanIdStore from the ApplicationContext using the getbeanIdStore() method.
  5. To create a beanId object, call the register("beanId name") method. If you know that the beanId is already registered, then you can retrieve it by calling the getbeanId("beanId name") method.
  6. beanId objects are ApplicationContext-scoped objects. Register them in your custom visitor implementation's initialization method and then put them in the visitor object as properties. You can then use them in the visitBefore and visitAfter methods. The beanId objects and the beanIdStore are thread-safe.
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.