Author: hlship
Date: Sun Oct 28 12:13:52 2007
New Revision: 589396
URL: http://svn.apache.org/viewvc?rev=589396&view=rev
Log:
TAPESTRY-1828: Convert uses of @InjectService to be @Inject plus a marker
annotation
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/ClasspathProvider.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/annotations/Primary.java
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/Local.java
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/LaunchCrusherTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryFilter.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/AppModule.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryFilter.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryFilter.java?rev=589396&r1=589395&r2=589396&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryFilter.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/TapestryFilter.java
Sun Oct 28 12:13:52 2007
@@ -14,9 +14,9 @@
package org.apache.tapestry;
-import static java.lang.String.format;
-
import java.io.IOException;
+import java.util.Formatter;
+import java.util.List;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -32,6 +32,9 @@
import org.apache.tapestry.internal.TapestryAppInitializer;
import org.apache.tapestry.ioc.Registry;
import org.apache.tapestry.ioc.def.ModuleDef;
+import org.apache.tapestry.ioc.services.ServiceActivity;
+import org.apache.tapestry.ioc.services.ServiceActivityScoreboard;
+import org.apache.tapestry.ioc.services.Status;
import org.apache.tapestry.ioc.services.SymbolProvider;
import org.apache.tapestry.services.HttpServletRequestHandler;
import org.apache.tapestry.services.ServletApplicationInitializer;
@@ -41,7 +44,7 @@
/**
* The TapestryFilter is responsible for intercepting all requests into the
web application. It
* identifies the requests that are relevant to Tapestry, and lets the servlet
container handle the
- * rest. It is also responsible for initializating Tapestry.
+ * rest. It is also responsible for initializing Tapestry.
*/
public class TapestryFilter implements Filter
{
@@ -95,8 +98,36 @@
long toFinish = System.currentTimeMillis();
- _logger.info(format("Startup time: %,d ms to build IoC Registry, %,d
ms overall.", toRegistry
- - start, toFinish - start));
+ StringBuilder buffer = new StringBuilder("Startup status:\n\n");
+ Formatter f = new Formatter(buffer);
+
+ f.format("Startup time: %,d ms to build IoC Registry, %,d ms overall."
+ + "\n\nStartup services status:\n", toRegistry - start,
toFinish - start);
+
+ int unrealized = 0;
+
+ ServiceActivityScoreboard scoreboard = _registry
+ .getService(ServiceActivityScoreboard.class);
+
+ List<ServiceActivity> serviceActivity =
scoreboard.getServiceActivity();
+
+ for (ServiceActivity activity : serviceActivity)
+ {
+ Status status = activity.getStatus();
+
+ f.format("%40s: %s\n", activity.getServiceId(), status.name());
+
+ if (status == Status.DEFINED || status == Status.VIRTUAL)
unrealized++;
+
+ }
+
+ f.format(
+ "\n%d/%d unrealized services (%4.2f%%)\n",
+ unrealized,
+ serviceActivity.size(),
+ 100. * unrealized / serviceActivity.size());
+
+ _logger.info(buffer.toString());
}
protected final FilterConfig getFilterConfig()
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java?rev=589396&r1=589395&r2=589396&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
Sun Oct 28 12:13:52 2007
@@ -54,6 +54,7 @@
import org.apache.tapestry.services.AssetFactory;
import org.apache.tapestry.services.BindingFactory;
import org.apache.tapestry.services.ClasspathAssetAliasManager;
+import org.apache.tapestry.services.ClasspathProvider;
import org.apache.tapestry.services.ComponentActionRequestFilter;
import org.apache.tapestry.services.ComponentActionRequestHandler;
import org.apache.tapestry.services.ComponentClassResolver;
@@ -271,6 +272,7 @@
return service;
}
+ @Marker(ClasspathProvider.class)
public AssetFactory buildClasspathAssetFactory(ResourceCache resourceCache,
ClasspathAssetAliasManager aliasManager)
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/ClasspathProvider.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/ClasspathProvider.java?rev=589396&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/ClasspathProvider.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/ClasspathProvider.java
Sun Oct 28 12:13:52 2007
@@ -0,0 +1,36 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.services;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+
+/**
+ * Used to select the correct [EMAIL PROTECTED] AssetFactory} for injection.
The marked interface will service
+ * assets located on the classpath.
+ */
[EMAIL PROTECTED](
+{ PARAMETER, FIELD })
[EMAIL PROTECTED](RUNTIME)
[EMAIL PROTECTED]
+public @interface ClasspathProvider
+{
+
+}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=589396&r1=589395&r2=589396&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
Sun Oct 28 12:13:52 2007
@@ -173,6 +173,7 @@
import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.ioc.annotations.Marker;
+import org.apache.tapestry.ioc.annotations.Primary;
import org.apache.tapestry.ioc.annotations.SubModule;
import org.apache.tapestry.ioc.annotations.Symbol;
import org.apache.tapestry.ioc.annotations.Value;
@@ -278,7 +279,7 @@
public static void contributeAlias(Configuration<AliasContribution>
configuration,
ObjectLocator locator,
- @InjectService("ComponentClassFactory")
+ @ComponentLayer
ClassFactory componentClassFactory,
@InjectService("DefaultDataTypeAnalyzer")
@@ -929,7 +930,7 @@
PropertyAccess propertyAccess,
- @InjectService("ComponentClassFactory")
+ @ComponentLayer
ClassFactory componentClassFactory)
{
_pipelineBuilder = pipelineBuilder;
@@ -970,7 +971,7 @@
public ValidationMessagesSource build(Collection<String> configuration,
UpdateListenerHub updateListenerHub,
- @InjectService("ClasspathAssetFactory")
+ @ClasspathProvider
AssetFactory classpathAssetFactory)
{
ValidationMessagesSourceImpl service = new
ValidationMessagesSourceImpl(configuration,
@@ -1145,6 +1146,7 @@
terminator);
}
+ @Marker(Primary.class)
public ComponentEventResultProcessor build(
Map<Class, ComponentEventResultProcessor> configuration)
{
@@ -1196,7 +1198,7 @@
public static ComponentMessagesSource build(UpdateListenerHub
updateListenerHub,
- @InjectService("ContextAssetFactory")
+ @ContextProvider
AssetFactory contextAssetFactory,
@Inject
@@ -1280,10 +1282,10 @@
}
public void contributeAssetSource(MappedConfiguration<String,
AssetFactory> configuration,
- @InjectService("ContextAssetFactory")
+ @ContextProvider
AssetFactory contextAssetFactory,
- @InjectService("ClasspathAssetFactory")
+ @ClasspathProvider
AssetFactory classpathAssetFactory)
{
configuration.add("context", contextAssetFactory);
@@ -1306,10 +1308,13 @@
* </dl>
*/
public void contributeComponentEventResultProcessor(
- @InjectService("ComponentInstanceResultProcessor")
- ComponentEventResultProcessor componentInstanceProcessor,
- ComponentClassResolver componentClassResolver,
- MappedConfiguration<Class, ComponentEventResultProcessor>
configuration)
+
+ @InjectService("ComponentInstanceResultProcessor")
+ ComponentEventResultProcessor componentInstanceProcessor,
+
+ ComponentClassResolver componentClassResolver,
+
+ MappedConfiguration<Class, ComponentEventResultProcessor> configuration)
{
configuration.add(
ActionResponseGenerator.class,
Modified:
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java?rev=589396&r1=589395&r2=589396&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry/internal/hibernate/HibernateSessionSourceImplTest.java
Sun Oct 28 12:13:52 2007
@@ -16,7 +16,6 @@
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import org.apache.tapestry.hibernate.HibernateConfigurer;
@@ -44,46 +43,53 @@
Collection<String> packageNames = CollectionFactory.newList(
"org.example.myapp.entities",
"org.example.app0.entities");
- HibernateEntityPackageManager packageManager =
newMock(HibernateEntityPackageManager.class);
- expect(packageManager.getPackageNames()).andReturn(packageNames);
+ HibernateEntityPackageManager packageManager =
newMock(HibernateEntityPackageManager.class);
+ expect(packageManager.getPackageNames()).andReturn(packageNames);
- List<HibernateConfigurer> filters = Arrays.asList(
- new DefaultHibernateConfigurer(),
- new PackageNameHibernateConfigurer(packageManager, new
ClassNameLocatorImpl()));
-
- replay();
+ List<HibernateConfigurer> filters = Arrays.asList(
+ new DefaultHibernateConfigurer(),
+ new PackageNameHibernateConfigurer(packageManager, new
ClassNameLocatorImpl()));
+
+ replay();
HibernateSessionSource source = new HibernateSessionSourceImpl(_log,
filters);
Session session = source.create();
- assertNotNull(session);
-
- // make sure it found the entity in the package
- ClassMetadata meta =
session.getSessionFactory().getClassMetadata(User.class);
- assertEquals(meta.getEntityName(),
"org.example.app0.entities.User");
-
+ assertNotNull(session);
+
+ // make sure it found the entity in the package
+ ClassMetadata meta =
session.getSessionFactory().getClassMetadata(User.class);
+ assertEquals(meta.getEntityName(), "org.example.app0.entities.User");
+
verify();
}
-
+
@Test
- public void get_configuration() {
- HibernateConfigurer configurer = new HibernateConfigurer() {
- public void configure(Configuration configuration) {
- configuration.setProperty("foo", "bar");
- configuration.configure();
- }
+ public void get_configuration()
+ {
+ HibernateConfigurer configurer = new HibernateConfigurer()
+ {
+ public void configure(Configuration configuration)
+ {
+ configuration.setProperty("foo", "bar");
+ configuration.configure();
+ }
};
- HibernateSessionSource source = new HibernateSessionSourceImpl(_log,
Arrays.asList(configurer));
-
+ HibernateSessionSource source = new HibernateSessionSourceImpl(_log,
Arrays
+ .asList(configurer));
+
Configuration config = source.getConfiguration();
assertNotNull(config);
assertEquals("bar", config.getProperty("foo"));
-
+
// configuration should be immutable
- try {
- config.setProperty("hibernate.dialect", "foo");
- fail("did not throw");
- } catch(UnsupportedOperationException e) {
- assertTrue(e.getMessage().contains("immutable"));
+ try
+ {
+ config.setProperty("hibernate.dialect", "foo");
+ fail("did not throw");
+ }
+ catch (UnsupportedOperationException e)
+ {
+ assertTrue(e.getMessage().contains("immutable"));
}
}
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/annotations/Primary.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/annotations/Primary.java?rev=589396&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/annotations/Primary.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/annotations/Primary.java
Sun Oct 28 12:13:52 2007
@@ -0,0 +1,42 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.ioc.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.apache.tapestry.ioc.services.ChainBuilder;
+
+import apple.awt.StrategyBufferImage;
+
+/**
+ * Marker annotation used to denote a service that is the primary instance of
some common interface.
+ * This is often used when a service is a [EMAIL PROTECTED] ChainBuilder chain
of command} or
+ * [EMAIL PROTECTED] StrategyBufferImage strategy-based} and, therefore, many
services will implement the
+ * same interface.
+ */
[EMAIL PROTECTED](
+{ PARAMETER, FIELD })
[EMAIL PROTECTED](RUNTIME)
[EMAIL PROTECTED]
+public @interface Primary
+{
+
+}
Modified:
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/AppModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/AppModule.java?rev=589396&r1=589395&r2=589396&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/AppModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/AppModule.java
Sun Oct 28 12:13:52 2007
@@ -18,7 +18,7 @@
import org.apache.tapestry.ioc.MappedConfiguration;
import org.apache.tapestry.ioc.OrderedConfiguration;
-import org.apache.tapestry.ioc.annotations.InjectService;
+import org.apache.tapestry.ioc.annotations.Marker;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.RequestFilter;
import org.apache.tapestry.services.RequestHandler;
@@ -29,6 +29,7 @@
* This module is automatically included as part of the Tapestry IoC Registry,
it's a good place to
* configure and extend Tapestry, or to place your own services.
*/
[EMAIL PROTECTED](Local.class)
public class AppModule
{
public static void contributeApplicationDefaults(
@@ -83,8 +84,9 @@
* management or security.
*/
public void contributeRequestHandler(OrderedConfiguration<RequestFilter>
configuration,
- @InjectService("TimingFilter")
- RequestFilter filter)
+
+ @Local
+ RequestFilter filter)
{
// Each contribution to an ordered configuration has a name, When
necessary, you may
// set constraints to precisely control the invocation order of the
contributed filter
Added:
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/Local.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/Local.java?rev=589396&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/Local.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-tutorial1/src/main/java/org/apache/tapestry/tutorial/services/Local.java
Sun Oct 28 12:13:52 2007
@@ -0,0 +1,20 @@
+/**
+ *
+ */
+package org.apache.tapestry.tutorial.services;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
[EMAIL PROTECTED](
+{ PARAMETER, FIELD })
[EMAIL PROTECTED](RUNTIME)
[EMAIL PROTECTED]
+public @interface Local
+{
+}
\ No newline at end of file