commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r155266 - in jakarta/commons/proper/betwixt/trunk/xdocs: guide/binding.xml tasks.xml
Date Thu, 24 Feb 2005 22:29:52 GMT
Author: rdonkin
Date: Thu Feb 24 14:29:51 2005
New Revision: 155266

URL: http://svn.apache.org/viewcvs?view=rev&rev=155266
Log:
Documentation for change ObjectToStringConverter to make context available and to make options
available from context. This is an alternative way to address the needs of Issue 33331.

Modified:
    jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml
    jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml

Modified: jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml?view=diff&r1=155265&r2=155266
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/guide/binding.xml Thu Feb 24 14:29:51 2005
@@ -667,6 +667,67 @@
 <code>org.apache.commons.betwixt.strategy</code> package. Examining the source
code for these classes
 is a good please to start when creating your own implementation.
         </p>
+	</subsection>
+        <subsection name='Flavours For Custom Converters'>
+        	<p>
+One problem facing those who create custom converters is that objects of the same type
+may (in different contexts) require different conversions. For example, a <code>java.util.Date</code>
+may in one context have the symantic meaning of a day (and so the conversion needs to suppress
the 
+time component) and in another may indicate a date time (and so the conversion in this case
needs to 
+render the time components). The same type may come in different <em>flavours</em>.

+        </p>
+        	<p>
+The recommended way to solve this kind of problem is to added options to the betwixt file
+which can then be picked up by the custom converter and used to determine the appropriate
+conversion.	
+        </p>
+        	<p>
+For example, consider a bean representing a person with an attribute
+giving that person's date of birth. Suppose that this is stored
+as aa <code>java.util.Date</code>. This needs to be rendered as 
+a date string (without a time component). A good approach would be 
+to add an option to the dot betwixt file as follows:
+		</p>
+<source><![CDATA[
+<?xml version='1.0'?>
+<info primitiveTypes="attribute">
+	<element name=''>
+		<element name='birthday' property='birthday'>
+			<option>
+				<name>org.apache.commons.betwixt.flavour</name>
+				<value>Day</value>
+			</option>
+		</element>
+		<addDefaults/>
+	</element>
+</info>
+]]>
+</source>           
+			<p>  	
+The following code snippet illustrates how a custom converter
+can use this information:
+        </p>
+<source><![CDATA[
+    public String objectToString(Object object, Class type, Context context) {
+        String flavour = null;
+        Options options = context.getOptions();
+        if (options != null) {
+            flavour = options.getValue("org.apache.commons.betwixt.flavour");
+        }
+
+        if ("Day".equals(flavour)) {
+            // render as date with no time component
+            ...
+        } else {
+            // Do normal rendering
+            ...
+        }
+    }
+]]>
+</source>
+			<p>
+Of course, the choice of the option name is purely arbitrary.			
+		</p>
     </subsection>
 </section>
     <section name='Multi Mapping'>

Modified: jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml?view=diff&r1=155265&r2=155266
==============================================================================
--- jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml (original)
+++ jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Thu Feb 24 14:29:51 2005
@@ -186,6 +186,9 @@
 <section name='Completed'>
     <subsection name='since 0.6'>
         <ul>
+        	<li>Added <strong>options to context</strong>. This replaces direct
flavour mechanism. 
+        	(Flavour becomes just a specific option).</li>
+        	<li>Factored out <strong>id storage</strong> into strategy</li>
             <li><strong>anonymous collections</strong> now allowed in betwixt
files</li>
             <li><strong>Improved introspection support for DynaBeans</strong></li>
             <li><strong>Improved introspection for interfaces</strong>
superinterface 
@@ -334,6 +337,16 @@
     </subsection>
 </section>
 <section name='Deprecated'>
+	<subsection name='since 0.6'>
+		<ul>
+			<li>ObjectStringConverter direct flavour replaced with use of options
+				<ul>
+					<li>objectToString replaced by method without flavour in signature</li>
+					<li>stringToObject replaced by method without flavour in signature</li>
+				</ul>
+			</li>
+		</ul>
+	</subsection>
     <subsection name='0.6'>
         <ul>
                 <li><strong>Refactoring (more declarative descriptors)</strong>



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


Mime
View raw message