Hello struts-dev,

  I am glad to announce to community my extension of struts -
  bean-factory. It is short description of it below -

  - in struts-config.xml we define bean-factories in such manner

  <bean-factories>
   <!-- Simple factory - creates object only (similar to new) -->
   <factory name="simple" type="org.apache.struts.factory.SimpleBeanFactory"/>
   <!-- JDBC factory - takes SQL query string, parameters and init
        array of beans -->
   <factory name="JDBC" 
            type="org.apache.struts.factory.jdbc.IndexLimitedJDBCBeanFactory"
            mappingClass="org.apache.struts.factory.jdbc.JDBCFactoryMapping"/>
  </bean-factories>
  
  - after that we define bean templates

  <bean-templates>
   <bean name="test" type="com.sv.beans.Test">
    <parameter name="id" type="java.lang.Integer"/>
    <parameter name="name" type="java.lang.String"/>
   </bean>
   <bean name="document" type="com.sv.beans.Document">
    <parameter name="docId" type="java.lang.Integer"/>
   </bean>
   <bean name="docIndex" type="com.sv.beans.Document">
    <parameter name="query" type="java.lang.String" value="SELECT * FROM web.test" 
force="true"/>
   </bean>
   <bean name="docLimIndex" type="com.sv.beans.Document">
    <parameter name="query" type="java.lang.String" value="SELECT * FROM web.test" 
force="true"/>
    <parameter name="start" type="java.lang.Integer" value="0"/>
    <parameter name="length" type="java.lang.Integer" value="10"/>
   </bean>
  </bean-templates>
  
    Each template is bean description with parameters definition.
    Bean-factories uses this information to create appropriate object
    and init some properties or call constructor with described
    parameters.

  - in each action mapping we add bean mappings to define lists of
    beans, which must be created at before call to perform of this
    action. Each bean-mapping defines link from bean-template to
    bean-factory which must be used to create bean instance.

    <action     path="/index"
                type="com.sv.action.ViewAction">
        <bean name="test" factory="simple"/>
        <forward        name="view"             path="/WEB-INF/jsp/index.jsp"/>        
                     
    </action>
    <action    path="/archive"
               type="com.sv.action.ViewAction">
        <bean name="docLimIndex" factory="JDBC" necessary="true"/>
        <forward        name="view"             path="/WEB-INF/jsp/archive.jsp"/>
    </action>

  - extended version of the ActionServlet - BeanFactoryServlet uses
    this information to create beans before call to the perform
    method.
  - with this mechanism we can define one formal action class -
    ViewAction and migrate all predicates to declarations and define
    all bean creations in struts-config.xml
  - and at all - I write bean to store one row, write bean-template
    definition, link it to the JDBC factory in action-mapping section
    and without other problems use this bean in jsp view!

  I need to write some help to use it and make some cosmetic additions
  to the code. After some days I'l be glad to publish this extention
  to community.

-- 
Best regards,
 Oleg                          mailto:[EMAIL PROTECTED]


Reply via email to