Author: hlship
Date: Fri Jan 2 15:10:26 2009
New Revision: 730861
URL: http://svn.apache.org/viewvc?rev=730861&view=rev
Log:
TAP5-430: Annotation for services to indicate that the service should not be
decorated
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/PreventServiceDecoration.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef2.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/PreventDecorationModule.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/Rocket.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/RocketImpl.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ServiceBindingOptions.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ModuleDef.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/Module.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
Fri Jan 2 15:10:26 2009
@@ -199,7 +199,7 @@
//
// ========================================================================
-
+ @PreventServiceDecoration
public static Alias buildAlias(Logger logger,
@Inject
@Symbol(InternalConstants.TAPESTRY_ALIAS_MODE_SYMBOL)
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ServiceBindingOptions.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ServiceBindingOptions.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ServiceBindingOptions.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/ServiceBindingOptions.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2009 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.
@@ -16,7 +16,6 @@
import org.apache.tapestry5.ioc.annotations.EagerLoad;
import org.apache.tapestry5.ioc.annotations.Scope;
-import org.apache.tapestry5.ioc.def.ServiceDef;
import java.lang.annotation.Annotation;
@@ -24,7 +23,7 @@
* Allows additional options for a service to be specified, overriding hard
coded defaults or defaults from annotations
* on the service.
*
- * @see ServiceDef
+ * @see org.apache.tapestry5.ioc.def.ServiceDef2
*/
public interface ServiceBindingOptions
{
@@ -43,6 +42,7 @@
*
* @param scope
* @return this binding options, for further configuration
+ * @see org.apache.tapestry5.ioc.ScopeConstants
*/
ServiceBindingOptions scope(String scope);
@@ -55,6 +55,13 @@
ServiceBindingOptions eagerLoad();
/**
+ * Disallows service decoration for this service.
+ *
+ * @return this binding options, for further configuration
+ */
+ ServiceBindingOptions preventDecoration();
+
+ /**
* Defines the marker interface(s) for the service, used to connect
injections by type at the point of injection
* with a particular service implementation, based on the intersection of
type and marker interface. The containing
* module will sometimes provide a set of default marker annotations for
all services within the module, this method
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/PreventServiceDecoration.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/PreventServiceDecoration.java?rev=730861&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/PreventServiceDecoration.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/annotations/PreventServiceDecoration.java
Fri Jan 2 15:10:26 2009
@@ -0,0 +1,37 @@
+// Copyright 2009 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.tapestry5.ioc.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * Marks a service as not eligible for decoration. This is useful for services
that, if decorated, can cause cycle
+ * dependency errors; for example, {...@link
org.apache.tapestry5.ioc.services.MasterObjectProvider}, or services
+ * <em>contributed to</em> MasterObjectProvider, are good candidates for this
annotation.
+ * <p/>
+ * The annotation can be applied to service implementation class or to a
service builder method in a module class.
+ * <p/>
+ * The annotation may also be placed on a module class, to indicate that all
services defined for the module should not
+ * allow decoration.
+ *
+ * @see org.apache.tapestry5.ioc.def.ServiceDef#isPreventDecoration()
+ * @since 5.1.0.0
+ */
+...@target({ElementType.TYPE, ElementType.METHOD})
+...@retention(RetentionPolicy.RUNTIME)
+...@documented
+public @interface PreventServiceDecoration
+{
+}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ModuleDef.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ModuleDef.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ModuleDef.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ModuleDef.java
Fri Jan 2 15:10:26 2009
@@ -30,9 +30,10 @@
Set<String> getServiceIds();
/**
- * Returns a service definition via the service's id.
+ * Returns a service definition via the service's id. Ideally, the
returned value should be an instance of {...@link
+ * org.apache.tapestry5.ioc.def.ServiceDef2}, and will be converted to
such if necessary.
*
- * @param serviceId the id of the service to retrieve
+ * @param serviceId the id of the service to retrieve (case is ignored)
* @return service definition or null if it doesn't exist
*/
ServiceDef getServiceDef(String serviceId);
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2009 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.
@@ -20,7 +20,8 @@
import java.util.Set;
/**
- * Service definition derived, by default, from a service builder method.
+ * Service definition derived, by default, from a service builder method. This
has been extended in Tapestry 5.1 with
+ * {...@link org.apache.tapestry5.ioc.def.ServiceDef2}, which adds additional
methods.
*/
public interface ServiceDef
{
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef2.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef2.java?rev=730861&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef2.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/def/ServiceDef2.java
Fri Jan 2 15:10:26 2009
@@ -0,0 +1,27 @@
+// Copyright 2009 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.tapestry5.ioc.def;
+
+/**
+ * Extension to {...@link org.apache.tapestry5.ioc.def.ServiceDef} containing
new methods added for Tapestry 5.1.
+ */
+public interface ServiceDef2 extends ServiceDef
+{
+ /**
+ * Returns true if the service should not be decorated. Most services
allow decoration, unless the {...@link
+ * org.apache.tapestry5.ioc.annotations.PreventServiceDecoration}
annotation is present.
+ */
+ boolean isPreventDecoration();
+}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
Fri Jan 2 15:10:26 2009
@@ -112,8 +112,10 @@
methods.removeAll(OBJECT_METHODS);
- grind(methods);
- bind(methods);
+ boolean modulePreventsServiceDecoration =
moduleClass.getAnnotation(PreventServiceDecoration.class) != null;
+
+ grind(methods, modulePreventsServiceDecoration);
+ bind(methods, modulePreventsServiceDecoration);
if (methods.isEmpty()) return;
@@ -147,7 +149,7 @@
return serviceDefs.get(serviceId);
}
- private void grind(Set<Method> remainingMethods)
+ private void grind(Set<Method> remainingMethods, boolean
modulePreventsServiceDecoration)
{
Method[] methods = moduleClass.getMethods();
@@ -173,7 +175,7 @@
if (name.startsWith(BUILD_METHOD_NAME_PREFIX))
{
- addServiceDef(m);
+ addServiceDef(m, modulePreventsServiceDecoration);
remainingMethods.remove(m);
continue;
}
@@ -273,7 +275,7 @@
/**
* Invoked for public methods that have the proper prefix.
*/
- private void addServiceDef(final Method method)
+ private void addServiceDef(final Method method, boolean
modulePreventsServiceDecoration)
{
String serviceId = stripMethodPrefix(method, BUILD_METHOD_NAME_PREFIX);
@@ -294,6 +296,9 @@
String scope = extractServiceScope(method);
boolean eagerLoad = method.isAnnotationPresent(EagerLoad.class);
+ boolean preventDecoration = modulePreventsServiceDecoration ||
+ method.getAnnotation(PreventServiceDecoration.class) != null;
+
ObjectCreatorSource source = new ObjectCreatorSource()
{
public ObjectCreator constructCreator(ServiceBuilderResources
resources)
@@ -310,7 +315,8 @@
Set<Class> markers = newSet(defaultMarkers);
markers.addAll(extractMarkers(method));
- ServiceDefImpl serviceDef = new ServiceDefImpl(returnType, serviceId,
markers, scope, eagerLoad, source);
+ ServiceDefImpl serviceDef = new ServiceDefImpl(returnType, serviceId,
markers, scope, eagerLoad,
+ preventDecoration,
source);
addServiceDef(serviceDef);
}
@@ -360,8 +366,13 @@
/**
* See if the build class defined a bind method and invoke it.
+ *
+ * @param remainingMethods set of methods as yet unaccounted for
+ * @param modulePreventsServiceDecoration
+ * true if {...@link
org.apache.tapestry5.ioc.annotations.PreventServiceDecoration} on module
+ * class
*/
- private void bind(Set<Method> remainingMethods)
+ private void bind(Set<Method> remainingMethods, boolean
modulePreventsServiceDecoration)
{
Throwable failure;
Method bindMethod = null;
@@ -374,7 +385,8 @@
throw new RuntimeException(
IOCMessages.bindMethodMustBeStatic(InternalUtils.asString(bindMethod,
classFactory)));
- ServiceBinderImpl binder = new ServiceBinderImpl(this, bindMethod,
classFactory, defaultMarkers);
+ ServiceBinderImpl binder = new ServiceBinderImpl(this, bindMethod,
classFactory, defaultMarkers,
+
modulePreventsServiceDecoration);
bindMethod.invoke(null, binder);
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java
Fri Jan 2 15:10:26 2009
@@ -17,6 +17,7 @@
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.def.ContributionDef;
import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.ServiceDef2;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import static org.apache.tapestry5.ioc.internal.util.InternalUtils.asString;
@@ -294,7 +295,7 @@
}
static String manyServicesMatchMarker(Class objectType, List<Class>
markers,
- Collection<ServiceDef>
matchingServices)
+ Collection<ServiceDef2>
matchingServices)
{
return MESSAGES.format("many-services-match-marker",
ClassFabUtils.toJavaClassName(objectType),
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/Module.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/Module.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/Module.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/Module.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -19,6 +19,7 @@
import org.apache.tapestry5.ioc.def.ContributionDef;
import org.apache.tapestry5.ioc.def.DecoratorDef;
import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.ServiceDef2;
import java.util.Collection;
import java.util.List;
@@ -89,7 +90,7 @@
* @param serviceId unique id for the service (caseless)
* @return the service definition or null
*/
- ServiceDef getServiceDef(String serviceId);
+ ServiceDef2 getServiceDef(String serviceId);
/**
* Returns the name used to obtain a logger for the module. Services
within the module suffix this with a period and
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java
Fri Jan 2 15:10:26 2009
@@ -15,14 +15,13 @@
package org.apache.tapestry5.ioc.internal;
import org.apache.tapestry5.ioc.*;
-import org.apache.tapestry5.ioc.def.ContributionDef;
-import org.apache.tapestry5.ioc.def.DecoratorDef;
-import org.apache.tapestry5.ioc.def.ModuleDef;
-import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.*;
import org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator;
import org.apache.tapestry5.ioc.internal.util.*;
-import org.apache.tapestry5.ioc.services.*;
-import org.apache.tapestry5.ioc.util.Stack;
+import org.apache.tapestry5.ioc.services.ClassFab;
+import org.apache.tapestry5.ioc.services.ClassFactory;
+import org.apache.tapestry5.ioc.services.MethodSignature;
+import org.apache.tapestry5.ioc.services.Status;
import org.slf4j.Logger;
import java.io.ObjectStreamException;
@@ -60,19 +59,14 @@
*/
private final Map<String, Object> services =
CollectionFactory.newCaseInsensitiveMap();
+ private final Map<String, ServiceDef2> serviceDefs =
CollectionFactory.newCaseInsensitiveMap();
+
/**
* The barrier is shared by all modules, which means that creation of
*any* service for any module is single
* threaded.
*/
private final static ConcurrentBarrier BARRIER = new ConcurrentBarrier();
- /**
- * Tracks what is currently going on in the module. Guarded by the Barrier.
- */
- private static final Stack<String> activeOperations =
CollectionFactory.newStack();
-
- private static boolean operationsReported;
-
public ModuleImpl(InternalRegistry registry, ServiceActivityTracker
tracker, ModuleDef moduleDef,
ClassFactory classFactory, Logger logger)
{
@@ -81,15 +75,25 @@
this.moduleDef = moduleDef;
this.classFactory = classFactory;
this.logger = logger;
+
+ for (String id : moduleDef.getServiceIds())
+ {
+ ServiceDef sd = moduleDef.getServiceDef(id);
+
+ ServiceDef2 sd2 = InternalUtils.toServiceDef2(sd);
+
+ serviceDefs.put(id, sd2);
+ }
}
+
public <T> T getService(String serviceId, Class<T> serviceInterface)
{
Defense.notBlank(serviceId, "serviceId");
Defense.notNull(serviceInterface, "serviceInterface");
// module may be null.
- ServiceDef def = moduleDef.getServiceDef(serviceId);
+ ServiceDef2 def = getServiceDef(serviceId);
// RegistryImpl should already have checked that the service exists.
assert def != null;
@@ -137,11 +141,10 @@
Collection<String> result = CollectionFactory.newList();
- for (String id : moduleDef.getServiceIds())
+ for (ServiceDef2 def : serviceDefs.values())
{
- ServiceDef def = moduleDef.getServiceDef(id);
-
- if (serviceInterface.isAssignableFrom(def.getServiceInterface()))
result.add(id);
+ if (serviceInterface.isAssignableFrom(def.getServiceInterface()))
+ result.add(def.getServiceId());
}
return result;
@@ -154,7 +157,7 @@
* @param eagerLoadProxies collection into which proxies for eager loaded
services are added (or null)
* @return the service proxy
*/
- private Object findOrCreate(final ServiceDef def,
+ private Object findOrCreate(final ServiceDef2 def,
final Collection<EagerLoadServiceProxy>
eagerLoadProxies)
{
final String key = def.getServiceId();
@@ -204,10 +207,8 @@
{
public void run()
{
- for (String serviceId : moduleDef.getServiceIds())
+ for (ServiceDef2 def : serviceDefs.values())
{
- ServiceDef def = moduleDef.getServiceDef(serviceId);
-
if (def.isEagerLoad()) findOrCreate(def, proxies);
}
}
@@ -222,7 +223,7 @@
*
* @param eagerLoadProxies a list into which any eager loaded proxies
should be added
*/
- private Object create(final ServiceDef def, final
Collection<EagerLoadServiceProxy> eagerLoadProxies)
+ private Object create(final ServiceDef2 def, final
Collection<EagerLoadServiceProxy> eagerLoadProxies)
{
final String serviceId = def.getServiceId();
@@ -262,9 +263,11 @@
creator = new LifecycleWrappedServiceCreator(registry,
def.getServiceScope(), resources, creator);
- // Don't allow the core IOC services services to be
decorated.
- if
(!TapestryIOCModule.class.equals(moduleDef.getBuilderClass()))
+ // Marked services (or services inside marked modules) are
not decorated.
+ // TapestryIOCModule prevents decoration of its services.
+
+ if (!def.isPreventDecoration())
creator = new InterceptorStackBuilder(module,
serviceId, creator, registry);
// Add a wrapper that checks for recursion.
@@ -476,9 +479,9 @@
return result;
}
- public ServiceDef getServiceDef(String serviceId)
+ public ServiceDef2 getServiceDef(String serviceId)
{
- return moduleDef.getServiceDef(serviceId);
+ return serviceDefs.get(serviceId);
}
public String getLoggerName()
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
Fri Jan 2 15:10:26 2009
@@ -16,10 +16,7 @@
import org.apache.tapestry5.ioc.*;
import org.apache.tapestry5.ioc.annotations.Local;
-import org.apache.tapestry5.ioc.def.ContributionDef;
-import org.apache.tapestry5.ioc.def.DecoratorDef;
-import org.apache.tapestry5.ioc.def.ModuleDef;
-import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.*;
import org.apache.tapestry5.ioc.internal.services.PerthreadManagerImpl;
import org.apache.tapestry5.ioc.internal.services.RegistryShutdownHubImpl;
import org.apache.tapestry5.ioc.internal.util.*;
@@ -85,14 +82,14 @@
private SymbolSource symbolSource;
- private final Map<Module, Set<ServiceDef>> moduleToServiceDefs =
CollectionFactory.newMap();
+ private final Map<Module, Set<ServiceDef2>> moduleToServiceDefs =
CollectionFactory.newMap();
/**
* From marker type to a list of marked service instances.
*/
- private final Map<Class, List<ServiceDef>> markerToServiceDef =
CollectionFactory.newMap();
+ private final Map<Class, List<ServiceDef2>> markerToServiceDef =
CollectionFactory.newMap();
- private final Set<ServiceDef> allServiceDefs = CollectionFactory.newSet();
+ private final Set<ServiceDef2> allServiceDefs = CollectionFactory.newSet();
private final OperationTracker operationTracker;
@@ -141,19 +138,20 @@
Module module = new ModuleImpl(this, tracker, def, classFactory,
logger);
- Set<ServiceDef> moduleServiceDefs = CollectionFactory.newSet();
+ Set<ServiceDef2> moduleServiceDefs = CollectionFactory.newSet();
for (String serviceId : def.getServiceIds())
{
- ServiceDef serviceDef = module.getServiceDef(serviceId);
+ ServiceDef2 serviceDef = module.getServiceDef(serviceId);
moduleServiceDefs.add(serviceDef);
allServiceDefs.add(serviceDef);
Module existing = serviceIdToModule.get(serviceId);
- if (existing != null) throw new
RuntimeException(IOCMessages.serviceIdConflict(serviceId, existing
- .getServiceDef(serviceId), serviceDef));
+ if (existing != null)
+ throw new
RuntimeException(IOCMessages.serviceIdConflict(serviceId, existing
+ .getServiceDef(serviceId), serviceDef));
serviceIdToModule.put(serviceId, module);
@@ -251,7 +249,7 @@
// Make sure each of the builtin services is also available via the
Builtin annotation
// marker.
- ServiceDef serviceDef = new ServiceDef()
+ ServiceDef2 serviceDef = new ServiceDef2()
{
public ObjectCreator createServiceCreator(ServiceBuilderResources
resources)
{
@@ -282,6 +280,11 @@
{
return false;
}
+
+ public boolean isPreventDecoration()
+ {
+ return true;
+ }
};
for (Class marker : serviceDef.getMarkers())
@@ -653,11 +656,11 @@
return masterProvider.provide(objectType, effectiveProvider, locator,
true);
}
- private Collection<ServiceDef> filterByType(Class<?> objectType,
Collection<ServiceDef> serviceDefs)
+ private Collection<ServiceDef2> filterByType(Class<?> objectType,
Collection<ServiceDef2> serviceDefs)
{
- Collection<ServiceDef> result = CollectionFactory.newSet();
+ Collection<ServiceDef2> result = CollectionFactory.newSet();
- for (ServiceDef sd : serviceDefs)
+ for (ServiceDef2 sd : serviceDefs)
{
if (objectType.isAssignableFrom(sd.getServiceInterface()))
{
@@ -676,7 +679,7 @@
boolean localOnly = localModule != null &&
provider.getAnnotation(Local.class) != null;
- Set<ServiceDef> matches = CollectionFactory.newSet();
+ Set<ServiceDef2> matches = CollectionFactory.newSet();
matches.addAll(filterByType(objectType, localOnly
?
moduleToServiceDefs.get(localModule)
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBinderImpl.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 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.
@@ -17,12 +17,11 @@
import org.apache.tapestry5.ioc.*;
import org.apache.tapestry5.ioc.annotations.EagerLoad;
import org.apache.tapestry5.ioc.annotations.Marker;
+import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
import org.apache.tapestry5.ioc.annotations.Scope;
import org.apache.tapestry5.ioc.def.ServiceDef;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.Defense;
-import static org.apache.tapestry5.ioc.internal.util.Defense.notBlank;
-import static org.apache.tapestry5.ioc.internal.util.Defense.notNull;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.OneShotLock;
import org.apache.tapestry5.ioc.services.ClassFactory;
@@ -45,14 +44,19 @@
private final Set<Class> defaultMarkers;
+ private final boolean moduleDefaultPreventDecoration;
+
public ServiceBinderImpl(ServiceDefAccumulator accumulator, Method
bindMethod,
ClassFactory classFactory,
- Set<Class> defaultMarkers)
+ Set<Class> defaultMarkers, boolean
moduleDefaultPreventDecoration)
{
this.accumulator = accumulator;
this.bindMethod = bindMethod;
this.classFactory = classFactory;
this.defaultMarkers = defaultMarkers;
+ this.moduleDefaultPreventDecoration = moduleDefaultPreventDecoration;
+
+ clear();
}
private String serviceId;
@@ -69,6 +73,8 @@
private String scope;
+ private boolean preventDecoration;
+
public void finish()
{
lock.lock();
@@ -90,10 +96,16 @@
Set<Class> markers = CollectionFactory.newSet(defaultMarkers);
markers.addAll(this.markers);
- ServiceDef serviceDef = new ServiceDefImpl(serviceInterface,
serviceId, markers, scope, eagerLoad, source);
+ ServiceDef serviceDef = new ServiceDefImpl(serviceInterface,
serviceId, markers, scope, eagerLoad,
+ preventDecoration, source);
accumulator.addServiceDef(serviceDef);
+ clear();
+ }
+
+ private void clear()
+ {
serviceId = null;
serviceInterface = null;
serviceImplementation = null;
@@ -101,6 +113,7 @@
this.markers.clear();
eagerLoad = false;
scope = null;
+ preventDecoration = moduleDefaultPreventDecoration;
}
private ObjectCreatorSource
createObjectCreatorSourceFromImplementationClass()
@@ -187,8 +200,8 @@
public <T> ServiceBindingOptions bind(Class<T> serviceInterface, Class<?
extends T> serviceImplementation)
{
- notNull(serviceInterface, "serviceIterface");
- notNull(serviceImplementation, "serviceImplementation");
+ Defense.notNull(serviceInterface, "serviceIterface");
+ Defense.notNull(serviceImplementation, "serviceImplementation");
lock.check();
@@ -215,6 +228,8 @@
markers.addAll(Arrays.asList(marker.value()));
}
+ preventDecoration |=
serviceImplementation.getAnnotation(PreventServiceDecoration.class) != null;
+
return this;
}
@@ -227,9 +242,18 @@
return this;
}
+ public ServiceBindingOptions preventDecoration()
+ {
+ lock.check();
+
+ preventDecoration = true;
+
+ return this;
+ }
+
public ServiceBindingOptions withId(String id)
{
- notBlank(id, "id");
+ Defense.notBlank(id, "id");
lock.check();
@@ -240,7 +264,7 @@
public ServiceBindingOptions scope(String scope)
{
- notBlank(scope, "scope");
+ Defense.notBlank(scope, "scope");
lock.check();
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefImpl.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceDefImpl.java
Fri Jan 2 15:10:26 2009
@@ -16,11 +16,11 @@
import org.apache.tapestry5.ioc.ObjectCreator;
import org.apache.tapestry5.ioc.ServiceBuilderResources;
-import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.ServiceDef2;
import java.util.Set;
-public class ServiceDefImpl implements ServiceDef
+public class ServiceDefImpl implements ServiceDef2
{
private final Class serviceInterface;
@@ -34,22 +34,26 @@
private final Set<Class> markers;
+ private final boolean preventDecoration;
+
/**
- * @param serviceInterface interface implemented by the service (or the
service implementation class, for
- * non-proxied services)
- * @param serviceId unique id for the service
- * @param markers set of marker annotation classes (will be
retained not copied)
- * @param scope scope of the service (i.e., {...@link
org.apache.tapestry5.ioc.ScopeConstants#DEFAULT}).
- * @param eagerLoad if true, the service is realized at startup,
rather than on-demand
- * @param source used to create the service implementation when
needed
+ * @param serviceInterface interface implemented by the service (or the
service implementation class, for
+ * non-proxied services)
+ * @param serviceId unique id for the service
+ * @param markers set of marker annotation classes (will be
retained not copied)
+ * @param scope scope of the service (i.e., {...@link
org.apache.tapestry5.ioc.ScopeConstants#DEFAULT}).
+ * @param eagerLoad if true, the service is realized at startup,
rather than on-demand
+ * @param preventDecoration if true, the service may not be decorated
+ * @param source used to create the service implementation when
needed
*/
ServiceDefImpl(Class serviceInterface, String serviceId, Set<Class>
markers, String scope,
- boolean eagerLoad, ObjectCreatorSource source)
+ boolean eagerLoad, boolean preventDecoration,
ObjectCreatorSource source)
{
this.serviceInterface = serviceInterface;
this.serviceId = serviceId;
this.scope = scope;
this.eagerLoad = eagerLoad;
+ this.preventDecoration = preventDecoration;
this.source = source;
this.markers = markers;
@@ -90,4 +94,9 @@
{
return markers;
}
+
+ public boolean isPreventDecoration()
+ {
+ return preventDecoration;
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImpl.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/MasterObjectProviderImpl.java
Fri Jan 2 15:10:26 2009
@@ -18,12 +18,14 @@
import org.apache.tapestry5.ioc.ObjectLocator;
import org.apache.tapestry5.ioc.ObjectProvider;
import org.apache.tapestry5.ioc.OperationTracker;
+import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
import org.apache.tapestry5.ioc.internal.util.Invokable;
import org.apache.tapestry5.ioc.services.ClassFabUtils;
import org.apache.tapestry5.ioc.services.MasterObjectProvider;
import java.util.List;
+...@preventservicedecoration
public class MasterObjectProviderImpl implements MasterObjectProvider
{
private final List<ObjectProvider> configuration;
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -19,6 +19,8 @@
import org.apache.tapestry5.ioc.annotations.InjectResource;
import org.apache.tapestry5.ioc.annotations.InjectService;
import org.apache.tapestry5.ioc.annotations.PostInjection;
+import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.ServiceDef2;
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
import static org.apache.tapestry5.ioc.internal.util.Defense.notBlank;
import org.apache.tapestry5.ioc.services.ClassFabUtils;
@@ -743,4 +745,48 @@
"You should make the constructor public, or mark
an alternate public constructor with the @Inject annotation.",
constructor));
}
+
+ public static ServiceDef2 toServiceDef2(final ServiceDef sd)
+ {
+ if (sd instanceof ServiceDef2)
+ return (ServiceDef2) sd;
+
+ return new ServiceDef2()
+ {
+ public boolean isPreventDecoration()
+ {
+ return false;
+ }
+
+ public ObjectCreator createServiceCreator(ServiceBuilderResources
resources)
+ {
+ return sd.createServiceCreator(resources);
+ }
+
+ public String getServiceId()
+ {
+ return sd.getServiceId();
+ }
+
+ public Set<Class> getMarkers()
+ {
+ return sd.getMarkers();
+ }
+
+ public Class getServiceInterface()
+ {
+ return sd.getServiceInterface();
+ }
+
+ public String getServiceScope()
+ {
+ return sd.getServiceScope();
+ }
+
+ public boolean isEagerLoad()
+ {
+ return sd.isEagerLoad();
+ }
+ };
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
Fri Jan 2 15:10:26 2009
@@ -16,6 +16,7 @@
import org.apache.tapestry5.ioc.*;
import org.apache.tapestry5.ioc.annotations.Marker;
+import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
import org.apache.tapestry5.ioc.internal.services.*;
import org.apache.tapestry5.ioc.util.TimeInterval;
@@ -29,6 +30,7 @@
* Defines the base set of services for the Tapestry IOC container.
*/
@Marker(Builtin.class)
+...@preventservicedecoration
public final class TapestryIOCModule
{
public static void bind(ServiceBinder binder)
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
Fri Jan 2 15:10:26 2009
@@ -1104,4 +1104,43 @@
"soIsThisMethod().");
}
}
+
+ /**
+ * TAP5-430
+ */
+ @Test
+ public void service_builder_method_marked_for_no_decoration()
+ {
+ Registry r = buildRegistry(PreventDecorationModule.class);
+
+ StringTransformer st = r.getService(StringTransformer.class);
+
+ assertEquals(st.transform("tapestry"), "TAPESTRY");
+
+ r.shutdown();
+ }
+
+ @Test
+ public void bind_service_marked_for_no_decoration_explicitly()
+ {
+ Registry r = buildRegistry(PreventDecorationModule.class);
+
+ Greeter g = r.getService(Greeter.class);
+
+ assertEquals(g.getGreeting(), "Greetings from ServiceIdGreeter.");
+
+ r.shutdown();
+ }
+
+ @Test
+ public void
bind_service_with_prevent_service_decoration_annotations_on_implementation_class()
+ {
+ Registry r = buildRegistry(PreventDecorationModule.class);
+
+ Rocket rocket = r.getService(Rocket.class);
+
+ assertEquals(rocket.getCountdown(), "3, 2, 1, Launch!");
+
+ r.shutdown();
+ }
}
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/PreventDecorationModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/PreventDecorationModule.java?rev=730861&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/PreventDecorationModule.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/PreventDecorationModule.java
Fri Jan 2 15:10:26 2009
@@ -0,0 +1,39 @@
+// Copyright 2009 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.tapestry5.ioc;
+
+import org.apache.tapestry5.ioc.annotations.Match;
+import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
+
+public class PreventDecorationModule
+{
+ public static void bind(ServiceBinder binder)
+ {
+ binder.bind(Greeter.class,
ServiceIdGreeter.class).withId("ServiceIdGreeter").preventDecoration();
+ binder.bind(Rocket.class, RocketImpl.class);
+ }
+
+ @PreventServiceDecoration
+ public StringTransformer buildStringTransformer()
+ {
+ return new UppercaseStringTransformer();
+ }
+
+ @Match("*")
+ public <T> T decorateEverything(Class<T> type, T instance)
+ {
+ throw new RuntimeException(String.format("Failure to decorate type
%s.", type.getName()));
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/Rocket.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/Rocket.java?rev=730861&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/Rocket.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/Rocket.java
Fri Jan 2 15:10:26 2009
@@ -0,0 +1,20 @@
+// Copyright 2009 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.tapestry5.ioc;
+
+public interface Rocket
+{
+ public String getCountdown();
+}
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/RocketImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/RocketImpl.java?rev=730861&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/RocketImpl.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/RocketImpl.java
Fri Jan 2 15:10:26 2009
@@ -0,0 +1,26 @@
+// Copyright 2009 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.tapestry5.ioc;
+
+import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
+
+...@preventservicedecoration
+public class RocketImpl implements Rocket
+{
+ public String getCountdown()
+ {
+ return "3, 2, 1, Launch!";
+ }
+}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleImplTest.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -25,6 +25,7 @@
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Set;
public class ModuleImplTest extends IOCInternalTestCase
@@ -68,6 +69,9 @@
ModuleDef moduleDef = mockModuleDef();
+ Set<String> serviceIds = Collections.emptySet();
+ expect(moduleDef.getServiceIds()).andReturn(serviceIds);
+
expect(moduleDef.getDecoratorDefs()).andReturn(rawDefs);
expect(rawDefs.iterator()).andReturn(Arrays.asList(def1,
def2).iterator());
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/RecursiveServiceCreationCheckWrapperTest.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2009 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.
@@ -32,7 +32,7 @@
ObjectCreator delegate = mockObjectCreator();
Object service = new Object();
- ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", null,
"singleton", false, source);
+ ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", null,
"singleton", false, false, source);
train_createObject(delegate, service);
@@ -70,7 +70,7 @@
ObjectCreator delegate = mockObjectCreator();
Object service = new Object();
- ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", null,
"singleton", false, source);
+ ServiceDef def = new ServiceDefImpl(Runnable.class, "Bar", null,
"singleton", false, false, source);
expect(delegate.createObject()).andThrow(failure);
@@ -101,6 +101,5 @@
assertSame(service, wrapper.createObject());
verify();
-
}
}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java?rev=730861&r1=730860&r2=730861&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/InternalUtilsTest.java
Fri Jan 2 15:10:26 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -16,6 +16,8 @@
import org.apache.tapestry5.ioc.*;
import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.ServiceDef2;
import org.apache.tapestry5.ioc.internal.QuietOperationTracker;
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
import static org.apache.tapestry5.ioc.internal.util.InternalUtils.toList;
@@ -574,4 +576,60 @@
assertEquals(InternalUtils.size(c), 3);
}
+
+ @Test
+ public void servicedef_to_servicedef2()
+ {
+ final ObjectCreator oc = mockObjectCreator();
+ final String serviceId = "RocketLauncher";
+ final Set<Class> markers = Collections.emptySet();
+ final Class serviceInterface = Runnable.class;
+
+ ServiceDef sd = new ServiceDef()
+ {
+ public ObjectCreator createServiceCreator(ServiceBuilderResources
resources)
+ {
+ return oc;
+ }
+
+ public String getServiceId()
+ {
+ return serviceId;
+ }
+
+ public Set<Class> getMarkers()
+ {
+ return markers;
+ }
+
+ public Class getServiceInterface()
+ {
+ return serviceInterface;
+ }
+
+ public String getServiceScope()
+ {
+ return ScopeConstants.PERTHREAD;
+ }
+
+ public boolean isEagerLoad()
+ {
+ return true;
+ }
+ };
+
+ replay();
+
+ ServiceDef2 sd2 = InternalUtils.toServiceDef2(sd);
+
+ assertSame(sd2.createServiceCreator(null), oc);
+ assertSame(sd2.getServiceId(), serviceId);
+ assertSame(sd2.getMarkers(), markers);
+ assertSame(sd2.getServiceInterface(), serviceInterface);
+ assertSame(sd2.getServiceScope(), ScopeConstants.PERTHREAD);
+ assertTrue(sd2.isEagerLoad());
+ assertFalse(sd2.isPreventDecoration());
+
+ verify();
+ }
}