Return-Path: Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 88923 invoked by uid 500); 16 Aug 2003 06:30:02 -0000 Received: (qmail 88920 invoked from network); 16 Aug 2003 06:30:02 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 16 Aug 2003 06:30:02 -0000 Received: (qmail 14290 invoked by uid 1289); 16 Aug 2003 06:30:24 -0000 Date: 16 Aug 2003 06:30:24 -0000 Message-ID: <20030816063024.14289.qmail@minotaur.apache.org> From: rdonkin@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/betwixt/xdocs/guide binding.xml X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N rdonkin 2003/08/15 23:30:24 Modified: betwixt/xdocs tasks.xml betwixt/xdocs/guide binding.xml Log: Added pluggable Object<->String conversion strategy documentation Revision Changes Path 1.20 +14 -0 jakarta-commons/betwixt/xdocs/tasks.xml Index: tasks.xml =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/tasks.xml,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- tasks.xml 29 Jul 2003 21:33:31 -0000 1.19 +++ tasks.xml 16 Aug 2003 06:30:24 -0000 1.20 @@ -236,6 +236,15 @@ Support for converting output strings ConvertUtils is now called to convert output strings (as well as input ones). +
  • + Refactored Object <-> String Conversion + This process has been factored out into a separate pluggable Strategy class + (ObjectStringConverter). A pure ConvertUtils implementation + has been created (ConvertUtilsObjectStringConverter). The default implementation + (DefaultsObjectStringConverter) delegates most conversions to ConvertUtils + but contains a special case that allows the default setting to round trip java.util.Date's + without breaking compatibility. +
  • @@ -352,6 +361,11 @@ ConvertUtils from commons-beanutils is now called to performt the object to string conversions. It is possible that in some circumstances, this change may effect the output. + +
  • + ConvertUtils conversion now ignored (by default) for java.util.Date + If you use a custom ConvertUtils java.util.Date converter then see + the guide.
  • 1.2 +87 -6 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- binding.xml 14 Aug 2003 21:25:26 -0000 1.1 +++ binding.xml 16 Aug 2003 06:30:24 -0000 1.2 @@ -339,16 +339,97 @@ property is specified then the bean can be written and then read back.

    + - -

    +

    + + +

    ConvertUtils is part of commons-beanutils -and it can be used to flexibly convert strings to objects and back again. Betwixt uses ConvertUtils to +and it can be used to flexibly convert strings to objects and back again. By default, Betwixt uses ConvertUtils to perform these conversions and so standard ConvertUtils methods can be called to customize these conversions. -

    -
    - +

    + + +

    +There are numerous situations when read beans from xml or writing beans to xml that String to Object +or Object to String conversions are required. Betwixt uses a Strategy class to allow a convenient +default which will work well for most basic users whilst allowing advanced users to fully hook in and +customize this process. +

    +

    +The default strategy uses ConvertUtils from +commons-beanutils to perform these conversions. +This is a powerful component that allows flexible customization of the conversion process. +

    +

    +There is one exception to this rule. If the class is a java.util.Date - or a subclass of java.util.Date which is not a subclass of java.sql.Date, java.sql.Time or java.sql.Timestamp - then this is converted to and from a string following this pattern: +

      +    EEE MMM dd HH:mm:ss zzz yyyy
      +
    +(using the SimpleDateFormat notation). Observent readers will realise that this is the same pattern +that is returned by java.util.Date.toString - and that's why this pattern was chosen. +It provides a good default for casual users. +

    +

    +Advanced users will probably need a particular date format. The recommended way to do this is through +registering appropriate converters with ConvertUtils. The default conversion strategy must also be +replaced with an instance of + +ConvertUtilsObjectStringConverter. This is set though a BindingConfiguration property. +

    +

    +For example, to delegate to ConvertUtils for all conversions in a read: +

      +    BeanReader reader = new BeanReader();
      +    reader.getBindingConfiguration(new ConvertUtilsObjectStringConverter());
      +    reader.parse...
      +
    +and in a write: +
      +    BeanWriter writer = new BeanWriter();
      +    writer.getBindingConfiguration(new ConvertUtilsObjectStringConverter());
      +    writer.write...
      +
    +

    +
    + +

    +ConvertUtils is flexible and powerful. It comes with a range of Converter +implementations which allow quick and easy customization. But, there are occasions where this will +not suit all the requirements of the user. Betwixt supports this need by allowing a custom +ObjectStringConverter to be plugged in. +

    +

    +The strategy class +ObjectStringConverter +is simple: containing only two simple methods. For more information about creating subclasses, see the javadocs. +The implementation to be used is set through the BindingConfiguration +ObjectStringConverter property. +

    +

    +For example, to set a custom ObjectStringConverter for all conversions in a read: +

      +    ObjectStringConverter converter = new MyObjectStringConverter();
      +    BeanReader reader = new BeanReader();
      +    reader.getBindingConfiguration(converter);
      +    reader.parse...
      +
    +and in a write: +
      +    ObjectStringConverter converter = new MyObjectStringConverter();
      +    BeanWriter writer = new BeanWriter();
      +    writer.getBindingConfiguration(converter);
      +    writer.write...
      +
    +

    +

    +Betwixt is distributed with a range of ObjectStringConverter's in the +org.apache.commons.betwixt.strategy package. Examining the source code for these classes +is a good please to start when creating your own implementation. +

    +