Revision: 358
Author: tfenne
Date: 2006-08-05 11:39:50 -0700 (Sat, 05 Aug 2006)
ViewCVS: http://svn.sourceforge.net/stripes/?rev=358&view=rev
Log Message:
-----------
Added type converters for String/Char/Object to make the type converter stuff
easier to work with.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
Added Paths:
-----------
trunk/stripes/src/net/sourceforge/stripes/validation/CharacterTypeConverter.java
trunk/stripes/src/net/sourceforge/stripes/validation/ObjectTypeConverter.java
trunk/stripes/src/net/sourceforge/stripes/validation/StringTypeConverter.java
Modified:
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
2006-08-04 03:31:40 UTC (rev 357)
+++
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
2006-08-05 18:39:50 UTC (rev 358)
@@ -926,9 +926,6 @@
if (converter != null) {
retval = converter.convert(values[i], propertyType,
errors);
}
- else if (propertyType.isAssignableFrom(String.class)) {
- retval = values[i];
- }
else {
Constructor constructor =
propertyType.getConstructor(String.class);
if (constructor != null) {
Added:
trunk/stripes/src/net/sourceforge/stripes/validation/CharacterTypeConverter.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/validation/CharacterTypeConverter.java
(rev 0)
+++
trunk/stripes/src/net/sourceforge/stripes/validation/CharacterTypeConverter.java
2006-08-05 18:39:50 UTC (rev 358)
@@ -0,0 +1,47 @@
+/* Copyright 2005-2006 Tim Fennell
+ *
+ * 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 net.sourceforge.stripes.validation;
+
+import java.util.Locale;
+import java.util.Collection;
+
+/**
+ * Simple type converter that converts the input String to a Character by
returning
+ * the first character in the String.
+ *
+ * @author Tim Fennell
+ * @since Stripes 1.4
+ */
+public class CharacterTypeConverter implements TypeConverter<Character> {
+ /** Does nothing. */
+ public void setLocale(Locale locale) { }
+
+ /**
+ * Converts the input String to a Character by taking the first character
in the
+ * String and returning it. If the String is null or empty (this should
never happen)
+ * then it will return the Character represented by ordinal 0, aka the
null character.
+ *
+ * @param input the String to convert into a single Character
+ * @param targetType the type to convert to
+ */
+ public Character convert(String input, Class<? extends Character>
targetType, Collection<ValidationError> errors) {
+ if (input != null && !"".equals(input)) {
+ return input.charAt(0);
+ }
+ else {
+ return '\0';
+ }
+ }
+}
Modified:
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
2006-08-04 03:31:40 UTC (rev 357)
+++
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
2006-08-05 18:39:50 UTC (rev 358)
@@ -61,6 +61,11 @@
converters.put(Date.class, DateTypeConverter.class);
converters.put(BigInteger.class, BigIntegerTypeConverter.class);
converters.put(BigDecimal.class, BigDecimalTypeConverter.class);
+
+ // Now some less useful, but still helpful converters
+ converters.put(String.class, StringTypeConverter.class);
+ converters.put(Object.class, ObjectTypeConverter.class);
+ converters.put(Character.class, CharacterTypeConverter.class);
}
/** Provides subclasses with access to the configuration provided at
initialization. */
Added:
trunk/stripes/src/net/sourceforge/stripes/validation/ObjectTypeConverter.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/validation/ObjectTypeConverter.java
(rev 0)
+++
trunk/stripes/src/net/sourceforge/stripes/validation/ObjectTypeConverter.java
2006-08-05 18:39:50 UTC (rev 358)
@@ -0,0 +1,35 @@
+/* Copyright 2005-2006 Tim Fennell
+ *
+ * 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 net.sourceforge.stripes.validation;
+
+import java.util.Locale;
+import java.util.Collection;
+
+/**
+ * A dummy type converter that targets the Object type by simply returning the
input
+ * String without any modifications.
+ *
+ * @author Tim Fennell
+ * @since Stripes 1.4
+ */
+public class ObjectTypeConverter implements TypeConverter<Object> {
+ /** Does Nothing */
+ public void setLocale(Locale locale) { }
+
+ /** Simple returns the input String un-modified in any way. */
+ public Object convert(String input, Class<? extends Object> targetType,
Collection<ValidationError> errors) {
+ return input;
+ }
+}
Added:
trunk/stripes/src/net/sourceforge/stripes/validation/StringTypeConverter.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/validation/StringTypeConverter.java
(rev 0)
+++
trunk/stripes/src/net/sourceforge/stripes/validation/StringTypeConverter.java
2006-08-05 18:39:50 UTC (rev 358)
@@ -0,0 +1,35 @@
+/* Copyright 2005-2006 Tim Fennell
+ *
+ * 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 net.sourceforge.stripes.validation;
+
+import java.util.Locale;
+import java.util.Collection;
+
+/**
+ * A dummy type converter that targets the String type by simply returning the
input
+ * String without any modifications.
+ *
+ * @author Tim Fennell
+ * @since Stripes 1.4
+ */
+public class StringTypeConverter implements TypeConverter<String> {
+ /** Does Nothing */
+ public void setLocale(Locale locale) { }
+
+ /** Simple returns the input String un-modified in any way. */
+ public String convert(String input, Class<? extends String> targetType,
Collection<ValidationError> errors) {
+ return input;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development