You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/01/23 17:44:58 UTC
svn commit: r614581 [3/3] - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry/internal/
tapestry-core/src/main/java/org/apache/tapestry/internal/bindings/
tapestry-core/src/main/java/org/apache/tapestry/internal/services/ ta...
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java?rev=614581&r1=614580&r2=614581&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java Wed Jan 23 08:44:46 2008
@@ -55,7 +55,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
ComponentResources resources = cpe.getComponentResources();
@@ -85,7 +85,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
ComponentResources resources = cpe.getComponentResources();
@@ -115,7 +115,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
ComponentResources resources = cpe.getComponentResources();
assertFalse(resources.isBound("fred"));
@@ -142,7 +142,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
cpe.addBlock("myblock", block1);
@@ -179,7 +179,7 @@
replay();
- ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, null);
cpe.bindParameter("barney", binding);
@@ -207,7 +207,7 @@
replay();
- ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, ins, null);
cpe.containingPageDidLoad();
@@ -251,8 +251,7 @@
replay();
- ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, container, "myid", null, ins, coercer, null,
- null, l);
+ ComponentPageElementImpl cpe = new ComponentPageElementImpl(page, container, "myid", null, ins, l, null);
try
{
@@ -286,7 +285,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
assertFalse(cpe.getComponentResources().isInvariant("fred"));
@@ -304,8 +303,8 @@
Page page = newPage(PAGE_NAME);
Component component = mockComponent();
ComponentModel model = mockComponentModel();
- TypeCoercer coercer = mockTypeCoercer();
Binding binding = mockBinding();
+ PageResources resources = mockPageResources();
train_getSupportsInformalParameters(model, true);
@@ -317,11 +316,11 @@
train_get(binding, boundValue);
- train_coerce(coercer, boundValue, Long.class, boundValue);
+ train_coerce(resources, boundValue, Long.class, boundValue);
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, resources);
cpe.bindParameter("barney", binding);
@@ -330,13 +329,14 @@
verify();
}
+
@Test
public void write_binding()
{
Page page = newPage(PAGE_NAME);
Component component = mockComponent();
ComponentModel model = mockComponentModel();
- TypeCoercer coercer = mockTypeCoercer();
+ PageResources resources = mockPageResources();
Binding binding = mockBinding();
Instantiator ins = newInstantiator(component, model);
@@ -347,13 +347,13 @@
expect(binding.getBindingType()).andReturn(Integer.class);
- train_coerce(coercer, 23, Integer.class, 23);
+ train_coerce(resources, 23, Integer.class, 23);
binding.set(23);
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, resources);
cpe.bindParameter("barney", binding);
@@ -374,7 +374,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
try
{
@@ -407,7 +407,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
cpe.addEmbeddedElement(childElement);
@@ -440,7 +440,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
cpe.addEmbeddedElement(child1);
@@ -476,7 +476,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
cpe.addMixin(mixinIns);
@@ -502,7 +502,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
cpe.addMixin(mixinIns);
@@ -538,7 +538,7 @@
replay();
- ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null, null);
+ ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, null);
cpe.addMixin(mixinInstantiator);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java?rev=614581&r1=614580&r2=614581&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImplTest.java Wed Jan 23 08:44:46 2008
@@ -45,8 +45,7 @@
replay();
- InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, coercer,
- null, null);
+ InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null);
resources.renderInformalParameters(writer);
@@ -73,8 +72,7 @@
replay();
- InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, coercer,
- null, null);
+ InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null);
resources.bindParameter("fred", binding);
@@ -90,11 +88,11 @@
Component component = mockComponent();
Instantiator ins = mockInstantiator(component);
MarkupWriter writer = mockMarkupWriter();
- TypeCoercer coercer = mockTypeCoercer();
ComponentModel model = mockComponentModel();
Binding binding = mockBinding();
Object rawValue = new Object();
String convertedValue = "*converted*";
+ PageResources pageResources = mockPageResources();
train_getNestedId(element, "foo.bar");
@@ -104,14 +102,14 @@
train_get(binding, rawValue);
- train_coerce(coercer, rawValue, String.class, convertedValue);
+ train_coerce(pageResources, rawValue, String.class, convertedValue);
writer.attributes("fred", convertedValue);
replay();
- InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, coercer,
- null, null);
+ InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins,
+ pageResources);
resources.bindParameter("fred", binding);
@@ -138,7 +136,7 @@
replay();
- ComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null, null, null);
+ ComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null);
resources.storeRenderVariable("myRenderVar", value);
@@ -171,7 +169,7 @@
replay();
- ComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null, null, null);
+ ComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null);
resources.storeRenderVariable("fred", "FRED");
resources.storeRenderVariable("barney", "BARNEY");
@@ -209,8 +207,7 @@
replay();
- InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null, null,
- null);
+ InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null);
resources.storeRenderVariable("fred", "FRED");
resources.storeRenderVariable("barney", "BARNEY");
@@ -249,8 +246,7 @@
replay();
- InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null, null,
- null);
+ InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, ins, null);
try
@@ -285,8 +281,7 @@
replay();
- InternalComponentResources resources = new InternalComponentResourcesImpl(page, element, null, ins, null, null,
- null);
+ InternalComponentResources resources = new InternalComponentResourcesImpl(page, element, null, ins, null);
resources.addPageLifecycleListener(listener);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?rev=614581&r1=614580&r2=614581&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java Wed Jan 23 08:44:46 2008
@@ -26,6 +26,7 @@
import org.apache.tapestry.internal.structure.ComponentPageElement;
import org.apache.tapestry.internal.structure.Page;
import org.apache.tapestry.internal.structure.PageElement;
+import org.apache.tapestry.internal.structure.PageResources;
import org.apache.tapestry.ioc.*;
import org.apache.tapestry.ioc.def.ContributionDef;
import org.apache.tapestry.ioc.def.ModuleDef;
@@ -239,12 +240,6 @@
expect(model.getComponentClassName()).andReturn(className).atLeastOnce();
}
- protected final void train_newRenderBodyElement(PageElementFactory elementFactory, ComponentPageElement component,
- PageElement body)
- {
- expect(elementFactory.newRenderBodyElement(component)).andReturn(body);
- }
-
protected final PageElement mockPageElement()
{
return newMock(PageElement.class);
@@ -322,9 +317,10 @@
}
protected final void train_newRootComponentElement(PageElementFactory elementFactory, String className,
- ComponentPageElement rootElement)
+ ComponentPageElement rootElement, Locale locale)
{
- expect(elementFactory.newRootComponentElement(isA(Page.class), eq(className))).andReturn(rootElement);
+ expect(elementFactory.newRootComponentElement(isA(Page.class), eq(className), eq(locale))).andReturn(
+ rootElement);
}
protected final void train_getModel(Instantiator ins, ComponentModel model)
@@ -582,5 +578,21 @@
protected final void train_getRenderingPage(PageRenderQueue queue, Page page)
{
expect(queue.getRenderingPage()).andReturn(page);
+ }
+
+ protected final PageResources mockPageResources()
+ {
+ return newMock(PageResources.class);
+ }
+
+ protected final void train_toClass(PageResources resources, String className, Class toClass)
+ {
+ expect(resources.toClass(className)).andReturn(toClass).atLeastOnce();
+ }
+
+ protected final <S, T> void train_coerce(PageResources pageResources, S input, Class<T> expectedType,
+ T coercedValue)
+ {
+ expect(pageResources.coerce(input, expectedType)).andReturn(coercedValue);
}
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/services/TypeCoercer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/services/TypeCoercer.java?rev=614581&r1=614580&r2=614581&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/services/TypeCoercer.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/services/TypeCoercer.java Wed Jan 23 08:44:46 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 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.
@@ -15,17 +15,20 @@
package org.apache.tapestry.ioc.services;
/**
- * Makes use of {@link Coercion}s (via {@link CoercionTuple}s) to convert between an input value
- * (of some specific type) and a desired output type. Smart about coercing, even if it requires
- * multiple coercing steps (i.e., via an intermediate type, such as String).
+ * Makes use of {@link Coercion}s (via {@link CoercionTuple}s) to convert between an input value (of some specific type)
+ * and a desired output type. Smart about coercing, even if it requires multiple coercing steps (i.e., via an
+ * intermediate type, such as String).
*/
public interface TypeCoercer
{
/**
- * Performs a coercion from an input type to a desired output type. When the target type is a
- * primitive, the actual conversion will be to the equivalent wrapper type. In some cases, the
- * TypeCoercer will need to search for an appropriate coercion, and may even combine existing
- * coercions to form new ones; in those cases, the results of the search are cached.
+ * Performs a coercion from an input type to a desired output type. When the target type is a primitive, the actual
+ * conversion will be to the equivalent wrapper type. In some cases, the TypeCoercer will need to search for an
+ * appropriate coercion, and may even combine existing coercions to form new ones; in those cases, the results of
+ * the search are cached.
+ * <p/>
+ * <p/>
+ * The TypeCoercer also caches the results of a coercion search.
*
* @param <S> source type (input)
* @param <T> target type (output)
@@ -36,16 +39,14 @@
<S, T> T coerce(S input, Class<T> targetType);
/**
- * Used primarily inside test suites, this method performs the same steps as
- * {@link #coerce(Object, Class)}, but returns a string describing the series of coercision,
- * such as "Object --> String --> Long --> Integer".
+ * Used primarily inside test suites, this method performs the same steps as {@link #coerce(Object, Class)}, but
+ * returns a string describing the series of coercision, such as "Object --> String --> Long --> Integer".
*
* @param <S> source type (input)
* @param <T> target type (output)
* @param inputType the source coercion type (use void.class for coercions from null)
* @param targetType defines the target type
- * @return a string identifying the series of coercions, or the empty string if no coercion is
- * necessary
+ * @return a string identifying the series of coercions, or the empty string if no coercion is necessary
*/
<S, T> String explain(Class<S> inputType, Class<T> targetType);
Added: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/ExceptionUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/ExceptionUtils.java?rev=614581&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/ExceptionUtils.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/ExceptionUtils.java Wed Jan 23 08:44:46 2008
@@ -0,0 +1,45 @@
+// 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.ioc.util;
+
+/**
+ * Contains static methods useful for manipulating exceptions.
+ */
+public class ExceptionUtils
+{
+ /**
+ * Locates a particular type of exception, working its way via the cause property of each exception in the exception
+ * stack.
+ *
+ * @param t the outermost exception
+ * @param type the type of exception to search for
+ * @return the first exception of the given type, if found, or null
+ */
+ public static <T extends Throwable> T findCause(Throwable t, Class<T> type)
+ {
+ Throwable current = t;
+
+ while (current != null)
+ {
+ if (type.isInstance(current)) return type.cast(current);
+
+ // Not a match, work down.
+
+ current = current.getCause();
+ }
+
+ return null;
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/ExceptionUtilsTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/ExceptionUtilsTest.java?rev=614581&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/ExceptionUtilsTest.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/util/ExceptionUtilsTest.java Wed Jan 23 08:44:46 2008
@@ -0,0 +1,40 @@
+// 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.ioc.util;
+
+import org.apache.tapestry.ioc.internal.util.TapestryException;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class ExceptionUtilsTest extends Assert
+{
+ @Test
+ public void find_cause_with_match()
+ {
+ TapestryException inner = new TapestryException("foo", null);
+
+ RuntimeException outer = new RuntimeException(inner);
+
+ assertSame(ExceptionUtils.findCause(outer, TapestryException.class), inner);
+ }
+
+ @Test
+ public void find_cause_no_match()
+ {
+ RuntimeException re = new RuntimeException("No cause for you!");
+
+ assertNull(ExceptionUtils.findCause(re, TapestryException.class));
+ }
+}