• Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • 4.0M5
    • None
    • Général
    • None
    • Operating System: Windows XP
      Platform: PC

      voir doc yabon

          [RUNTIME-97] Helper pour saxer des bean

          C'est souvent que l'on code un générateur spécifique qui récupère un bean ou un collection de beans (depuis un DAO)
          et que l'on se tappe à la mimine le toSAX de cette structure.

          Il pourrait donc être intéressant d'avoir ce genre de Generator abstrait avec le comportement par défaut qui représente 99% des cas mais toujours la possibilité de modifier un petit comportement :

          /**
           * {@link ServiceableGenerator} extension for SAXing a bean.<p>
           * The bean is retrieve from {@link #getObject()} and is SAXed using
           * JavaBean properties by default.<br>
           * This behaviour can be changed by implementing the right <code>sax*</code> methods.
           */
          public class AbstractBeanGenerator<T> extends ServiceableGenerator
          {
            public void generate() throws IOException, SAXException, ProcessingException
            {
               ...
            }
          
            /**
             * Retrieve the object to SAX.
             * @return the object to SAX.
             * @throws Exception if an error occurs.
             */
            public abstract T getObject() throws Exception;
          
            /**
             * Retrieve the name to use for the root element.
             * @return the name of the root element.
             */
            protected String getRootElementName(T object) throws SAXException
            {
               return "bean";
            }
          
            /**
             * SAX the object retrieved.
             * @param object the object retrieved.
             */
            protected void saxObject(T object) throws SAXException
            {
               ...
            }
            
            /**
             * SAX a collection.
             * @param collection the collection to SAX.
             */
            protected void saxCollection(Collection collection) throws SAXException
            {
               ...
            }
          
            /**
             * SAX a bean.
             * @param bean a bean, might be the retrieved object or a composite.
             */
            protected void saxBean(Object bean) throws SAXException
            {
               ...
            }
          
            /**
             * SAX a property of a bean.
             * @param bean a bean, might be the retrieved object or a composite.
             * @param propertyName the property name.
             * @param propertyValue the property value.
             */
            protected void saxBeanProperty(Object bean, String propertyName, Object propertyValue) throws SAXException
            {
               ...
            }
          
            /**
             * SAX a string property of a bean.
             * @param bean a bean, might be the retrieved object or a composite.
             * @param propertyName the property name.
             * @param propertyValue the property value.
             */
            protected void saxStringBeanProperty(Object bean, String propertyName, String propertyValue) throws SAXException
            {
               ...
            }
          
            /**
             * SAX a date property of a bean.
             */
            protected void saxDateBeanProperty(Object bean, String propertyName, Date propertyValue) throws SAXException
            {
               ...
            }
           
            ...
          }
          

          Sébastien Launay (Inactive) added a comment - C'est souvent que l'on code un générateur spécifique qui récupère un bean ou un collection de beans (depuis un DAO) et que l'on se tappe à la mimine le toSAX de cette structure. Il pourrait donc être intéressant d'avoir ce genre de Generator abstrait avec le comportement par défaut qui représente 99% des cas mais toujours la possibilité de modifier un petit comportement : /** * {@link ServiceableGenerator} extension for SAXing a bean.<p> * The bean is retrieve from {@link #getObject()} and is SAXed using * JavaBean properties by default .<br> * This behaviour can be changed by implementing the right <code>sax*</code> methods. */ public class AbstractBeanGenerator<T> extends ServiceableGenerator { public void generate() throws IOException, SAXException, ProcessingException { ... } /** * Retrieve the object to SAX. * @ return the object to SAX. * @ throws Exception if an error occurs. */ public abstract T getObject() throws Exception; /** * Retrieve the name to use for the root element. * @ return the name of the root element. */ protected String getRootElementName(T object) throws SAXException { return "bean" ; } /** * SAX the object retrieved. * @param object the object retrieved. */ protected void saxObject(T object) throws SAXException { ... } /** * SAX a collection. * @param collection the collection to SAX. */ protected void saxCollection(Collection collection) throws SAXException { ... } /** * SAX a bean. * @param bean a bean, might be the retrieved object or a composite. */ protected void saxBean( Object bean) throws SAXException { ... } /** * SAX a property of a bean. * @param bean a bean, might be the retrieved object or a composite. * @param propertyName the property name. * @param propertyValue the property value. */ protected void saxBeanProperty( Object bean, String propertyName, Object propertyValue) throws SAXException { ... } /** * SAX a string property of a bean. * @param bean a bean, might be the retrieved object or a composite. * @param propertyName the property name. * @param propertyValue the property value. */ protected void saxStringBeanProperty( Object bean, String propertyName, String propertyValue) throws SAXException { ... } /** * SAX a date property of a bean. */ protected void saxDateBeanProperty( Object bean, String propertyName, Date propertyValue) throws SAXException { ... } ... }

            Unassigned Unassigned
            raphael Raphaël Franchet
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: