Author: hlship
Date: Thu Jan 17 12:09:49 2008
New Revision: 612958
URL: http://svn.apache.org/viewvc?rev=612958&view=rev
Log:
TAPESTRY-1739: Add byte, short and float Translators
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/ByteTranslator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/DoubleTranslator.java
- copied, changed from r594319,
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/FloatTranslator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/StringTranslator.java
- copied, changed from r594319,
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/StringTranslator.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/translator/
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/StringTranslator.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/translator/DoubleTranslatorTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/translator/IntegerTranslatorTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/translator/LongTranslatorTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/translator/StringTranslatorTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/Translator.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/FieldValidationSupportImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidationSupport.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TranslatorDefaultSource.java
tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/FieldValidationSupportImplTest.java
tapestry/tapestry5/trunk/tapestry5.ipr
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/Translator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/Translator.java?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/Translator.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/Translator.java
Thu Jan 17 12:09:49 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -27,11 +27,11 @@
public interface Translator<T>
{
/**
- * Converts a server-side value to a client-side string. This allows for
formatting of the value
- * in a way appropriate to the end user. The output client value should be
parsable by
- * [EMAIL PROTECTED] #parseClient(String, Messages)}.
+ * Converts a server-side value to a client-side string. This allows for
formatting of the value in a way
+ * appropriate to the end user. The output client value should be parsable
by [EMAIL PROTECTED] #parseClient(String,
+ * Messages)}.
*
- * @param value the server side value (which may be null)
+ * @param value the server side value (which will not be null)
* @return client-side value to present to the user
*/
String toClient(T value);
@@ -39,7 +39,7 @@
/**
* Converts a submitted request value into an appropriate server side
value.
*
- * @param clientValue (possibly null or the empty string)
+ * @param clientValue to convert to a server value; this will not be the
empty string or null
* @param messages validator messages assembled by [EMAIL PROTECTED]
ValidationMessagesSource}
* @return equivalent server-side value (possibly null)
* @throws ValidationException if the value can not be parsed
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/FieldValidationSupportImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/FieldValidationSupportImpl.java?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/FieldValidationSupportImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/FieldValidationSupportImpl.java
Thu Jan 17 12:09:49 2008
@@ -18,6 +18,7 @@
import org.apache.tapestry.corelib.internal.InternalMessages;
import org.apache.tapestry.internal.util.Holder;
import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.runtime.ComponentEventException;
import org.apache.tapestry.services.FieldValidationSupport;
@@ -39,6 +40,8 @@
@SuppressWarnings({"unchecked"})
public String toClient(Object value, ComponentResources
componentResources, Translator translator)
{
+ if (value == null) return null;
+
final Holder<String> resultHolder = Holder.create();
ComponentEventCallback callback = new ComponentEventCallback()
@@ -61,6 +64,7 @@
if (resultHolder.hasValue()) return resultHolder.get();
+
return translator.toClient(value);
}
@@ -68,6 +72,8 @@
public Object parseClient(String clientValue, ComponentResources
componentResources, Translator translator)
throws ValidationException
{
+ if (InternalUtils.isBlank(clientValue)) return null;
+
final Holder<Object> resultHolder = Holder.create();
ComponentEventCallback callback = new ComponentEventCallback()
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImpl.java?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImpl.java
Thu Jan 17 12:09:49 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
_registry = StrategyRegistry.newInstance(Translator.class,
configuration);
}
- public Translator find(Class valueType)
+ public Translator get(Class valueType)
{
return _registry.get(valueType);
}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/ByteTranslator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/ByteTranslator.java?rev=612958&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/ByteTranslator.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/ByteTranslator.java
Thu Jan 17 12:09:49 2008
@@ -0,0 +1,39 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.translator;
+
+import org.apache.tapestry.Translator;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.ioc.Messages;
+
+public class ByteTranslator implements Translator<Byte>
+{
+ public String toClient(Byte value)
+ {
+ return value.toString();
+ }
+
+ public Byte parseClient(String clientValue, Messages messages) throws
ValidationException
+ {
+ try
+ {
+ return new Byte(clientValue.trim());
+ }
+ catch (NumberFormatException ex)
+ {
+ throw new
ValidationException(messages.format("integer-format-exception", clientValue));
+ }
+ }
+}
Copied:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/DoubleTranslator.java
(from r594319,
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java)
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/DoubleTranslator.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/DoubleTranslator.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java&r1=594319&r2=612958&rev=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/DoubleTranslator.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/DoubleTranslator.java
Thu Jan 17 12:09:49 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.translator;
+package org.apache.tapestry.internal.translator;
import org.apache.tapestry.Translator;
import org.apache.tapestry.ValidationException;
import org.apache.tapestry.ioc.Messages;
-import org.apache.tapestry.ioc.internal.util.InternalUtils;
public class DoubleTranslator implements Translator<Double>
{
@@ -28,9 +27,6 @@
*/
public Double parseClient(String clientValue, Messages messages) throws
ValidationException
{
- if (InternalUtils.isBlank(clientValue))
- return null;
-
try
{
return new Double(clientValue.trim());
@@ -46,6 +42,6 @@
*/
public String toClient(Double value)
{
- return value == null ? "" : value.toString();
+ return value.toString();
}
}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/FloatTranslator.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/FloatTranslator.java?rev=612958&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/FloatTranslator.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/FloatTranslator.java
Thu Jan 17 12:09:49 2008
@@ -0,0 +1,39 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.translator;
+
+import org.apache.tapestry.Translator;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.ioc.Messages;
+
+public class FloatTranslator implements Translator<Float>
+{
+ public String toClient(Float value)
+ {
+ return value.toString();
+ }
+
+ public Float parseClient(String clientValue, Messages messages) throws
ValidationException
+ {
+ try
+ {
+ return new Float(clientValue.trim());
+ }
+ catch (NumberFormatException ex)
+ {
+ throw new
ValidationException(messages.format("number-format-exception", clientValue));
+ }
+ }
+}
Copied:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/StringTranslator.java
(from r594319,
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/StringTranslator.java)
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/StringTranslator.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/StringTranslator.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/StringTranslator.java&r1=594319&r2=612958&rev=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/translator/StringTranslator.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/translator/StringTranslator.java
Thu Jan 17 12:09:49 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.translator;
+package org.apache.tapestry.internal.translator;
import org.apache.tapestry.Translator;
import org.apache.tapestry.ValidationException;
import org.apache.tapestry.ioc.Messages;
-import org.apache.tapestry.ioc.internal.util.InternalUtils;
public class StringTranslator implements Translator<String>
{
@@ -26,15 +25,15 @@
*/
public String parseClient(String clientValue, Messages messages) throws
ValidationException
{
- return InternalUtils.isBlank(clientValue) ? null : clientValue;
+ return clientValue;
}
/**
- * Returns the value, or the empty string if value is null.
+ * Returns the value.
*/
public String toClient(String value)
{
- return value == null ? "" : value;
+ return value;
}
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidationSupport.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidationSupport.java?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidationSupport.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/FieldValidationSupport.java
Thu Jan 17 12:09:49 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -20,29 +20,32 @@
import org.apache.tapestry.ValidationException;
/**
- * Services to help with field [EMAIL PROTECTED] org.apache.tapestry.Validator
validation} and
- * [EMAIL PROTECTED] org.apache.tapestry.Translator translation}. This service
encapsulates
- * the logic that mixes normal configured/declared validation/translation with
- * events triggered on the component.
+ * Services to help with field [EMAIL PROTECTED] org.apache.tapestry.Validator
validation} and [EMAIL PROTECTED]
+ * org.apache.tapestry.Translator translation}. This service encapsulates the
logic that mixes normal
+ * configured/declared validation/translation with events triggered on the
component.
*/
public interface FieldValidationSupport
{
/**
- * A wrapper around [EMAIL PROTECTED]
org.apache.tapestry.Translator#toClient(Object)} that first
- * fires a "toclient" event on the component to see if it can perform the
conversion.
+ * A wrapper around [EMAIL PROTECTED]
org.apache.tapestry.Translator#toClient(Object)} that first fires a "toclient"
event on
+ * the component to see if it can perform the conversion. If the value is
null, then no event is fired and the
+ * translator is <em>not</em> invoked, the return value is simply null.
*
* @param value to be converted to a client-side string
* @param componentResources used to fire events on the component
* @param translator used if the component does not provide a
non-null value
- * @return the translated value
+ * @return the translated value or null if the value is null
*/
String toClient(Object value, ComponentResources componentResources,
Translator translator);
/**
* A wrapper around [EMAIL PROTECTED]
org.apache.tapestry.Translator#parseClient(String,
org.apache.tapestry.ioc.Messages)}.
* First a "parseclient" event is fired; the translator is only invoked if
that returns null.
+ * <p/>
+ * If the client value is null or blank, then no event is fired and the
translator is not invoked. Instead, the
+ * return value is null.
*
- * @param clientValue the value provided by the client (may be null)
+ * @param clientValue the value provided by the client (not null or
blank)
* @param componentResources used to trigger events
* @param translator translator that will do the work if the
component event returns null
* @return the input parsed to an object
@@ -53,10 +56,10 @@
throws ValidationException;
/**
- * Performs validation on a parsed value from the client. Normal
validations occur first,
- * then a "validate" event is triggered on the component.
+ * Performs validation on a parsed value from the client. Normal
validations occur first, then a "validate" event
+ * is triggered on the component.
*
- * @param value parsed value from the client
+ * @param value parsed value from the client, possibly null
* @param componentResources used to trigger events
* @param validator performs normal validations
* @throws ValidationException if the value is not valid
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
Thu Jan 17 12:09:49 2008
@@ -29,6 +29,7 @@
import org.apache.tapestry.internal.grid.CollectionGridDataSource;
import org.apache.tapestry.internal.grid.NullDataSource;
import org.apache.tapestry.internal.services.*;
+import org.apache.tapestry.internal.translator.*;
import org.apache.tapestry.internal.util.IntegerRange;
import org.apache.tapestry.ioc.*;
import static org.apache.tapestry.ioc.IOCConstants.PERTHREAD_SCOPE;
@@ -42,10 +43,6 @@
import org.apache.tapestry.runtime.Component;
import org.apache.tapestry.runtime.ComponentResourcesAware;
import org.apache.tapestry.runtime.RenderCommand;
-import org.apache.tapestry.translator.DoubleTranslator;
-import org.apache.tapestry.translator.IntegerTranslator;
-import org.apache.tapestry.translator.LongTranslator;
-import org.apache.tapestry.translator.StringTranslator;
import org.apache.tapestry.util.StringToEnumCoercion;
import org.apache.tapestry.validator.*;
import org.slf4j.Logger;
@@ -511,20 +508,22 @@
/**
- * Contributes the basic set of default translators: <ul> <li>Integer</li>
<li>String</li> <li>Long</li>
- * <li>Double</li> </li>
+ * Contributes the basic set of default translators: <ul> <li>String</li>
<li>Byte</li> <li>Integer</li>
+ * <li>Long</li> <li>Float</li> <li>Double</li> </li>
*/
public static void
contributeTranslatorDefaultSource(MappedConfiguration<Class, Translator>
configuration)
{
- configuration.add(Integer.class, new IntegerTranslator());
configuration.add(String.class, new StringTranslator());
+ configuration.add(Byte.class, new ByteTranslator());
+ configuration.add(Integer.class, new IntegerTranslator());
configuration.add(Long.class, new LongTranslator());
+ configuration.add(Float.class, new FloatTranslator());
configuration.add(Double.class, new DoubleTranslator());
}
/**
- * Contributes the basic set of named translators: <ul> <li>integer</li>
<li>string</li> <li>long</li>
- * <li>double</li> </ul>
+ * Contributes the basic set of named translators: <ul> <li>string</li>
<li>byte</li> <li>integer</li>
+ * <li>long</li> <li>float</li> <li>double</li> </ul>
*/
public static void contributeTranslatorSource(MappedConfiguration<String,
Translator> configuration)
{
@@ -533,9 +532,11 @@
// organized (perhaps they should be joined together into a single
service, where we
// identify a name and a match type).
- configuration.add("integer", new IntegerTranslator());
configuration.add("string", new StringTranslator());
+ configuration.add("byte", new ByteTranslator());
+ configuration.add("integer", new IntegerTranslator());
configuration.add("long", new LongTranslator());
+ configuration.add("float", new FloatTranslator());
configuration.add("double", new DoubleTranslator());
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TranslatorDefaultSource.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TranslatorDefaultSource.java?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TranslatorDefaultSource.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TranslatorDefaultSource.java
Thu Jan 17 12:09:49 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -18,19 +18,18 @@
import org.apache.tapestry.Translator;
/**
- * Used by certain form-control element component to obtain a default
translator appropriate to the
- * type of property editted by the component.
+ * Used by certain form-control element component to obtain a default
translator appropriate to the type of property
+ * editted by the component.
*/
public interface TranslatorDefaultSource
{
/**
- * Finds a [EMAIL PROTECTED] Translator} that is appropriate to the given
type, which is usually obtained
- * via [EMAIL PROTECTED] Binding#getBindingType()}. Performs an
inheritanced-based search for the best
- * match.
+ * Finds a [EMAIL PROTECTED] Translator} that is appropriate to the given
type, which is usually obtained via [EMAIL PROTECTED]
+ * Binding#getBindingType()}. Performs an inheritanced-based search for
the best match.
*
* @param valueType the type of value for which a default translator is
needed
* @return the matching translator
* @throws IllegalArgumentException if no translator may be found
*/
- Translator find(Class valueType);
+ Translator get(Class valueType);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml Thu Jan 17
12:09:49 2008
@@ -37,7 +37,6 @@
<package name="org.apache.tapestry.services"/>
<package name="org.apache.tapestry.util"/>
<package name="org.apache.tapestry.runtime"/>
- <package name="org.apache.tapestry.translator"/>
<package name="org.apache.tapestry.validator"/>
</packages>
</test>
@@ -53,6 +52,7 @@
<package name="org.apache.tapestry.internal.bindings"/>
<package name="org.apache.tapestry.internal.model"/>
<package name="org.apache.tapestry.internal.test"/>
+ <package name="org.apache.tapestry.internal.translator"/>
</packages>
</test>
</suite>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/FieldValidationSupportImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/FieldValidationSupportImplTest.java?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/FieldValidationSupportImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/FieldValidationSupportImplTest.java
Thu Jan 17 12:09:49 2008
@@ -72,6 +72,42 @@
verify();
}
+ @Test
+ public void
to_client_for_null_value_returns_null_and_bypasses_events_and_translator()
throws Exception
+ {
+ ComponentResources resources = mockComponentResources();
+ Translator translator = mockTranslator();
+ ValidationMessagesSource source = mockValidationMessagesSource();
+
+ replay();
+
+
+ FieldValidationSupport support = new
FieldValidationSupportImpl(source);
+
+ assertNull(support.parseClient(null, resources, translator));
+
+
+ verify();
+ }
+
+ @Test
+ public void
parse_client_for_blank_string_returns_null_and_bypasses_events_and_translator()
throws Exception
+ {
+ ComponentResources resources = mockComponentResources();
+ Translator translator = mockTranslator();
+ ValidationException ve = new ValidationException("Just didn't feel
right.");
+ ValidationMessagesSource source = mockValidationMessagesSource();
+
+
+ replay();
+
+ FieldValidationSupport support = new
FieldValidationSupportImpl(source);
+
+ assertNull(support.parseClient("", resources, translator));
+
+ verify();
+ }
+
@SuppressWarnings({"ThrowableInstanceNeverThrown"})
@Test
public void parse_client_event_handler_throws_validation_exception()
throws Exception
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImplTest.java?rev=612958&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImplTest.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/TranslatorDefaultSourceImplTest.java
Thu Jan 17 12:09:49 2008
@@ -0,0 +1,138 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import org.apache.tapestry.Translator;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.services.TranslatorDefaultSource;
+import org.apache.tapestry.services.ValidationMessagesSource;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.util.Locale;
+
+/**
+ * Actually, a test for the source and for all of the built-in translators.
+ */
+public class TranslatorDefaultSourceImplTest extends InternalBaseTestCase
+{
+ private TranslatorDefaultSource _source;
+ private ValidationMessagesSource _messagesSource;
+
+ @BeforeClass
+ public void setup()
+ {
+ _source = getService(TranslatorDefaultSource.class);
+ _messagesSource = getService(ValidationMessagesSource.class);
+ }
+
+ @DataProvider(name = "to_client_data")
+ public Object[][] to_client_data()
+ {
+ return new Object[][]{
+
+ {Byte.class, (byte) 65, "65"},
+
+ {Integer.class, 997, "997"},
+
+ {Long.class, 12345l, "12345"},
+
+ {Double.class, 123.45d, "123.45"},
+
+ {String.class, "abcd", "abcd"},
+
+ {Float.class, (float) -22.7, "-22.7"}
+
+ };
+ }
+
+ @Test(dataProvider = "to_client_data")
+ public void to_client(Class type, Object value, String expected)
+ {
+ Translator t = _source.get(type);
+
+ String actual = t.toClient(value);
+
+ assertEquals(actual, expected);
+ }
+
+ @DataProvider(name = "parse_client_success_data")
+ public Object[][] parse_client_success_data()
+ {
+ return new Object[][]{
+
+ {Byte.class, " 23 ", (byte) 23},
+
+ {Integer.class, " 123 ", 123},
+
+ {Long.class, " -1234567 ", -1234567l},
+
+ {Double.class, " 3.14 ", 3.14d},
+
+ {String.class, " abcdef ", " abcdef "},
+
+ {Float.class, " 28.95 ", (float) 28.95},
+
+ };
+ }
+
+ @Test(dataProvider = "parse_client_success_data")
+ public void parse_client(Class type, String input, Object expected) throws
Exception
+ {
+ Translator t = _source.get(type);
+
+ Object actual = t.parseClient(input,
_messagesSource.getValidationMessages(Locale.ENGLISH));
+
+ assertEquals(actual, expected);
+ }
+
+ @DataProvider(name = "parse_client_failure_data")
+ public Object[][] parse_client_failure_data()
+ {
+ return new Object[][]{
+
+ {Byte.class, "fred", "The input value 'fred' is not parseable
as an integer value."},
+
+ {Integer.class, "fred", "The input value 'fred' is not
parseable as an integer value."},
+
+ {Long.class, "fred", "The input value 'fred' is not parseable
as an integer value."},
+
+ {Double.class, "fred", "The input value 'fred' is not
parseable as a numeric value."},
+
+ {Float.class, "fred", "The input value 'fred' is not parseable
as a numeric value."}
+
+ };
+ }
+
+ @Test(dataProvider = "parse_client_failure_data")
+ public void parse_client_failure(Class type, String input, String
expectedMessage)
+ {
+
+ Translator t = _source.get(type);
+
+ try
+ {
+ t.parseClient(input,
_messagesSource.getValidationMessages(Locale.ENGLISH));
+ unreachable();
+ }
+ catch (ValidationException ex)
+ {
+ assertEquals(ex.getMessage(), expectedMessage);
+ }
+
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry5.ipr
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry5.ipr?rev=612958&r1=612957&r2=612958&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry5.ipr (original)
+++ tapestry/tapestry5/trunk/tapestry5.ipr Thu Jan 17 12:09:49 2008
@@ -50,7 +50,7 @@
</component>
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
- <option name="DEPLOY_AFTER_MAKE" value="1" />
+ <option name="DEPLOY_AFTER_MAKE" value="2" />
<excludeFromCompile>
<directory url="file://$PROJECT_DIR$/quickstart/src/main/resources"
includeSubdirectories="true" />
</excludeFromCompile>