You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2004/02/04 00:01:45 UTC

cvs commit: jakarta-commons/betwixt/xdocs/guide binding.xml

rdonkin     2004/02/03 15:01:45

  Modified:    betwixt/xdocs Tag: REFACTORING-BRANCH_2004-01-13 tasks.xml
               betwixt/xdocs/guide Tag: REFACTORING-BRANCH_2004-01-13
                        binding.xml
  Log:
  Documentation for SimpleTypeMapper strategy
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.25.2.5  +4 -0      jakarta-commons/betwixt/xdocs/tasks.xml
  
  Index: tasks.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/tasks.xml,v
  retrieving revision 1.25.2.4
  retrieving revision 1.25.2.5
  diff -u -r1.25.2.4 -r1.25.2.5
  --- tasks.xml	21 Jan 2004 21:25:20 -0000	1.25.2.4
  +++ tasks.xml	3 Feb 2004 23:01:45 -0000	1.25.2.5
  @@ -269,6 +269,10 @@
   to <addDefaults> that allow matching properties or adders to be
   supressed.
               </li>
  +            <li>
  +<strong>SimpleTypeMapper strategy</strong> for finely grained control over simple type (primitive) 
  +binding.
  +            </li>
           </ul>
       </subsection>
   </section>
  
  
  
  No                   revision
  No                   revision
  1.3.2.1   +37 -0     jakarta-commons/betwixt/xdocs/guide/binding.xml
  
  Index: binding.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/guide/binding.xml,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- binding.xml	8 Sep 2003 13:58:53 -0000	1.3
  +++ binding.xml	3 Feb 2004 23:01:45 -0000	1.3.2.1
  @@ -281,6 +281,43 @@
       </p>
       
       <p>
  +More finely grained control over which primitive properties are mapped to elements and which
  +to attributes can be supplied by creating a custom <code>SimpleTypeMapper</code> strategy
  +and plugging that into the introspection configuration. 
  +    </p>
  +    
  +    <p>
  +Here is an example implementation (which maps strings to elements 
  +and everything else to attributes):
  +    </p>
  +<source><![CDATA[    
  +    /** Implementation binds strings to elements but everything else to attributes */
  +    public class StringsAsElementsSimpleTypeMapper extends SimpleTypeMapper {
  +        /**
  +         * Binds strings to elements but everything else to attributes
  +         */
  +        public Binding bind(
  +                            String propertyName, 
  +                            Class propertyType, 
  +                            IntrospectionConfiguration configuration) {
  +            if (String.class.equals(propertyType)) {
  +                return SimpleTypeMapper.Binding.ELEMENT;
  +            }
  +            return SimpleTypeMapper.Binding.ATTRIBUTE;
  +        }
  +    }
  +]]></source>    
  +    <p>
  +This class can be used to configure <code>Betwixt</code> so that strings are bounds to
  +elements but other primitives are bound to attributes as follows:
  +    </p>
  +<source><![CDATA[     
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        introspector.getConfiguration().setSimpleTypeMapper(
  +            new StringsAsElementsSimpleTypeMapper());
  +        ...
  +]]></source> 
  +    <p>
       The <strong><code>WrapCollectionsInElement</code></strong> property determines whether the elements 
       for a composite property (ie one that returns a collection or iterator) should be wrapped in a parent
       element. For example, if <code>isWrapCollectionsInElement</code> is true then a property with signature 
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org