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 2011/04/16 00:18:09 UTC
svn commit: r1092829 - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry5/internal/services/
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services...
Author: hlship
Date: Fri Apr 15 22:18:09 2011
New Revision: 1092829
URL: http://svn.apache.org/viewvc?rev=1092829&view=rev
Log:
TAP5-853: Reimplement PipelineBuilder using PlasticProxyFactory
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilder.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodIterator.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodSignature.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/BodyBuilder.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilderTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java?rev=1092829&r1=1092828&r2=1092829&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PropertyConduitSourceImpl.java Fri Apr 15 22:18:09 2011
@@ -55,7 +55,6 @@ import org.apache.tapestry5.ioc.internal
import org.apache.tapestry5.ioc.internal.util.GenericsUtils;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.services.ClassPropertyAdapter;
-import org.apache.tapestry5.ioc.services.MethodSignature;
import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
import org.apache.tapestry5.ioc.services.PropertyAccess;
import org.apache.tapestry5.ioc.services.PropertyAdapter;
@@ -1112,7 +1111,7 @@ public class PropertyConduitSourceImpl i
Type returnType = GenericsUtils.extractActualType(activeType, method);
- return new Term(returnType, new MethodSignature(method).getUniqueId(), new AnnotationProvider()
+ return new Term(returnType, toUniqueId(method), new AnnotationProvider()
{
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
{
@@ -1394,4 +1393,19 @@ public class PropertyConduitSourceImpl i
return new NullPointerException(message);
}
+ private static String toUniqueId(Method method)
+ {
+ StringBuilder builder = new StringBuilder(method.getName()).append("(");
+ String sep = "";
+
+ for (Class parameterType : method.getParameterTypes())
+ {
+ builder.append(sep);
+ builder.append(PlasticUtils.toTypeName(parameterType));
+
+ sep = ",";
+ }
+
+ return builder.append(")").toString();
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilder.java?rev=1092829&r1=1092828&r2=1092829&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilder.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilder.java Fri Apr 15 22:18:09 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2011 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
+// 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,
@@ -14,19 +14,29 @@
package org.apache.tapestry5.ioc.internal.services;
+import static java.lang.String.format;
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
-import org.apache.tapestry5.ioc.services.ClassFab;
-import org.apache.tapestry5.ioc.services.ClassFactory;
-import org.apache.tapestry5.ioc.services.MethodIterator;
-import org.apache.tapestry5.ioc.services.MethodSignature;
-import org.slf4j.Logger;
-import static java.lang.String.format;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.List;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.services.ClassFab;
+import org.apache.tapestry5.ioc.services.ClassFactory;
+import org.apache.tapestry5.ioc.services.MethodIterator;
+import org.apache.tapestry5.ioc.services.MethodSignature;
+import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
+import org.apache.tapestry5.plastic.ClassInstantiator;
+import org.apache.tapestry5.plastic.InstructionBuilder;
+import org.apache.tapestry5.plastic.InstructionBuilderCallback;
+import org.apache.tapestry5.plastic.PlasticClass;
+import org.apache.tapestry5.plastic.PlasticClassTransformer;
+import org.apache.tapestry5.plastic.PlasticField;
+import org.apache.tapestry5.plastic.PlasticMethod;
+import org.slf4j.Logger;
+
/**
* Used by the {@link org.apache.tapestry5.ioc.internal.services.PipelineBuilderImpl} to create bridge classes and to
* create instances of bridge classes. A bridge class implements the <em>service</em> interface. Within the chain,
@@ -40,30 +50,68 @@ class BridgeBuilder<S, F>
private final Class<F> filterInterface;
- private final ClassFab classFab;
-
private final FilterMethodAnalyzer filterMethodAnalyzer;
- private Constructor constructor;
+ private final PlasticProxyFactory proxyFactory;
+
+ private ClassInstantiator<S> instantiator;
- BridgeBuilder(Logger logger, Class<S> serviceInterface, Class<F> filterInterface,
- ClassFactory classFactory)
+ BridgeBuilder(Logger logger, Class<S> serviceInterface, Class<F> filterInterface, ClassFactory classFactory,
+ PlasticProxyFactory proxyFactory)
+ {
+ this(logger, serviceInterface, filterInterface, proxyFactory);
+ }
+
+ BridgeBuilder(Logger logger, Class<S> serviceInterface, Class<F> filterInterface, PlasticProxyFactory proxyFactory)
{
this.logger = logger;
this.serviceInterface = serviceInterface;
this.filterInterface = filterInterface;
- classFab = classFactory.newClass(this.serviceInterface);
+ this.proxyFactory = proxyFactory;
filterMethodAnalyzer = new FilterMethodAnalyzer(serviceInterface);
}
- private void createClass()
+ /**
+ * Instantiates a bridge object.
+ *
+ * @param nextBridge
+ * the next Bridge object in the pipeline, or the terminator service
+ * @param filter
+ * the filter object for this step of the pipeline
+ */
+ public S instantiateBridge(S nextBridge, F filter)
+ {
+ if (instantiator == null)
+ createInstantiator();
+
+ return instantiator.with(filterInterface, filter).with(serviceInterface, nextBridge).newInstance();
+ }
+
+ private void createInstantiator()
{
- List<MethodSignature> serviceMethods = newList();
- List<MethodSignature> filterMethods = newList();
+ instantiator = proxyFactory.createProxy(serviceInterface, new PlasticClassTransformer()
+ {
+ public void transform(PlasticClass plasticClass)
+ {
+ PlasticField filterField = plasticClass.introduceField(filterInterface, "filter")
+ .injectFromInstanceContext();
+ PlasticField nextField = plasticClass.introduceField(serviceInterface, "next")
+ .injectFromInstanceContext();
- createInfrastructure();
+ processMethods(plasticClass, filterField, nextField);
+
+ plasticClass.addToString(String.format("<PipelineBridge from %s to %s>", serviceInterface.getName(),
+ filterInterface.getName()));
+ }
+ });
+ }
+
+ private void processMethods(PlasticClass plasticClass, PlasticField filterField, PlasticField nextField)
+ {
+ List<MethodSignature> serviceMethods = CollectionFactory.newList();
+ List<MethodSignature> filterMethods = CollectionFactory.newList();
MethodIterator mi = new MethodIterator(serviceInterface);
@@ -72,8 +120,6 @@ class BridgeBuilder<S, F>
serviceMethods.add(mi.next());
}
- boolean toStringMethodExists = mi.getToString();
-
mi = new MethodIterator(filterInterface);
while (mi.hasNext())
@@ -85,56 +131,10 @@ class BridgeBuilder<S, F>
{
MethodSignature ms = serviceMethods.remove(0);
- addBridgeMethod(ms, filterMethods);
+ addBridgeMethod(plasticClass, filterField, nextField, ms, filterMethods);
}
reportExtraFilterMethods(filterMethods);
-
- if (!toStringMethodExists)
- {
- String toString = format(
- "<PipelineBridge from %s to %s>",
- serviceInterface.getName(),
- filterInterface.getName());
- classFab.addToString(toString);
- }
-
- Class bridgeClass = classFab.createClass();
-
- constructor = bridgeClass.getConstructors()[0];
- }
-
- private void createInfrastructure()
- {
- classFab.addField("_next", Modifier.PRIVATE | Modifier.FINAL, serviceInterface);
- classFab.addField("_filter", Modifier.PRIVATE | Modifier.FINAL, filterInterface);
-
- classFab.addConstructor(new Class[]
- { serviceInterface, filterInterface }, null, "{ _next = $1; _filter = $2; }");
-
- classFab.addInterface(serviceInterface);
- }
-
- /**
- * Instantiates a bridge object.
- *
- * @param nextBridge the next Bridge object in the pipeline, or the terminator service
- * @param filter the filter object for this step of the pipeline
- */
- public S instantiateBridge(S nextBridge, F filter)
- {
- if (constructor == null) createClass();
-
- try
- {
- Object instance = constructor.newInstance(nextBridge, filter);
-
- return serviceInterface.cast(instance);
- }
- catch (Exception ex)
- {
- throw new RuntimeException(ex);
- }
}
private void reportExtraFilterMethods(List filterMethods)
@@ -145,8 +145,7 @@ class BridgeBuilder<S, F>
{
MethodSignature ms = (MethodSignature) i.next();
- logger.error(ServiceMessages
- .extraFilterMethod(ms, filterInterface, serviceInterface));
+ logger.error(ServiceMessages.extraFilterMethod(ms, filterInterface, serviceInterface));
}
}
@@ -157,8 +156,11 @@ class BridgeBuilder<S, F>
* The matching method signature from the list of filterMethods is removed and code generation strategies for making
* the two methods call each other are added.
*/
- private void addBridgeMethod(MethodSignature ms, List filterMethods)
+ private void addBridgeMethod(PlasticClass plasticClass, PlasticField filterField, PlasticField nextField,
+ final MethodSignature ms, List filterMethods)
{
+ PlasticMethod method = plasticClass.introduceMethod(ms.getMethod());
+
Iterator i = filterMethods.iterator();
while (i.hasNext())
@@ -169,69 +171,51 @@ class BridgeBuilder<S, F>
if (position >= 0)
{
- addBridgeMethod(position, ms, fms);
+ bridgeServiceMethodToFilterMethod(method, filterField, nextField, position, ms, fms);
i.remove();
return;
}
}
- String message = ServiceMessages.unmatchedServiceMethod(ms, filterInterface);
-
- logger.error(message);
+ method.changeImplementation(new InstructionBuilderCallback()
+ {
+ public void doBuild(InstructionBuilder builder)
+ {
+ String message = ServiceMessages.unmatchedServiceMethod(ms, filterInterface);
- String code = format("throw new %s(\"%s\");", RuntimeException.class.getName(), message);
+ logger.error(message);
- classFab.addMethod(Modifier.PUBLIC, ms, code);
+ builder.throwException(RuntimeException.class, message);
+ }
+ });
}
- /**
- * Adds a method to the class which bridges from the service method to the corresponding method in the filter
- * interface. The next service (either another Bridge, or the terminator at the end of the pipeline) is passed to
- * the filter).
- */
- private void addBridgeMethod(int position, MethodSignature ms, MethodSignature fms)
+ private void bridgeServiceMethodToFilterMethod(PlasticMethod method, final PlasticField filterField,
+ final PlasticField nextField, final int position, MethodSignature ms, final MethodSignature fms)
{
- StringBuilder buffer = new StringBuilder(100);
-
- buffer.append("return ($r) _filter.");
- buffer.append(ms.getName());
- buffer.append("(");
-
- boolean comma = false;
- int filterParameterCount = fms.getParameterTypes().length;
-
- for (int i = 0; i < position; i++)
+ method.changeImplementation(new InstructionBuilderCallback()
{
- if (comma) buffer.append(", ");
-
- buffer.append("$");
- // Add one to the index to get the parameter symbol ($0 is the implicit
- // this parameter).
- buffer.append(i + 1);
-
- comma = true;
- }
-
- if (comma) buffer.append(", ");
-
- // _next is the variable in -this- Bridge that points to the -next- Bridge
- // or the terminator for the pipeline. The filter is expected to reinvoke the
- // method on the _next that's passed to it.
-
- buffer.append("_next");
-
- for (int i = position + 1; i < filterParameterCount; i++)
- {
- buffer.append(", $");
- buffer.append(i);
- }
+ public void doBuild(InstructionBuilder builder)
+ {
+ builder.loadThis().getField(filterField);
- buffer.append(");");
+ int argumentIndex = 0;
- // This should work, unless the exception types turn out to not be compatble. We still
- // don't do a check on that, and not sure that Javassist does either!
+ for (int i = 0; i < fms.getParameterTypes().length; i++)
+ {
+ if (i == position)
+ {
+ builder.loadThis().getField(nextField);
+ }
+ else
+ {
+ builder.loadArgument(argumentIndex++);
+ }
+ }
- classFab.addMethod(Modifier.PUBLIC, ms, buffer.toString());
+ builder.invoke(fms.getMethod()).returnResult();
+ }
+ });
}
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImpl.java?rev=1092829&r1=1092828&r2=1092829&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PipelineBuilderImpl.java Fri Apr 15 22:18:09 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2011 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
+// 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,
@@ -18,21 +18,24 @@ import org.apache.tapestry5.ioc.services
import org.apache.tapestry5.ioc.services.ClassFactory;
import org.apache.tapestry5.ioc.services.DefaultImplementationBuilder;
import org.apache.tapestry5.ioc.services.PipelineBuilder;
+import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
import org.slf4j.Logger;
import java.util.List;
public class PipelineBuilderImpl implements PipelineBuilder
{
- private final ClassFactory classFactory;
+
+ private final PlasticProxyFactory proxyFactory;
private final DefaultImplementationBuilder defaultImplementationBuilder;
- public PipelineBuilderImpl(@Builtin ClassFactory classFactory,
+ public PipelineBuilderImpl(@Builtin
+ PlasticProxyFactory proxyFactory,
- DefaultImplementationBuilder defaultImplementationBuilder)
+ DefaultImplementationBuilder defaultImplementationBuilder)
{
- this.classFactory = classFactory;
+ this.proxyFactory = proxyFactory;
this.defaultImplementationBuilder = defaultImplementationBuilder;
}
@@ -44,11 +47,12 @@ public class PipelineBuilderImpl impleme
}
public <S, F> S build(Logger logger, Class<S> serviceInterface, Class<F> filterInterface, List<F> filters,
- S terminator)
+ S terminator)
{
- if (filters.isEmpty()) return terminator;
+ if (filters.isEmpty())
+ return terminator;
- BridgeBuilder<S, F> bb = new BridgeBuilder<S, F>(logger, serviceInterface, filterInterface, classFactory);
+ BridgeBuilder<S, F> bb = new BridgeBuilder<S, F>(logger, serviceInterface, filterInterface, proxyFactory);
// The first bridge will point to the terminator.
// Like service decorators, we work deepest (last)
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodIterator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodIterator.java?rev=1092829&r1=1092828&r2=1092829&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodIterator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodIterator.java Fri Apr 15 22:18:09 2011
@@ -1,10 +1,10 @@
-// Copyright 2004, 2005, 2006 The Apache Software Foundation
+// Copyright 2004, 2005, 2006, 2011 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
+// 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,
@@ -24,8 +24,9 @@ import java.util.*;
* Utility used to iterate over the publically visible methods of a class or interface. The MethodIterator understands
* some complications that can occur when a class inherits the same method from multiple interfaces and with slightly
* different signatures (due to the fact that declared thrown exceptions can vary slightly for the "same" method).
- *
+ *
* @see org.apache.tapestry5.ioc.services.MethodSignature#isOverridingSignatureOf(MethodSignature)
+ * @deprecated In 5.3.0, to be removed in a later release
*/
public class MethodIterator
{
@@ -46,7 +47,6 @@ public class MethodIterator
}
};
-
public MethodIterator(Class subjectClass)
{
Method[] methods = subjectClass.getMethods();
@@ -59,7 +59,6 @@ public class MethodIterator
signatures = newList(map.values());
count = signatures.size();
-
Collections.sort(signatures, COMPARATOR);
}
@@ -72,7 +71,8 @@ public class MethodIterator
MethodSignature existing = map.get(uid);
- if (existing == null || sig.isOverridingSignatureOf(existing)) map.put(uid, sig);
+ if (existing == null || sig.isOverridingSignatureOf(existing))
+ map.put(uid, sig);
}
public boolean hasNext()
@@ -84,12 +84,14 @@ public class MethodIterator
* Returns the next method (as a {@link MethodSignature}, returning null when all are exhausted. Each method
* signature is returned exactly once (even if the same method signature is defined in multiple inherited classes or
* interfaces). The method signatures returned in ascending order, according to the "natural ordering".
- *
- * @throws NoSuchElementException if there are no more signatures
+ *
+ * @throws NoSuchElementException
+ * if there are no more signatures
*/
public MethodSignature next()
{
- if (index >= count) throw new NoSuchElementException();
+ if (index >= count)
+ throw new NoSuchElementException();
return signatures.get(index++);
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodSignature.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodSignature.java?rev=1092829&r1=1092828&r2=1092829&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodSignature.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/MethodSignature.java Fri Apr 15 22:18:09 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 2011 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,6 +30,8 @@ import org.apache.tapestry5.ioc.internal
* <p/>
* This version of MethodSignature works with <em>loaded</em> classes, and it usually used in the context of
* {@link org.apache.tapestry5.ioc.services.ClassFab} to create new classes and subclasses.
+ *
+ * @deprecated In 5.3.0, to be removed in a later release
*/
@SuppressWarnings("all")
public class MethodSignature
@@ -44,8 +46,16 @@ public class MethodSignature
private final Class[] exceptionTypes;
+ private final Method method;
+
public MethodSignature(Class returnType, String name, Class[] parameterTypes, Class[] exceptionTypes)
{
+ this(null, returnType, name, parameterTypes, exceptionTypes);
+ }
+
+ private MethodSignature(Method method, Class returnType, String name, Class[] parameterTypes, Class[] exceptionTypes)
+ {
+ this.method = method;
assert returnType != null;
this.returnType = returnType;
assert InternalUtils.isNonBlank(name);
@@ -58,7 +68,7 @@ public class MethodSignature
public MethodSignature(Method m)
{
- this(m.getReturnType(), m.getName(), m.getParameterTypes(), m.getExceptionTypes());
+ this(m, m.getReturnType(), m.getName(), m.getParameterTypes(), m.getExceptionTypes());
}
/**
@@ -75,6 +85,16 @@ public class MethodSignature
}
/**
+ * If this signature was created from a method, return that method.
+ *
+ * @since 5.3.0
+ */
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ /**
* Returns the parameter types for this method. May return null. Caution: do not modify the returned array.
*/
public Class[] getParameterTypes()
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/BodyBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/BodyBuilder.java?rev=1092829&r1=1092828&r2=1092829&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/BodyBuilder.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/BodyBuilder.java Fri Apr 15 22:18:09 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2011 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
+// 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,
@@ -14,10 +14,10 @@
package org.apache.tapestry5.ioc.util;
-import org.apache.tapestry5.ioc.services.MethodSignature;
-
import java.util.Formatter;
+import org.apache.tapestry5.ioc.services.MethodSignature;
+
/**
* Utility class for assembling the <em>body</em> used with Javassist when defining a method or constructor. Basically,
* assists with formatting and with indentation. This makes the code that assembles a method body much simpler ... and
@@ -27,6 +27,8 @@ import java.util.Formatter;
* This class is not threadsafe.
* <p/>
* Most of the methods return the BodyBuilder, to form a fluent interface.
+ *
+ * @deprecated In 5.3/0, to be removed in a later release
*/
public final class BodyBuilder
{
@@ -61,9 +63,11 @@ public final class BodyBuilder
/**
* Adds text to the current line, without ending the line.
- *
- * @param format string format, as per {@link java.util.Formatter}
- * @param args arguments referenced by format specifiers
+ *
+ * @param format
+ * string format, as per {@link java.util.Formatter}
+ * @param args
+ * arguments referenced by format specifiers
*/
public BodyBuilder add(String format, Object... args)
{
@@ -74,9 +78,11 @@ public final class BodyBuilder
/**
* Adds text to the current line and ends the line.
- *
- * @param format string format, as per {@link java.util.Formatter}
- * @param args arguments referenced by format specifiers
+ *
+ * @param format
+ * string format, as per {@link java.util.Formatter}
+ * @param args
+ * arguments referenced by format specifiers
*/
public BodyBuilder addln(String format, Object... args)
{
@@ -93,7 +99,8 @@ public final class BodyBuilder
formatter.format(format, args);
- if (newLine) newline();
+ if (newLine)
+ newline();
return this;
}
@@ -109,7 +116,8 @@ public final class BodyBuilder
*/
public BodyBuilder begin()
{
- if (!atNewLine) newline();
+ if (!atNewLine)
+ newline();
indent();
buffer.append("{");
@@ -125,7 +133,8 @@ public final class BodyBuilder
*/
public BodyBuilder end()
{
- if (!atNewLine) newline();
+ if (!atNewLine)
+ newline();
// TODO: Could check here if nesting depth goes below zero.
@@ -151,9 +160,9 @@ public final class BodyBuilder
}
/**
- * Returns the current contents of the buffer. This value is often passed to methods such as {@link
- * org.apache.tapestry5.ioc.services.ClassFab#addConstructor(Class[], Class[], String)} or {@link
- * org.apache.tapestry5.ioc.services.ClassFab#addMethod(int, MethodSignature, String)}.
+ * Returns the current contents of the buffer. This value is often passed to methods such as
+ * {@link org.apache.tapestry5.ioc.services.ClassFab#addConstructor(Class[], Class[], String)} or
+ * {@link org.apache.tapestry5.ioc.services.ClassFab#addMethod(int, MethodSignature, String)}.
* <p/>
* A BodyBuilder can be used again after invoking toString(), typically by invoking {@link #clear()}.
*/
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilderTest.java?rev=1092829&r1=1092828&r2=1092829&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilderTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/BridgeBuilderTest.java Fri Apr 15 22:18:09 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2011 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
+// 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,
@@ -14,16 +14,23 @@
package org.apache.tapestry5.ioc.internal.services;
+import java.io.Serializable;
+
import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import org.apache.tapestry5.ioc.services.ClassFactory;
+import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
import org.slf4j.Logger;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.io.Serializable;
-
public class BridgeBuilderTest extends IOCInternalTestCase
{
- private ClassFactory classFactory = new ClassFactoryImpl();
+ private PlasticProxyFactory proxyFactory;
+
+ @BeforeClass
+ public void setup()
+ {
+ proxyFactory = getService(PlasticProxyFactory.class);
+ }
@Test
public void standard_interface_and_filter()
@@ -32,8 +39,8 @@ public class BridgeBuilderTest extends I
replay();
- BridgeBuilder<StandardService, StandardFilter> bb = new BridgeBuilder<StandardService, StandardFilter>(
- logger, StandardService.class, StandardFilter.class, classFactory);
+ BridgeBuilder<StandardService, StandardFilter> bb = new BridgeBuilder<StandardService, StandardFilter>(logger,
+ StandardService.class, StandardFilter.class, proxyFactory);
StandardFilter sf = new StandardFilter()
{
@@ -75,8 +82,8 @@ public class BridgeBuilderTest extends I
replay();
- BridgeBuilder<ToStringService, ToStringFilter> bb = new BridgeBuilder<ToStringService, ToStringFilter>(
- logger, ToStringService.class, ToStringFilter.class, classFactory);
+ BridgeBuilder<ToStringService, ToStringFilter> bb = new BridgeBuilder<ToStringService, ToStringFilter>(logger,
+ ToStringService.class, ToStringFilter.class, proxyFactory);
ToStringFilter f = new ToStringFilter()
{
@@ -109,13 +116,12 @@ public class BridgeBuilderTest extends I
ExtraServiceMethod next = newMock(ExtraServiceMethod.class);
Serializable filter = newMock(Serializable.class);
- logger
- .error("Method void extraServiceMethod() has no match in filter interface java.io.Serializable.");
+ logger.error("Method void extraServiceMethod() has no match in filter interface java.io.Serializable.");
replay();
BridgeBuilder<ExtraServiceMethod, Serializable> bb = new BridgeBuilder<ExtraServiceMethod, Serializable>(
- logger, ExtraServiceMethod.class, Serializable.class, classFactory);
+ logger, ExtraServiceMethod.class, Serializable.class, proxyFactory);
ExtraServiceMethod esm = bb.instantiateBridge(next, filter);
@@ -126,8 +132,7 @@ public class BridgeBuilderTest extends I
}
catch (RuntimeException ex)
{
- assertEquals(
- ex.getMessage(),
+ assertEquals(ex.getMessage(),
"Method void extraServiceMethod() has no match in filter interface java.io.Serializable.");
}
@@ -141,15 +146,14 @@ public class BridgeBuilderTest extends I
Serializable next = newMock(Serializable.class);
ExtraFilterMethod filter = newMock(ExtraFilterMethod.class);
- logger
- .error("Method void extraFilterMethod() of filter interface "
- + "org.apache.tapestry5.ioc.internal.services.ExtraFilterMethod does not have a matching method "
- + "in java.io.Serializable.");
+ logger.error("Method void extraFilterMethod() of filter interface "
+ + "org.apache.tapestry5.ioc.internal.services.ExtraFilterMethod does not have a matching method "
+ + "in java.io.Serializable.");
replay();
- BridgeBuilder<Serializable, ExtraFilterMethod> bb = new BridgeBuilder<Serializable, ExtraFilterMethod>(
- logger, Serializable.class, ExtraFilterMethod.class, classFactory);
+ BridgeBuilder<Serializable, ExtraFilterMethod> bb = new BridgeBuilder<Serializable, ExtraFilterMethod>(logger,
+ Serializable.class, ExtraFilterMethod.class, proxyFactory);
assertNotNull(bb.instantiateBridge(next, filter));
@@ -163,8 +167,8 @@ public class BridgeBuilderTest extends I
replay();
- BridgeBuilder<MiddleService, MiddleFilter> bb = new BridgeBuilder<MiddleService, MiddleFilter>(
- logger, MiddleService.class, MiddleFilter.class, classFactory);
+ BridgeBuilder<MiddleService, MiddleFilter> bb = new BridgeBuilder<MiddleService, MiddleFilter>(logger,
+ MiddleService.class, MiddleFilter.class, proxyFactory);
MiddleFilter mf = new MiddleFilter()
{