<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    沉睡森林@漂在北京

    本處文章除注明“轉載”外均為原創,轉載請注明出處。

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      152 隨筆 :: 4 文章 :: 114 評論 :: 0 Trackbacks

     

    今天在使用Digester的時候遇到了一個問題,還沒有找到很好的辦法解決。
        java
    文件如下:
        Digester digester = new Digester();
       digester.setValidating(false);
       digester.addObjectCreate("catalog", Catalog2.class);
       digester.addObjectCreate("catalog/hi/book", Book2.class);
       digester.addBeanPropertySetter("catalog/hi/book/author", "author");
       digester.addBeanPropertySetter("catalog/hi/book/title", "title");
       
       digester.addSetNext("catalog/book", "addBook");
       
       File input = new File("E:\\MyProjects\\Workspace\\DigesterDemo\\src\\com\\example\\demo2\\example.xml");
       
       Catalog2 c = (Catalog2) digester.parse(input);
       System.out.println(c.toString());

        xml
    文件如下:
    <?xml version="1.0"?>
    <catalog  >
     <hi>
      <book>
       <author>Author 1</author>
       <title>Title 1</title>
      </book>
     </hi>
    </catalog>

     

    其中,當我加入了hi節點后,輸出為null,不加入時,可以處理。即加入了hi節點后,books.size = 0

     

    不知道這個問題如何才可以搞定,按照struts的源代碼可以看出,struts-config/action-mappings/action  這里也同樣沒有actionMappings這個對象的實例。

     

    后來,終于在自己的代碼里面找到了問題, digester.addSetNext("catalog/book", "addBook"); 這里的代碼catalog/book中間少了一個hi節點。加上馬上就好了。

     

    但解決上面問題的過程中,我還發現了struts下面的ConfigRuleSet對象。代碼貼出來。

     

    package org.apache.struts.config;

     

    import org.apache.commons.digester.AbstractObjectCreationFactory;

    import org.apache.commons.digester.Digester;

    import org.apache.commons.digester.Rule;

    import org.apache.commons.digester.RuleSetBase;

    import org.apache.struts.util.RequestUtils;

    import org.xml.sax.Attributes;

     

    /**

     * <p>

     * The set of Digester rules required to parse a Struts configuration file (

     * <code>struts-config.xml</code>).

     * </p>

     *

     * @author Craig R. McClanahan

     * @version $Revision: 1.14 $ $Date: 2002/12/21 04:42:20 $

     * @since Struts 1.1

     */

     

    public class ConfigRuleSet extends RuleSetBase {

     

         // --------------------------------------------------------- Public Methods

     

         /**

          * <p>

          * Add the set of Rule instances defined in this RuleSet to the specified

          * <code>Digester</code> instance, associating them with our namespace URI

          * (if any). This method should only be called by a Digester instance. These

          * rules assume that an instance of

          * <code>org.apache.struts.config.ModuleConfig</code> is pushed onto the

          * evaluation stack before parsing begins.

          * </p>

          *

          * @param digester

          *            Digester instance to which the new Rule instances should be

          *            added.

          */

         public void addRuleInstances(Digester digester) {

     

             digester.addObjectCreate("struts-config/data-sources/data-source",

                       "org.apache.struts.config.DataSourceConfig", "className");

             digester.addSetProperties("struts-config/data-sources/data-source");

             digester.addSetNext("struts-config/data-sources/data-source",

                       "addDataSourceConfig",

                       "org.apache.struts.config.DataSourceConfig");

     

             digester.addRule("struts-config/data-sources/data-source/set-property",

                       new AddDataSourcePropertyRule());

     

             digester.addRule("struts-config/action-mappings",

                       new SetActionMappingClassRule());

     

             digester.addFactoryCreate("struts-config/action-mappings/action",

                       new ActionMappingFactory());

             digester.addSetProperties("struts-config/action-mappings/action");

             digester.addSetNext("struts-config/action-mappings/action",

                       "addActionConfig", "org.apache.struts.config.ActionConfig");

     

             digester.addSetProperty(

                       "struts-config/action-mappings/action/set-property",

                       "property", "value");

     

             digester.addObjectCreate(

                       "struts-config/action-mappings/action/exception",

                       "org.apache.struts.config.ExceptionConfig", "className");

             digester

                       .addSetProperties("struts-config/action-mappings/action/exception");

             digester.addSetNext("struts-config/action-mappings/action/exception",

                       "addExceptionConfig",

                       "org.apache.struts.config.ExceptionConfig");

     

             digester.addSetProperty(

                       "struts-config/action-mappings/action/exception/set-property",

                       "property", "value");

     

             digester.addObjectCreate(

                       "struts-config/action-mappings/action/forward",

                       // "org.apache.struts.config.ForwardConfig",

                       "org.apache.struts.action.ActionForward", "className");

             digester

                       .addSetProperties("struts-config/action-mappings/action/forward");

             digester.addSetNext("struts-config/action-mappings/action/forward",

                       "addForwardConfig", "org.apache.struts.config.ForwardConfig");

     

             digester.addSetProperty(

                       "struts-config/action-mappings/action/forward/set-property",

                       "property", "value");

     

             digester.addObjectCreate("struts-config/controller",

                       "org.apache.struts.config.ControllerConfig", "className");

             digester.addSetProperties("struts-config/controller");

             digester.addSetNext("struts-config/controller", "setControllerConfig",

                       "org.apache.struts.config.ControllerConfig");

     

             digester.addSetProperty("struts-config/controller/set-property",

                       "property", "value");

     

             digester.addObjectCreate("struts-config/form-beans/form-bean",

             // "org.apache.struts.config.FormBeanConfig",

                       "org.apache.struts.action.ActionFormBean", "className");

             digester.addSetProperties("struts-config/form-beans/form-bean");

             digester.addSetNext("struts-config/form-beans/form-bean",

                       "addFormBeanConfig", "org.apache.struts.config.FormBeanConfig");

     

             digester.addObjectCreate(

                       "struts-config/form-beans/form-bean/form-property",

                       "org.apache.struts.config.FormPropertyConfig", "className");

             digester

                       .addSetProperties("struts-config/form-beans/form-bean/form-property");

             digester.addSetNext("struts-config/form-beans/form-bean/form-property",

                       "addFormPropertyConfig",

                       "org.apache.struts.config.FormPropertyConfig");

     

             digester

                       .addSetProperty(

                                "struts-config/form-beans/form-bean/form-property/set-property",

                                "property", "value");

     

             digester.addSetProperty(

                       "struts-config/form-beans/form-bean/set-property", "property",

                       "value");

     

             digester.addObjectCreate("struts-config/global-exceptions/exception",

                       "org.apache.struts.config.ExceptionConfig", "className");

             digester.addSetProperties("struts-config/global-exceptions/exception");

             digester.addSetNext("struts-config/global-exceptions/exception",

                       "addExceptionConfig",

                       "org.apache.struts.config.ExceptionConfig");

     

             digester.addSetProperty(

                       "struts-config/global-exceptions/exception/set-property",

                       "property", "value");

     

             digester.addObjectCreate("struts-config/global-forwards/forward",

             // "org.apache.struts.config.ForwardConfig",

                       "org.apache.struts.action.ActionForward", "className");

             digester.addSetProperties("struts-config/global-forwards/forward");

             digester.addSetNext("struts-config/global-forwards/forward",

                       "addForwardConfig", "org.apache.struts.config.ForwardConfig");

     

             digester.addSetProperty(

                       "struts-config/global-forwards/forward/set-property",

                       "property", "value");

     

             digester.addObjectCreate("struts-config/message-resources",

                       "org.apache.struts.config.MessageResourcesConfig", "className");

             digester.addSetProperties("struts-config/message-resources");

             digester.addSetNext("struts-config/message-resources",

                       "addMessageResourcesConfig",

                       "org.apache.struts.config.MessageResourcesConfig");

     

             digester.addSetProperty("struts-config/message-resources/set-property",

                       "property", "value");

     

             digester.addObjectCreate("struts-config/plug-in",

                       "org.apache.struts.config.PlugInConfig");

             digester.addSetProperties("struts-config/plug-in");

             digester.addSetNext("struts-config/plug-in", "addPlugInConfig",

                       "org.apache.struts.config.PlugInConfig");

     

             digester.addRule("struts-config/plug-in/set-property",

                       new PlugInSetPropertyRule());

     

         }

     

    }

     

    /**

     * Class that calls <code>addProperty()</code> for the top object on the stack,

     * which must be a <code>org.apache.struts.config.DataSourceConfig</code>.

     */

     

    final class AddDataSourcePropertyRule extends Rule {

     

         public AddDataSourcePropertyRule() {

             super();

         }

     

         public void begin(Attributes attributes) throws Exception {

             DataSourceConfig dsc = (DataSourceConfig) digester.peek();

             dsc.addProperty(attributes.getValue("property"), attributes

                       .getValue("value"));

         }

     

    }

     

    /**

     * Class that records the name and value of a configuration property to be used

     * in configuring a <code>PlugIn</code> instance when instantiated.

     */

     

    final class PlugInSetPropertyRule extends Rule {

     

         public PlugInSetPropertyRule() {

             super();

         }

     

         public void begin(Attributes attributes) throws Exception {

             PlugInConfig plugInConfig = (PlugInConfig) digester.peek();

             plugInConfig.addProperty(attributes.getValue("property"), attributes

                       .getValue("value"));

         }

     

    }

     

    /**

     * Class that sets the name of the class to use when creating action mapping

     * instances. The value is set on the object on the top of the stack, which must

     * be a <code>org.apache.struts.config.ModuleConfig</code>.

     */

    final class SetActionMappingClassRule extends Rule {

     

         public SetActionMappingClassRule() {

             super();

         }

     

         public void begin(Attributes attributes) throws Exception {

             String className = attributes.getValue("type");

             if (className != null) {

                  ModuleConfig mc = (ModuleConfig) digester.peek();

                  mc.setActionMappingClass(className);

             }

         }

     

    }

     

    /**

     * An object creation factory which creates action mapping instances, taking

     * into account the default class name, which may have been specified on the

     * parent element and which is made available through the object on the top of

     * the stack, which must be a <code>org.apache.struts.config.ModuleConfig</code>

     * .

     */

    final class ActionMappingFactory extends AbstractObjectCreationFactory {

     

         public Object createObject(Attributes attributes) {

     

             // Identify the name of the class to instantiate

             String className = attributes.getValue("className");

             if (className == null) {

                  ModuleConfig mc = (ModuleConfig) digester.peek();

                  className = mc.getActionMappingClass();

             }

     

             // Instantiate the new object and return it

             Object actionMapping = null;

             try {

                  actionMapping = RequestUtils.applicationInstance(className);

             } catch (Exception e) {

                  digester.getLogger()

                           .error("ActionMappingFactory.createObject: ", e);

             }

     

             return actionMapping;

         }

     

    }



    posted on 2008-10-17 18:26 王總兵 閱讀(509) 評論(0)  編輯  收藏 所屬分類: Digester

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲色偷偷综合亚洲AV伊人| 久久中文字幕免费视频| 色偷偷亚洲男人天堂| 亚洲中文无码mv| 亚洲欧美乱色情图片| 亚洲第一区二区快射影院| 亚洲一区二区三区免费视频| 亚洲妇女水蜜桃av网网站| 亚洲国产综合在线| 亚洲人成电影院在线观看| 亚洲成人网在线播放| 亚洲成年人免费网站| 亚洲成人动漫在线观看| 亚洲丝袜中文字幕| 久久精品国产亚洲av麻豆蜜芽| 亚洲午夜国产精品无卡| 亚洲三级视频在线| 亚洲午夜成人精品无码色欲| 亚洲精品无码你懂的| 色窝窝亚洲av网| 国产精品无码永久免费888 | 亚洲精品和日本精品| 国产成人精品亚洲精品| 亚洲精品乱码久久久久久蜜桃不卡| 国产亚洲成AV人片在线观黄桃| 亚洲av综合avav中文| 亚洲va精品中文字幕| 风间由美在线亚洲一区| a在线视频免费观看| 一级毛片在线观看免费| 日韩一区二区a片免费观看 | a毛片免费全部播放完整成| 日本在线看片免费| 黄页网站在线观看免费高清| 国产又粗又猛又爽又黄的免费视频| 亚洲成人影院在线观看| 亚洲VA中文字幕无码毛片 | 亚洲色偷偷狠狠综合网| 久久亚洲精品无码aⅴ大香| 99亚洲精品卡2卡三卡4卡2卡| 亚洲免费在线观看|