good point. On 10/25/07, Mike Kienenberger <[EMAIL PROTECTED]> wrote: > I have another question. > > Why were these three converters checked into Tomahawk with absolutely > no discussion and nothing going through the sandbox first? > > I search my mail archives for AtomicLongConverter and the ONLY > reference to it is the commit itself. > > -Mike > > > On 9/16/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Author: dennisbyrne > > Date: Sun Sep 16 20:30:22 2007 > > New Revision: 576248 > > > > URL: http://svn.apache.org/viewvc?rev=576248&view=rev > > Log: > > three new Converters, three tests, and documentation > > > > Added: > > > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicBooleanConverter.java > > > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicIntegerConverter.java > > > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicLongConverter.java > > myfaces/tomahawk/trunk/core/src/site/xdoc/atomicConversion.xml > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/ > > > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicBooleanConverterTestCase.java > > > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicIntegerConverterTest.java > > > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicLongConverterTest.java > > Modified: > > > > myfaces/tomahawk/trunk/core/src/main/resources-facesconfig/META-INF/faces-config.xml > > myfaces/tomahawk/trunk/core/src/site/site.xml > > > > Added: > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicBooleanConverter.java > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicBooleanConverter.java?rev=576248&view=auto > > ============================================================================== > > --- > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicBooleanConverter.java > > (added) > > +++ > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicBooleanConverter.java > > Sun Sep 16 20:30:22 2007 > > @@ -0,0 +1,39 @@ > > +package org.apache.myfaces.convert; > > + > > +import java.util.concurrent.atomic.AtomicBoolean; > > +import java.util.concurrent.atomic.AtomicInteger; > > + > > +import javax.faces.component.UIComponent; > > +import javax.faces.context.FacesContext; > > +import javax.faces.convert.Converter; > > +import javax.faces.convert.ConverterException; > > + > > +public class AtomicBooleanConverter implements Converter { > > + > > + public Object getAsObject(FacesContext ctx, UIComponent ui, String > > string) { > > + > > + return string != null && string.trim().length() > 0 ? > > + new > > AtomicBoolean(Boolean.parseBoolean(string.trim())) : null; > > + } > > + > > + public String getAsString(FacesContext ctx, UIComponent ui, Object > > object) { > > + > > + String string = ""; > > + > > + if( object != null ) { > > + > > + if(object instanceof String) { > > + string = (String) object; > > + }else if(object instanceof AtomicBoolean){ > > + string = ((AtomicBoolean)object).toString(); > > + }else { > > + throw new ConverterException("Received an > > instance of " > > + + > > object.getClass().getName() + ", but was expecting an instance of " > > + + > > AtomicInteger.class.getName()); > > + } > > + } > > + > > + return string; > > + } > > + > > +} > > > > Added: > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicIntegerConverter.java > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicIntegerConverter.java?rev=576248&view=auto > > ============================================================================== > > --- > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicIntegerConverter.java > > (added) > > +++ > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicIntegerConverter.java > > Sun Sep 16 20:30:22 2007 > > @@ -0,0 +1,49 @@ > > +package org.apache.myfaces.convert; > > + > > +import java.util.concurrent.atomic.AtomicInteger; > > + > > +import javax.faces.component.UIComponent; > > +import javax.faces.context.FacesContext; > > +import javax.faces.convert.Converter; > > +import javax.faces.convert.ConverterException; > > + > > +public class AtomicIntegerConverter implements Converter { > > + > > + public Object getAsObject(FacesContext ctx, UIComponent ui, String > > value) { > > + > > + Object object = null; > > + > > + if( value != null && value.trim().length() > 0 ) { > > + try > > + { > > + object = new > > AtomicInteger(Integer.parseInt(value.trim())); > > + > > + }catch(NumberFormatException nfe) { > > + throw new ConverterException(nfe); > > + } > > + } > > + > > + return object; > > + } > > + > > + public String getAsString(FacesContext ctx, UIComponent ui, Object > > object) { > > + > > + String string = ""; > > + > > + if(object != null) { > > + > > + if( object instanceof String ) { > > + string = (String) object; > > + }else if(object instanceof AtomicInteger) { > > + string = ((AtomicInteger)object).toString(); > > + }else { > > + throw new ConverterException("Received an > > instance of " > > + + > > object.getClass().getName() + ", but was expecting an instance of " > > + + > > AtomicInteger.class.getName()); > > + } > > + } > > + > > + return string; > > + } > > + > > +} > > > > Added: > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicLongConverter.java > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicLongConverter.java?rev=576248&view=auto > > ============================================================================== > > --- > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicLongConverter.java > > (added) > > +++ > > myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/convert/AtomicLongConverter.java > > Sun Sep 16 20:30:22 2007 > > @@ -0,0 +1,48 @@ > > +package org.apache.myfaces.convert; > > + > > +import java.util.concurrent.atomic.AtomicLong; > > + > > +import javax.faces.component.UIComponent; > > +import javax.faces.context.FacesContext; > > +import javax.faces.convert.Converter; > > +import javax.faces.convert.ConverterException; > > + > > +public class AtomicLongConverter implements Converter { > > + > > + public Object getAsObject(FacesContext ctx, UIComponent ui, String > > value) { > > + > > + Object object = null; > > + > > + if( value != null && value.trim().length() > 0 ) { > > + try > > + { > > + object = new > > AtomicLong(Long.parseLong(value.trim())); > > + > > + }catch(NumberFormatException nfe) { > > + throw new ConverterException(nfe); > > + } > > + } > > + > > + return object; > > + } > > + > > + public String getAsString(FacesContext ctx, UIComponent ui, Object > > object) { > > + > > + String string = ""; > > + > > + if(object != null) { > > + > > + if( object instanceof String ) { > > + string = (String) object; > > + }else if(object instanceof AtomicLong) { > > + string = ((AtomicLong)object).toString(); > > + }else { > > + throw new ConverterException("Received an > > instance of " > > + + > > object.getClass().getName() + ", but was expecting an instance of " > > + + > > AtomicLong.class.getName()); > > + } > > + } > > + > > + return string; > > + } > > +} > > > > Modified: > > myfaces/tomahawk/trunk/core/src/main/resources-facesconfig/META-INF/faces-config.xml > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/resources-facesconfig/META-INF/faces-config.xml?rev=576248&r1=576247&r2=576248&view=diff > > ============================================================================== > > --- > > myfaces/tomahawk/trunk/core/src/main/resources-facesconfig/META-INF/faces-config.xml > > (original) > > +++ > > myfaces/tomahawk/trunk/core/src/main/resources-facesconfig/META-INF/faces-config.xml > > Sun Sep 16 20:30:22 2007 > > @@ -423,6 +423,20 @@ > > > > <converter-class>org.apache.myfaces.custom.fileupload.UploadedFileConverter</converter-class> > > </converter> > > > > + <converter> > > + > > <converter-for-class>java.util.concurrent.atomic.AtomicBoolean</converter-for-class> > > + > > <converter-class>org.apache.myfaces.convert.AtomicBooleanConverter</converter-class> > > + </converter> > > + > > + <converter> > > + > > <converter-for-class>java.util.concurrent.atomic.AtomicInteger</converter-for-class> > > + > > <converter-class>org.apache.myfaces.convert.AtomicIntegerConverter</converter-class> > > + </converter> > > + > > + <converter> > > + > > <converter-for-class>java.util.concurrent.atomic.AtomicLong</converter-for-class> > > + > > <converter-class>org.apache.myfaces.convert.AtomicLongConverter</converter-class> > > + </converter> > > > > <!-- MyFaces Renderkit Extensions --> > > > > > > Modified: myfaces/tomahawk/trunk/core/src/site/site.xml > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/site/site.xml?rev=576248&r1=576247&r2=576248&view=diff > > ============================================================================== > > --- myfaces/tomahawk/trunk/core/src/site/site.xml (original) > > +++ myfaces/tomahawk/trunk/core/src/site/site.xml Sun Sep 16 20:30:22 2007 > > @@ -76,7 +76,8 @@ > > <menu name="Other Goodies"> > > <item name="Extensions filter" href="extensionsFilter.html"/> > > <item name="forceId" href="forceId.html"/> > > - <item name="Tiles Support" href="tiles.html"/> > > + <item name="Tiles Support" href="tiles.html"/> > > + <item name="Atomic Conversion" href="atomicConversion.html"/> > > </menu> > > > > <menu name="Testing"> > > > > Added: myfaces/tomahawk/trunk/core/src/site/xdoc/atomicConversion.xml > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/site/xdoc/atomicConversion.xml?rev=576248&view=auto > > ============================================================================== > > --- myfaces/tomahawk/trunk/core/src/site/xdoc/atomicConversion.xml (added) > > +++ myfaces/tomahawk/trunk/core/src/site/xdoc/atomicConversion.xml Sun Sep > > 16 20:30:22 2007 > > @@ -0,0 +1,49 @@ > > +<?xml version="1.0" encoding="UTF-8"?> > > + > > +<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation Maven//EN" > > "http://maven.apache.org/dtd/maven-xdoc.dtd"> > > + > > +<document> > > + > > + <body> > > + <section name="Description"> > > + <p> > > + Converters for : > > + <ul> > > + <li>java.util.concurrent.atomic.AtomicBoolean</li> > > + <li>java.util.concurrent.atomic.AtomicInteger</li> > > + <li>java.util.concurrent.atomic.AtomicLong</li> > > + </ul> > > + </p> > > + </section> > > + > > + <section name="API"> > > + > > + <table> > > + <tr> > > + <td colspan="1" rowspan="1">since</td> > > + <td colspan="1" rowspan="1">1.1.7</td> > > + </tr> > > + <tr> > > + <td colspan="1" rowspan="1">author</td> > > + <td colspan="1" rowspan="1">Dennis Byrne</td> > > + </tr> > > + </table> > > + </section> > > + > > + <section name="Usage"> > > + <source xml:space="preserve"> > > +<h:inputText value="#{managedBean.propertyOfTypeAtomicBoolean}"/> > > +<h:inputText value="#{managedBean.propertyOfTypeAtomicInteger}"/> > > +<h:inputText value="#{managedBean.propertyOfTypeAtomicLong}"/> > > + </source> > > + </section> > > + > > + <section name="Instructions"> > > + <p> > > + No configuration required. The Converters > > are registered at startup simply by using MyFaces Tomahawk. > > + </p> > > + </section> > > + </body> > > + > > + > > +</document> > > > > Added: > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicBooleanConverterTestCase.java > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicBooleanConverterTestCase.java?rev=576248&view=auto > > ============================================================================== > > --- > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicBooleanConverterTestCase.java > > (added) > > +++ > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicBooleanConverterTestCase.java > > Sun Sep 16 20:30:22 2007 > > @@ -0,0 +1,48 @@ > > +package org.apache.myfaces.convert; > > + > > +import java.util.concurrent.atomic.AtomicBoolean; > > + > > +import javax.faces.convert.Converter; > > +import javax.faces.convert.ConverterException; > > + > > +import junit.framework.TestCase; > > + > > +public class AtomicBooleanConverterTestCase extends TestCase { > > + > > + public void testGetAsObject() { > > + > > + Converter converter = new AtomicBooleanConverter(); > > + > > + assertNull(converter.getAsObject(null, null, null)); > > + assertNull(converter.getAsObject(null, null, "")); > > + assertNull(converter.getAsObject(null, null, " ")); > > + assertTrue(((AtomicBoolean)converter.getAsObject(null, > > null, "true")).get()); > > + assertTrue(((AtomicBoolean)converter.getAsObject(null, > > null, "true ")).get()); > > + assertTrue(((AtomicBoolean)converter.getAsObject(null, > > null, " true")).get()); > > + assertFalse(((AtomicBoolean)converter.getAsObject(null, > > null, "false")).get()); > > + assertFalse(((AtomicBoolean)converter.getAsObject(null, > > null, "false ")).get()); > > + assertFalse(((AtomicBoolean)converter.getAsObject(null, > > null, " false")).get()); > > + assertFalse(((AtomicBoolean)converter.getAsObject(null, > > null, " boom ")).get()); > > + > > + } > > + > > + public void testGetAsString() { > > + > > + Converter converter = new AtomicBooleanConverter(); > > + > > + assertEquals("", converter.getAsString(null, null, null)); > > + assertEquals("", converter.getAsString(null, null, "")); > > + assertEquals("true", converter.getAsString(null, null, new > > AtomicBoolean(true))); > > + assertEquals("false", converter.getAsString(null, null, new > > AtomicBoolean(false))); > > + > > + try { > > + > > + converter.getAsString(null, null, new Boolean(true) > > ); > > + > > + fail(); > > + > > + }catch(ConverterException c) { } > > + > > + } > > + > > +} > > > > Added: > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicIntegerConverterTest.java > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicIntegerConverterTest.java?rev=576248&view=auto > > ============================================================================== > > --- > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicIntegerConverterTest.java > > (added) > > +++ > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicIntegerConverterTest.java > > Sun Sep 16 20:30:22 2007 > > @@ -0,0 +1,54 @@ > > +package org.apache.myfaces.convert; > > + > > +import java.util.concurrent.atomic.AtomicInteger; > > + > > +import javax.faces.convert.Converter; > > +import javax.faces.convert.ConverterException; > > + > > +import junit.framework.TestCase; > > + > > +public class AtomicIntegerConverterTest extends TestCase { > > + > > + public void testGetAsObject() { > > + > > + Converter converter = new AtomicIntegerConverter(); > > + > > + assertNull( converter.getAsObject(null, null, null) ); > > + assertNull( converter.getAsObject(null, null, "") ); > > + assertNull( converter.getAsObject(null, null, " ") ); > > + assertTrue( 8 == ((AtomicInteger) > > converter.getAsObject(null, null, " 8")).intValue() ); > > + assertTrue( 8 == ((AtomicInteger) > > converter.getAsObject(null, null, "8 ")).intValue() ); > > + assertTrue( 8 == ((AtomicInteger) > > converter.getAsObject(null, null, "8")).intValue() ); > > + int over = Integer.MAX_VALUE + 1; > > + assertTrue( over == ((AtomicInteger) > > converter.getAsObject(null, null, over + "")).intValue() ); > > + int under = Integer.MIN_VALUE - 1; > > + assertTrue( under == ((AtomicInteger) > > converter.getAsObject(null, null, under + "")).intValue() ); > > + > > + try { > > + > > + converter.getAsObject(null, null, "NaN"); > > + > > + fail("should only take numbers"); > > + > > + }catch(ConverterException c) { } > > + } > > + > > + public void testGetAsString() { > > + > > + Converter converter = new AtomicIntegerConverter(); > > + > > + assertEquals("", converter.getAsString(null, null, null)); > > + assertEquals("", converter.getAsString(null, null, "")); > > + assertEquals(" ", converter.getAsString(null, null, " ")); > > + assertEquals("-1", converter.getAsString(null, null, new > > AtomicInteger(-1))); > > + > > + try { > > + > > + converter.getAsString(null, null, new Integer(0)); > > + > > + fail("should only take atomic ints"); > > + > > + }catch(ConverterException c) { } > > + } > > + > > +} > > > > Added: > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicLongConverterTest.java > > URL: > > http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicLongConverterTest.java?rev=576248&view=auto > > ============================================================================== > > --- > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicLongConverterTest.java > > (added) > > +++ > > myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/convert/AtomicLongConverterTest.java > > Sun Sep 16 20:30:22 2007 > > @@ -0,0 +1,54 @@ > > +package org.apache.myfaces.convert; > > + > > +import java.util.concurrent.atomic.AtomicLong; > > + > > +import javax.faces.convert.Converter; > > +import javax.faces.convert.ConverterException; > > + > > +import junit.framework.TestCase; > > + > > +public class AtomicLongConverterTest extends TestCase{ > > + > > + public void testGetAsObject() { > > + > > + Converter converter = new AtomicLongConverter(); > > + > > + assertNull( converter.getAsObject(null, null, null) ); > > + assertNull( converter.getAsObject(null, null, "") ); > > + assertNull( converter.getAsObject(null, null, " ") ); > > + assertTrue( 8 == ((AtomicLong) converter.getAsObject(null, > > null, " 8")).longValue() ); > > + assertTrue( 8 == ((AtomicLong) converter.getAsObject(null, > > null, "8 ")).longValue() ); > > + assertTrue( 8 == ((AtomicLong) converter.getAsObject(null, > > null, "8")).longValue() ); > > + long over = Long.MAX_VALUE + 1; > > + assertTrue( over == ((AtomicLong) > > converter.getAsObject(null, null, over + "")).longValue() ); > > + long under = Long.MIN_VALUE - 1; > > + assertTrue( under == ((AtomicLong) > > converter.getAsObject(null, null, under + "")).longValue() ); > > + > > + try { > > + > > + converter.getAsObject(null, null, "NaN"); > > + > > + fail("should only take numbers"); > > + > > + }catch(ConverterException c) { } > > + > > + } > > + > > + public void testGetAsString() { > > + > > + Converter converter = new AtomicLongConverter(); > > + > > + assertEquals("", converter.getAsString(null, null, null)); > > + assertEquals("", converter.getAsString(null, null, "")); > > + assertEquals(" ", converter.getAsString(null, null, " ")); > > + assertEquals("-1", converter.getAsString(null, null, new > > AtomicLong(-1))); > > + > > + try { > > + > > + converter.getAsString(null, null, new Long(0)); > > + > > + fail("should only take atomic ints"); > > + > > + }catch(ConverterException c) { } > > + } > > +} > > \ No newline at end of file > > > > > > >
-- Matthias Wessendorf further stuff: blog: http://matthiaswessendorf.wordpress.com/ mail: matzew-at-apache-dot-org
