Author: hlship
Date: Fri Jan 22 22:16:45 2010
New Revision: 902294
URL: http://svn.apache.org/viewvc?rev=902294&view=rev
Log:
Remove ParameterAccess, as it has been eclipsed by ParameterConduit
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/ParameterAccess.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalComponentResources.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ParameterWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalComponentResources.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalComponentResources.java?rev=902294&r1=902293&r2=902294&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalComponentResources.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalComponentResources.java
Fri Jan 22 22:16:45 2010
@@ -19,6 +19,7 @@
import org.apache.tapestry5.internal.structure.Page;
import org.apache.tapestry5.internal.structure.PageResetListener;
import org.apache.tapestry5.internal.transform.ParameterConduit;
+import org.apache.tapestry5.runtime.PageLifecycleListener;
import org.apache.tapestry5.runtime.RenderQueue;
/**
@@ -63,25 +64,27 @@
void queueRender(RenderQueue queue);
/**
- * Gets access object for the parameter.
- *
- * @param parameterName
- * @return object used to read and update the parameter
- */
- ParameterAccess getParameterAccess(String parameterName);
-
- /**
- * Delegates to
- * {...@link
Page#addResetListener(org.apache.tapestry5.internal.structure.PageResetListener)}.
+ * Delegates to {...@link
Page#addResetListener(org.apache.tapestry5.internal.structure.PageResetListener)}.
*
* @param listener
* to register
*/
void addPageResetListener(PageResetListener listener);
- /** @since 5.2.0 */
+ /**
+ * Gets a previously stored ParameterConduit, allowing PCs to be shared
between a component
+ * and a mixin of that component.
+ *
+ * @since 5.2.0
+ */
ParameterConduit getParameterConduit(String parameterName);
- /** @since 5.2.0 */
+ /**
+ * Stores a ParameterConduit for later access. Tthis occurs inside a
component's
+ * {...@link PageLifecycleListener#containingPageDidLoad()} lifecycle
+ * method.
+ *
+ * @since 5.2.0
+ */
void setParameterConduit(String parameterName, ParameterConduit conduit);
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java?rev=902294&r1=902293&r2=902294&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
Fri Jan 22 22:16:45 2010
@@ -1,4 +1,4 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2010 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.
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java?rev=902294&r1=902293&r2=902294&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
Fri Jan 22 22:16:45 2010
@@ -27,19 +27,18 @@
import org.apache.tapestry5.Link;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.internal.InternalComponentResources;
-import org.apache.tapestry5.internal.ParameterAccess;
import org.apache.tapestry5.internal.services.Instantiator;
import org.apache.tapestry5.internal.transform.ParameterConduit;
import org.apache.tapestry5.ioc.AnnotationProvider;
import org.apache.tapestry5.ioc.Location;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.NullAnnotationProvider;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.Defense;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.TapestryException;
import org.apache.tapestry5.model.ComponentModel;
-import org.apache.tapestry5.model.ParameterModel;
import org.apache.tapestry5.runtime.Component;
import org.apache.tapestry5.runtime.PageLifecycleListener;
import org.apache.tapestry5.runtime.RenderQueue;
@@ -71,14 +70,7 @@
// Case insensitive map from parameter name to binding
private Map<String, Binding> bindings;
- // Case insensitive map from parameter name to ParameterAccess
- private Map<String, ParameterAccess> access;
-
- // Case-insensitive map from container-parameter name to ParameterAccess,
for BindParameter.
- // Should only ever be used for mixins.
- private Map<String, ParameterAccess> containerParameterAccess;
-
- // Case insentive map from parameter name to ParameterConduit, used to
support mixins
+ // Case insensitive map from parameter name to ParameterConduit, used to
support mixins
// which need access to the containing component's PC's
private Map<String, ParameterConduit> conduits;
@@ -89,6 +81,8 @@
private static final Object[] EMPTY = new Object[0];
+ private static final AnnotationProvider NULL_ANNOTATION_PROVIDER = new
NullAnnotationProvider();
+
private boolean informalsComputed;
private final boolean mixin;
@@ -151,7 +145,6 @@
component = componentInstantiator.newInstance(this);
}
-
public boolean isMixin()
{
return mixin;
@@ -162,7 +155,6 @@
return element.getLocation();
}
-
public String toString()
{
return String.format("InternalComponentResources[%s]",
getCompleteId());
@@ -235,7 +227,11 @@
public <T> T getInformalParameter(String name, Class<T> type)
{
- return getParameterAccess(name).read(type);
+ Binding binding = getBinding(name);
+
+ Object value = binding == null ? null : binding.get();
+
+ return elementResources.coerce(value, type);
}
public Block getBody()
@@ -266,7 +262,9 @@
public <T extends Annotation> T getParameterAnnotation(String
parameterName,
Class<T> annotationType)
{
- return getParameterAccess(parameterName).getAnnotation(annotationType);
+ Binding binding = getBinding(parameterName);
+
+ return binding == null ? null : binding.getAnnotation(annotationType);
}
public boolean isRendering()
@@ -328,7 +326,9 @@
public Class getBoundType(String parameterName)
{
- return getParameterAccess(parameterName).getBoundType();
+ Binding binding = getBinding(parameterName);
+
+ return binding == null ? null : binding.getBindingType();
}
public Binding getBinding(String parameterName)
@@ -338,7 +338,9 @@
public AnnotationProvider getAnnotationProvider(String parameterName)
{
- return getParameterAccess(parameterName);
+ Binding binding = getBinding(parameterName);
+
+ return binding == null ? NULL_ANNOTATION_PROVIDER : binding;
}
public Logger getLogger()
@@ -493,121 +495,16 @@
page.addLifecycleListener(listener);
}
- public ParameterAccess getParameterAccess(final String parameterName)
- {
- if (access == null)
- access = CollectionFactory.newCaseInsensitiveMap();
-
- ParameterAccess result = access.get(parameterName);
-
- if (result == null)
- {
- result = createParameterAccess(parameterName);
- access.put(parameterName, result);
- }
-
- return result;
- }
-
- private ParameterAccess createParameterAccess(final String parameterName)
- {
- final Binding binding = getBinding(parameterName);
-
- ParameterModel parameterModel =
getComponentModel().getParameterModel(parameterName);
-
- final boolean allowNull = parameterModel == null ? true :
parameterModel.isAllowNull();
-
- final boolean cache = parameterModel == null ? false :
parameterModel.isCached();
-
- return new ParameterAccess()
- {
-
- public boolean isBound()
- {
- return binding != null;
- }
-
- public <T> T read(Class<T> desiredType)
- {
- if (binding == null)
- return null;
-
- T result;
-
- try
- {
- // Will throw NPE if binding is null, but this should
never be called if the
- // parameter is not bound.
-
- Object boundValue = binding.get();
-
- result = elementResources.coerce(boundValue, desiredType);
- }
- catch (Exception ex)
- {
- throw new
TapestryException(StructureMessages.getParameterFailure(
- parameterName, getCompleteId(), ex), binding, ex);
- }
-
- if (result == null && !allowNull)
- throw new TapestryException(
- String
- .format(
- "Parameter '%s' of component %s is
bound to null. This parameter is not allowed to be null.",
- parameterName, getCompleteId()),
binding, null);
-
- return result;
- }
-
- public <T> void write(T parameterValue)
- {
- if (binding == null)
- return;
-
- Class bindingType = binding.getBindingType();
-
- try
- {
- Object coerced = elementResources.coerce(parameterValue,
bindingType);
-
- binding.set(coerced);
- }
- catch (Exception ex)
- {
- throw new
TapestryException(StructureMessages.writeParameterFailure(
- parameterName, getCompleteId(), ex), binding, ex);
- }
- }
-
- public boolean isInvariant()
- {
- return binding != null && binding.isInvariant();
- }
-
- public Class getBoundType()
- {
- return binding == null ? null : binding.getBindingType();
- }
-
- public <T extends Annotation> T getAnnotation(Class<T>
annotationClass)
- {
- return binding == null ? null :
binding.getAnnotation(annotationClass);
- }
- };
- }
-
public void addPageResetListener(PageResetListener listener)
{
page.addResetListener(listener);
}
-
public ParameterConduit getParameterConduit(String parameterName)
{
return InternalUtils.get(conduits, parameterName);
}
-
public void setParameterConduit(String parameterName, ParameterConduit
conduit)
{
if (conduits == null)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java?rev=902294&r1=902293&r2=902294&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java
Fri Jan 22 22:16:45 2010
@@ -45,16 +45,6 @@
InternalUtils.joinSorted(components));
}
- static String getParameterFailure(String parameterName, String
componentId, Throwable cause)
- {
- return MESSAGES.format("get-parameter-failure", parameterName,
componentId, cause);
- }
-
- static String writeParameterFailure(String parameterName, String
componentId, Throwable cause)
- {
- return MESSAGES.format("write-parameter-failure", parameterName,
componentId, cause);
- }
-
static String unknownMixin(String componentId, String mixinClassName)
{
return MESSAGES.format("unknown-mixin", componentId, mixinClassName);
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ParameterWorker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ParameterWorker.java?rev=902294&r1=902293&r2=902294&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ParameterWorker.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ParameterWorker.java
Fri Jan 22 22:16:45 2010
@@ -4,7 +4,7 @@
// 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
+// 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,
@@ -21,10 +21,10 @@
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.internal.InternalComponentResources;
-import org.apache.tapestry5.internal.ParameterAccess;
import org.apache.tapestry5.internal.bindings.LiteralBinding;
import org.apache.tapestry5.internal.services.ComponentClassCache;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.internal.util.TapestryException;
import org.apache.tapestry5.ioc.services.TypeCoercer;
import org.apache.tapestry5.model.MutableComponentModel;
import org.apache.tapestry5.services.BindingSource;
@@ -103,7 +103,7 @@
.defaultPrefix(), enableCaching);
transformation.claimField(fieldName, annotation);
-
+
ComponentValueProvider<ParameterConduit> provider = new
ComponentValueProvider<ParameterConduit>()
{
// Invoked from the components' constructor. This causes a few
issues (it would be
@@ -131,12 +131,12 @@
private Object defaultValue;
- private ParameterAccess parameterAccess;
-
- private Binding defaultBinding;
+ private Binding parameterBinding;
boolean loaded = false;
+ private boolean invariant = false;
+
// Is the current value of the binding cached in the
// value field?
private boolean cached = false;
@@ -156,11 +156,6 @@
icr.setParameterConduit(parameterName, this);
}
- private boolean isInvariant()
- {
- return parameterAccess.isInvariant();
- }
-
private boolean isLoaded()
{
return loaded;
@@ -170,8 +165,7 @@
{
// Assignments before the page is loaded ultimately
exist to set the
// default value for the field. Often this is from the
(original)
- // constructor method,
- // which is converted to a real method as part of the
transformation.
+ // constructor method, which is converted to a real
method as part of the transformation.
if (!loaded)
{
@@ -181,7 +175,7 @@
// This will catch read-only or unbound parameters.
- parameterAccess.write(newValue);
+ writeToBinding(newValue);
value = newValue;
@@ -193,9 +187,63 @@
cached = enableCaching && icr.isRendering();
}
+ private Object readFromBinding()
+ {
+ Object result = null;
+
+ try
+ {
+ Object boundValue = parameterBinding.get();
+
+ result = typeCoercer.coerce(boundValue, fieldType);
+ }
+ catch (RuntimeException ex)
+ {
+ throw new TapestryException(String
+ .format("Failure reading parameter '%s' of
component %s: %s",
+ parameterName,
icr.getCompleteId(), InternalUtils
+ .toMessage(ex)),
parameterBinding, ex);
+ }
+
+ if (result != null || annotation.allowNull())
+ return result;
+
+ throw new TapestryException(
+ String
+ .format(
+ "Parameter '%s' of component
%s is bound to null. This parameter is not allowed to be null.",
+ parameterName,
icr.getCompleteId()),
+ parameterBinding, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void writeToBinding(Object newValue)
+ {
+ // An unbound parameter acts like a simple field
+ // with no side effects.
+
+ if (parameterBinding == null)
+ return;
+
+ try
+ {
+ Object coerced = typeCoercer.coerce(newValue,
parameterBinding
+ .getBindingType());
+
+ parameterBinding.set(coerced);
+ }
+ catch (RuntimeException ex)
+ {
+ throw new TapestryException(String
+ .format("Failure writing parameter '%s' of
component %s: %s",
+ parameterName,
icr.getCompleteId(), InternalUtils
+ .toMessage(ex)), icr, ex);
+ }
+ }
+
public void reset()
{
- if (!isInvariant())
+ if (!invariant)
{
value = defaultValue;
cached = false;
@@ -216,14 +264,14 @@
if (binding != null)
icr.bindParameter(parameterName, binding);
-
- defaultBinding = null;
}
- parameterAccess =
icr.getParameterAccess(parameterName);
+ parameterBinding = icr.getBinding(parameterName);
loaded = true;
+ invariant = parameterBinding != null &&
parameterBinding.isInvariant();
+
value = defaultValue;
}
@@ -240,12 +288,12 @@
// set via a default method on the component, or from
the field's initial
// value.
- return defaultBinding;
+ return parameterBinding;
}
public boolean isBound()
{
- return parameterAccess.isBound();
+ return parameterBinding != null;
}
@SuppressWarnings("unchecked")
@@ -257,13 +305,14 @@
// Read the parameter's binding and cast it to the
// field's type.
- Object result = parameterAccess.read(fieldType);
+
+ Object result = readFromBinding();
// If the value is invariant, we can cache it forever.
Otherwise, we
// we may want to cache it for the remainder of the
component render (if the
// component is currently rendering).
- if (isInvariant() || (enableCaching &&
icr.isRendering()))
+ if (invariant || (enableCaching && icr.isRendering()))
{
value = result;
cached = true;
@@ -279,11 +328,12 @@
if (value instanceof Binding)
{
- defaultBinding = (Binding) value;
+ parameterBinding = (Binding) value;
return;
}
- defaultBinding = new LiteralBinding(null, "default " +
parameterName, value);
+ parameterBinding = new LiteralBinding(null, "default "
+ parameterName,
+ value);
}
};
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties?rev=902294&r1=902293&r2=902294&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties
Fri Jan 22 22:16:45 2010
@@ -1,4 +1,4 @@
-# Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+# Copyright 2006, 2007, 2008, 2009, 2010 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.
@@ -14,8 +14,6 @@
missing-parameters=Parameter(s) '%s' are required for %s, but have not been
bound.
no-such-component=Component %s does not contain an embedded component with id
'%s'. Available components: %s.
-get-parameter-failure=Failure reading parameter '%s' of component %s: %s
-write-parameter-failure=Failure writing parameter '%s' of component %s: %s
unknown-mixin=Component %s does not contain a mixin of type %s.
detach-failure=Listener %s failed during page detach: %s
wrong-phase-result-type=The return value from a render phase event method was
not compatible with the expected return type. Expected is a component, a block
or an instance of %s. \