You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by gv...@apache.org on 2007/07/28 18:59:01 UTC
svn commit: r560570 - in /shale/framework/trunk/shale-core: pom.xml
src/main/java/org/apache/shale/util/ConverterHelper.java
src/test/java/org/apache/shale/util/ConverterHelperTestCase.java
Author: gvanmatre
Date: Sat Jul 28 09:59:00 2007
New Revision: 560570
URL: http://svn.apache.org/viewvc?view=rev&rev=560570
Log:
When the shale-tiger Property annotation is evaluated, a nifty type converter is used to coerce the source data type to the target data type. This utility reuses existing JSF converters outside the context of rendering. It assumes a FacesContext and UIViewRoot. I removed the requirement that a UIViewRoot is needed. Since we are using converters for outside of the component tree, we just need a object that extends UIComponent (SHALE-406).
Added:
shale/framework/trunk/shale-core/src/test/java/org/apache/shale/util/ConverterHelperTestCase.java (with props)
Modified:
shale/framework/trunk/shale-core/pom.xml
shale/framework/trunk/shale-core/src/main/java/org/apache/shale/util/ConverterHelper.java
Modified: shale/framework/trunk/shale-core/pom.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-core/pom.xml?view=diff&rev=560570&r1=560569&r2=560570
==============================================================================
--- shale/framework/trunk/shale-core/pom.xml (original)
+++ shale/framework/trunk/shale-core/pom.xml Sat Jul 28 09:59:00 2007
@@ -64,6 +64,21 @@
</dependency>
<dependency>
+ <groupId>org.apache.myfaces.core</groupId>
+ <artifactId>myfaces-impl</artifactId>
+ <version>1.1.4</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-digester</groupId>
+ <artifactId>commons-digester</artifactId>
+ <version>1.8</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
<groupId>org.apache.shale</groupId>
<artifactId>shale-test</artifactId>
<version>${version}</version>
Modified: shale/framework/trunk/shale-core/src/main/java/org/apache/shale/util/ConverterHelper.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-core/src/main/java/org/apache/shale/util/ConverterHelper.java?view=diff&rev=560570&r1=560569&r2=560570
==============================================================================
--- shale/framework/trunk/shale-core/src/main/java/org/apache/shale/util/ConverterHelper.java (original)
+++ shale/framework/trunk/shale-core/src/main/java/org/apache/shale/util/ConverterHelper.java Sat Jul 28 09:59:00 2007
@@ -18,6 +18,7 @@
package org.apache.shale.util;
import javax.faces.FacesException;
+import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
@@ -65,7 +66,13 @@
if (String.class == type) {
return value;
}
- return converter(context, type).getAsObject(context, context.getViewRoot(), value);
+
+ UIViewRoot root = context.getViewRoot();
+ if (root == null) {
+ root = new UIViewRoot();
+ }
+
+ return converter(context, type).getAsObject(context, root, value);
}
@@ -88,7 +95,12 @@
} else if ((String.class == type) && (value instanceof String)) {
return (String) value;
}
- return converter(context, type).getAsString(context, context.getViewRoot(), value);
+ UIViewRoot root = context.getViewRoot();
+ if (root == null) {
+ root = new UIViewRoot();
+ }
+
+ return converter(context, type).getAsString(context, root, value);
}
Added: shale/framework/trunk/shale-core/src/test/java/org/apache/shale/util/ConverterHelperTestCase.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-core/src/test/java/org/apache/shale/util/ConverterHelperTestCase.java?view=auto&rev=560570
==============================================================================
--- shale/framework/trunk/shale-core/src/test/java/org/apache/shale/util/ConverterHelperTestCase.java (added)
+++ shale/framework/trunk/shale-core/src/test/java/org/apache/shale/util/ConverterHelperTestCase.java Sat Jul 28 09:59:00 2007
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.shale.util;
+
+import java.net.URL;
+import java.util.Locale;
+
+import javax.faces.context.FacesContext;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.config.ConfigParser;
+
+/**
+ * <p>Test case for <code>ConverterHelper</code>.</p>
+ */
+public class ConverterHelperTestCase extends AbstractJsfTestCase {
+
+
+ // ------------------------------------------------------------ Constructors
+
+
+ // Construct a new instance of this test case.
+ public ConverterHelperTestCase(String name) {
+ super(name);
+ }
+
+
+ // ---------------------------------------------------- Overall Test Methods
+
+
+ // Set up instance variables required by this test case.
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ helper = new ConverterHelper();
+ parser = new ConfigParser();
+
+ URL[] urls = parser.getPlatformURLs();
+ // load the runtime converters
+ parser.parse(urls);
+ }
+
+
+ // Return the tests included in this test case.
+ public static Test suite() {
+
+ return (new TestSuite(ConverterHelperTestCase.class));
+
+ }
+
+
+ // Tear down instance variables required by this test case.
+ protected void tearDown() throws Exception {
+
+ helper = null;
+ parser = null;
+ super.tearDown();
+
+ }
+
+
+ // ------------------------------------------------------ Instance Variables
+
+
+ // The instance to be tested
+ ConverterHelper helper = null;
+ ConfigParser parser = null;
+
+
+ // ------------------------------------------------------------ Test Methods
+
+
+ public void testNullViewRoot() {
+
+ assertNotNull(FacesContext.getCurrentInstance().getViewRoot());
+
+ String stringValue = "1";
+
+ // Intentionally set the root to null
+ FacesContext.getCurrentInstance().setViewRoot(null);
+ Long longValue = (Long) helper.asObject(FacesContext.getCurrentInstance(),
+ Long.class, stringValue);
+ assertNotNull(longValue);
+ assertEquals((long) 1, longValue.longValue());
+
+ }
+
+
+
+
+}
Propchange: shale/framework/trunk/shale-core/src/test/java/org/apache/shale/util/ConverterHelperTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-core/src/test/java/org/apache/shale/util/ConverterHelperTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL