tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r418774 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/aspect/org/apache/tapestry/internal/aspects/ main/java/org/apache/tapestry/ main/java/org/apache/tapestry/internal/event/ main/java/org/apache/tapestry/internal/ioc/ main/java/o...
Date Mon, 03 Jul 2006 14:23:06 GMT
Author: hlship
Date: Mon Jul  3 07:23:04 2006
New Revision: 418774

URL: http://svn.apache.org/viewvc?rev=418774&view=rev
Log:
Start work on IoC layer.
Add missing copyrights.

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/IOCMessages.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/Module.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleGrinder.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDef.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDefImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceIdConflictMethodBuilder.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ErrorLog.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/annotations/
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Id.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ioc/
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ioc/IOCStrings.properties
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FieService.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FoeService.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleBuilderWithId.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleGrinderTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SimpleModuleBuilder.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/transform/SyncCostBench.java
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj
    tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Renderable.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/event/InvalidationEventHubImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSource.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoader.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoaderImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TokenType.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElement.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/MarkupPageElement.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImplTest.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj Mon Jul  3 07:23:04 2006
@@ -4,7 +4,7 @@
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-// http://www.apache.org/licenses/LICENSE-2.0
+//     http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj Mon Jul  3 07:23:04 2006
@@ -4,7 +4,7 @@
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-// http://www.apache.org/licenses/LICENSE-2.0
+//     http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Renderable.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Renderable.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Renderable.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Renderable.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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;
 
 /**

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/event/InvalidationEventHubImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/event/InvalidationEventHubImpl.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/event/InvalidationEventHubImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/event/InvalidationEventHubImpl.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.event;
 
 import static org.apache.tapestry.util.CollectionFactory.newThreadSafeList;

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/IOCMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/IOCMessages.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/IOCMessages.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/IOCMessages.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,50 @@
+// Copyright 2006 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.internal.ioc;
+
+import java.lang.reflect.Method;
+
+import org.apache.hivemind.Messages;
+import org.apache.hivemind.impl.MessageFormatter;
+import org.apache.tapestry.internal.annotations.Utility;
+
+/**
+ * @author Howard M. Lewis Ship
+ */
+@Utility
+public final class IOCMessages
+{
+    private static final Messages MESSAGES = new MessageFormatter(IOCMessages.class);
+
+    static String buildMethodConflict(Method conflict, Method existing)
+    {
+        return MESSAGES.format("build-method-conflict", conflict, existing);
+    }
+
+    static String voidBuildMethod(Method method)
+    {
+        return MESSAGES.format("void-build-method", method);
+    }
+
+    static String buildMethodWrongReturnType(Method method)
+    {
+        return MESSAGES.format("build-method-wrong-return-type", method);
+    }
+
+    static String missingService(String serviceId, String moduleId)
+    {
+        return MESSAGES.format("missing-service", serviceId, moduleId);
+    }
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/Module.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/Module.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/Module.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/Module.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,27 @@
+// Copyright 2006 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.internal.ioc;
+
+/**
+ * A module with the Tapestry IoC registry. Each Module is constructed around a corresponding module
+ * builder instance; the methods and annotations of that instance define the services provided by
+ * the module.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface Module
+{
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleGrinder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleGrinder.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleGrinder.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ModuleGrinder.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,203 @@
+// Copyright 2006 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.internal.ioc;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tapestry.ioc.ErrorLog;
+import org.apache.tapestry.ioc.annotations.Id;
+
+import static org.apache.tapestry.internal.ioc.IOCMessages.buildMethodConflict;
+import static org.apache.tapestry.internal.ioc.IOCMessages.buildMethodWrongReturnType;
+import static org.apache.tapestry.internal.ioc.IOCMessages.voidBuildMethod;
+import static org.apache.tapestry.util.CollectionFactory.newMap;
+
+/**
+ * Grinds through a module builder class, identifying all the services and contributions.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class ModuleGrinder
+{
+    /** The prefix used to identify service building methods. */
+
+    private static final String BUILD_METHOD_NAME_PREFIX = "build";
+
+    private final Class _moduleBuilder;
+
+    private final ErrorLog _log;
+
+    /** Keyed on unqualified service id. */
+    private final Map<String, ServiceDef> _serviceDefs = newMap();
+
+    private final String _moduleId;
+
+    /**
+     * @param moduleBuilder
+     *            the class that is responsible for building
+     * @param log
+     */
+    public ModuleGrinder(Class moduleBuilder, ErrorLog log)
+    {
+        _moduleBuilder = moduleBuilder;
+        _log = log;
+
+        _moduleId = extractModuleId();
+
+        grind();
+    }
+
+    /** Returns the ids of the services built/provided by the module. */
+    public Set<String> getServiceIds()
+    {
+        return _serviceDefs.keySet();
+    }
+
+    /**
+     * Returns a service definition via local (unqualified) service id. May return null (after
+     * logging a warning) if the requested service does not exist.
+     * 
+     * @param serviceId
+     *            unqualified service ids
+     * @return service definition or null
+     */
+    public ServiceDef getServiceDef(String serviceId)
+    {
+        ServiceDef result = _serviceDefs.get(serviceId);
+
+        if (result == null)
+            _log.warn(IOCMessages.missingService(serviceId, _moduleId), null);
+
+        return result;
+    }
+
+    /**
+     * Returns the module id extracted from the {@link org.apache.tapestry.ioc.annotations.Id}
+     * annotation on the module builder class (or calculated from the module bulder's package, if
+     * the annotation is not present).
+     */
+    public String getModuleId()
+    {
+        return _moduleId;
+    }
+
+    private String extractModuleId()
+    {
+        Id id = getAnnotation(_moduleBuilder, Id.class);
+
+        if (id != null)
+            return id.value();
+
+        String className = _moduleBuilder.getName();
+
+        // Don't try to do this with classes in the default package. Then again, you should
+        // never put classes in the default package!
+
+        int lastdot = className.lastIndexOf('.');
+
+        return className.substring(0, lastdot);
+    }
+
+    private <T extends Annotation> T getAnnotation(AnnotatedElement element, Class<T> annotationType)
+    {
+        return element.getAnnotation(annotationType);
+    }
+
+    // private <T extends Annotation> T getRequiredAnnotation(AnnotatedElement element,
+    // Class<T> annotationType)
+    // {
+    // T result = element.getAnnotation(annotationType);
+    //
+    // if (result == null)
+    // _log.fail(IOCMessages.missingAnnotation(annotationType, element), null);
+    //
+    // return result;
+    // }
+
+    private void grind()
+    {
+        Method[] methods = _moduleBuilder.getMethods();
+
+        Comparator<Method> c = new Comparator<Method>()
+        {
+            // By name, ascending, then by parameter count, descending.
+
+            public int compare(Method o1, Method o2)
+            {
+                int result = o1.getName().compareTo(o2.getName());
+
+                if (result == 0)
+                    result = o2.getParameterTypes().length - o1.getParameterTypes().length;
+
+                return result;
+            }
+
+        };
+
+        Arrays.sort(methods, c);
+
+        for (Method m : methods)
+        {
+            String name = m.getName();
+
+            if (!name.startsWith(BUILD_METHOD_NAME_PREFIX))
+                continue;
+
+            addServiceBuildMethod(m);
+        }
+    }
+
+    /** Invoked for public methods that have the proper prefix. */
+    private void addServiceBuildMethod(Method method)
+    {
+        // TODO: Methods named just "build"
+        String serviceId = method.getName().substring(BUILD_METHOD_NAME_PREFIX.length());
+
+        ServiceDef existing = _serviceDefs.get(serviceId);
+
+        if (existing != null)
+        {
+            _log.warn(buildMethodConflict(method, existing.getBuilderMethod()), null);
+            return;
+        }
+
+        // Any number of parameters is fine, we'll adapt. Eventually we have to check
+        // that we can satisfy the parameters requested. Thrown exceptions of the method
+        // will be caught and wrapped, so we don't need to check those. But we do need a proper
+        // return type.
+
+        Class returnType = method.getReturnType();
+
+        if (returnType.equals(void.class))
+        {
+            _log.warn(voidBuildMethod(method), null);
+            return;
+        }
+
+        if (!returnType.isInterface())
+        {
+            _log.warn(buildMethodWrongReturnType(method), null);
+            return;
+        }
+
+        _serviceDefs.put(serviceId, new ServiceDefImpl(serviceId, method));
+    }
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDef.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDef.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDef.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDef.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,40 @@
+// Copyright 2006 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.internal.ioc;
+
+import java.lang.reflect.Method;
+
+/**
+ * Service definition.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface ServiceDef
+{
+    /**
+     * Returns the method to invoke, on the corresponding module builder instance, that will provide
+     * the core service implementation.
+     */
+    Method getBuilderMethod();
+
+    /** Returns the unqualified service id, derived from the method name. */
+    String getServiceId();
+
+    /**
+     * Returns the service interface associated with this service. This is the interface exposed to
+     * the outside world, as well as the one used to build proxies.
+     */
+    Class getServiceInterface();
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDefImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDefImpl.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDefImpl.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceDefImpl.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,49 @@
+// Copyright 2006 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.internal.ioc;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author Howard M. Lewis Ship
+ */
+public class ServiceDefImpl implements ServiceDef
+{
+    private final Method _builderMethod;
+
+    private final String _serviceId;
+
+    ServiceDefImpl(String serviceId, Method builderMethod)
+    {
+        _serviceId = serviceId;
+        _builderMethod = builderMethod;
+    }
+
+    public Method getBuilderMethod()
+    {
+        return _builderMethod;
+    }
+
+    public String getServiceId()
+    {
+        return _serviceId;
+    }
+
+    public Class getServiceInterface()
+    {
+        return _builderMethod.getReturnType();
+    }
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceIdConflictMethodBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceIdConflictMethodBuilder.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceIdConflictMethodBuilder.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/ioc/ServiceIdConflictMethodBuilder.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,34 @@
+// Copyright 2006 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.internal.ioc;
+
+/**
+ * Used by {@link org.apache.tapestry.internal.ioc.ModuleGrinderTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class ServiceIdConflictMethodBuilder
+{
+    public FieService buildFred()
+    {
+        return null;
+    }
+
+    public FieService buildFred(Object param)
+    {
+        return null;
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSource.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSource.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSource.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.pageload;
 
 import java.util.Locale;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImpl.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImpl.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.pageload;
 
 import static org.apache.tapestry.util.CollectionFactory.newMap;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoader.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoader.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoader.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoader.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.pageload;
 
 import java.util.Locale;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoaderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoaderImpl.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoaderImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/pageload/PageLoaderImpl.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.pageload;
 
 import static org.apache.tapestry.util.CollectionFactory.newList;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TokenType.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TokenType.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TokenType.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TokenType.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.parser;
 
 /**

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElement.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElement.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElement.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElement.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.structure;
 
 import org.apache.tapestry.internal.InternalComponentResources;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.structure;
 
 import java.util.List;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/MarkupPageElement.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/MarkupPageElement.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/MarkupPageElement.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/MarkupPageElement.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.structure;
 
 import org.apache.tapestry.internal.parser.TemplateToken;

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ErrorLog.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ErrorLog.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ErrorLog.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ErrorLog.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,46 @@
+// Copyright 2006 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;
+
+/**
+ * Used by services and other code to log errors that occur during construction.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface ErrorLog
+{
+    /**
+     * Notification of a non-fatal error.
+     * 
+     * @param message
+     *            message to log to the console or a log file
+     * @param exception
+     *            optional exception related to the message
+     */
+    void warn(String message, Throwable exception);
+
+    /**
+     * Notification of a serious error. The error will be logged and the ErrorLog implementation may
+     * decide to either throw a runtime exception (and abort the operation, whatever it was), or
+     * return to allow the code to attempt to continue (other failures, such as
+     * NullPointerException, are likely). *
+     * 
+     * @param message
+     *            message to log to the console or a log file
+     * @param exception
+     *            optional exception related to the message
+     */
+    void fail(String message, Throwable exception);
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/ServiceResources.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,39 @@
+// Copyright 2006 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;
+
+/**
+ * Contains resources that may be provided to a service when it initializes, which includes other
+ * services visible to the service.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface ServiceResources
+{
+    /**
+     * Locates a service given a fully qualified service id and the corresponding service interface
+     * type.
+     * 
+     * @param <T>
+     * @param serviceId
+     *            fully qualified id of the service
+     * @param serviceInterface
+     *            the interface the service implements
+     * @return the service's proxy
+     * @throws RuntimeException
+     *             if the service does not exist (this is considered programmer error)
+     */
+    <T> T getService(String serviceId, Class<T> serviceInterface);
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Id.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Id.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Id.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ioc/annotations/Id.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,37 @@
+// Copyright 2006 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 java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Optional annotation placed on classes that are used as module builders. This is only needed when
+ * the desired module id does not match the module builder's package.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+@Target(TYPE)
+@Retention(RUNTIME)
+@Documented
+public @interface Id {
+
+    /** The fully qualified id of the module. */
+    String value();
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ioc/IOCStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ioc/IOCStrings.properties?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ioc/IOCStrings.properties (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ioc/IOCStrings.properties Mon Jul  3 07:23:04 2006
@@ -0,0 +1,18 @@
+# Copyright 2006 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.
+
+build-method-conflict=Service building method {0} conflicts with (has the same name as, but different parameters than) previously seen method {1} and has been ignored.
+void-build-method=Method {0} appears to be a service builder method, but a void return type doesn't make sense. The method has been ignored.
+build-method-wrong-return-type=Method {0} is named like a service builder method, but the return type is not acceptible (try an interface). The method has been ignored.
+missing-service=Service ''{0}'' (within module ''{1}'') does not exist.
\ No newline at end of file

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml Mon Jul  3 07:23:04 2006
@@ -18,6 +18,7 @@
 <suite name="Tapestry 5">
   <test verbose="2" name="General" annotations="1.5">
     <packages>
+      <package name="org.apache.tapestry.internal.ioc"/>
       <package name="org.apache.tapestry.transform"/>
       <package name="org.apache.tapestry.internal.transform"/>
       <package name="org.apache.tapestry.internal.transform.worker"/>

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FieService.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FieService.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FieService.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FieService.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,25 @@
+// Copyright 2006 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.internal.ioc;
+
+/**
+ * A placeholder for a real service interface.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface FieService
+{
+    void fie();
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FoeService.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FoeService.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FoeService.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/FoeService.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,25 @@
+// Copyright 2006 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.internal.ioc;
+
+/**
+ * A placeholder for a real service interface.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public interface FoeService
+{
+    int foe();
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleBuilderWithId.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleBuilderWithId.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleBuilderWithId.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleBuilderWithId.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,28 @@
+// Copyright 2006 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.internal.ioc;
+
+import org.apache.tapestry.ioc.annotations.Id;
+
+/**
+ * Used by {@link org.apache.tapestry.internal.ioc.ModuleGrinderTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+@Id("tapestry.ioc")
+public class ModuleBuilderWithId
+{
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleGrinderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleGrinderTest.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleGrinderTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/ModuleGrinderTest.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,146 @@
+// Copyright 2006 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.internal.ioc;
+
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.util.Set;
+
+import org.apache.tapestry.ioc.ErrorLog;
+import org.apache.tapestry.test.TestBase;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import static org.apache.tapestry.internal.ioc.IOCMessages.buildMethodConflict;
+import static org.testng.Assert.assertEquals;
+
+/**
+ * @author Howard M. Lewis Ship
+ */
+public class ModuleGrinderTest extends TestBase
+{
+    @Test
+    public void moduleBuilderWithoutId()
+    {
+        ErrorLog log = newErrorLog();
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleGrinder g = new ModuleGrinder(BigDecimal.class, log);
+
+        Assert.assertEquals("java.math", g.getModuleId());
+
+        verify();
+    }
+
+    protected final ErrorLog newErrorLog()
+    {
+        return newMock(ErrorLog.class);
+    }
+
+    @Test
+    public void moduleBuilderWithId()
+    {
+        ErrorLog log = newErrorLog();
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleGrinder g = new ModuleGrinder(ModuleBuilderWithId.class, log);
+
+        Assert.assertEquals("tapestry.ioc", g.getModuleId());
+
+        verify();
+    }
+
+    @Test
+    public void simpleModule() throws Exception
+    {
+        ErrorLog log = newErrorLog();
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleGrinder g = new ModuleGrinder(SimpleModuleBuilder.class, log);
+
+        Set<String> ids = g.getServiceIds();
+
+        Assert.assertEquals(ids.size(), 2);
+        Assert.assertTrue(ids.contains("Fred"));
+        Assert.assertTrue(ids.contains("Barney"));
+
+        ServiceDef sd = g.getServiceDef("Fred");
+
+        assertEquals(sd.getServiceId(), "Fred");
+
+        assertEquals(sd.getServiceInterface(), FieService.class);
+
+        assertEquals(sd.getBuilderMethod(), SimpleModuleBuilder.class.getMethod("buildFred"));
+
+        sd = g.getServiceDef("Barney");
+
+        assertEquals(sd.getServiceId(), "Barney");
+
+        assertEquals(sd.getServiceInterface(), FoeService.class);
+
+        assertEquals(sd.getBuilderMethod(), SimpleModuleBuilder.class.getMethod("buildBarney"));
+
+        verify();
+    }
+
+    /** Two different methods both claim to build the same service. */
+    @Test
+    public void serviceIdConflict() throws Exception
+    {
+        Method conflictMethod = ServiceIdConflictMethodBuilder.class.getMethod("buildFred");
+        Method expectedMethod = ServiceIdConflictMethodBuilder.class.getMethod(
+                "buildFred",
+                Object.class);
+
+        ErrorLog log = newErrorLog();
+
+        log.warn(buildMethodConflict(conflictMethod, expectedMethod), null);
+
+        replay();
+
+        // BigDecimal is arbitrary, any class would do.
+
+        ModuleGrinder g = new ModuleGrinder(ServiceIdConflictMethodBuilder.class, log);
+
+        Set<String> ids = g.getServiceIds();
+
+        Assert.assertEquals(ids.size(), 1);
+        Assert.assertTrue(ids.contains("Fred"));
+
+        ServiceDef sd = g.getServiceDef("Fred");
+
+        assertEquals(sd.getServiceId(), "Fred");
+
+        assertEquals(sd.getServiceInterface(), FieService.class);
+
+        // The methods are considered in ascending order, by name, then descending order, by
+        // parameter count. So the grinder will latch onto the method that takes a parameter,
+        // and consider the other method (with no parameters) the conflict.
+
+        assertEquals(sd.getBuilderMethod(), expectedMethod);
+
+        verify();
+    }
+
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SimpleModuleBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SimpleModuleBuilder.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SimpleModuleBuilder.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/ioc/SimpleModuleBuilder.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,38 @@
+// Copyright 2006 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.internal.ioc;
+
+/**
+ * Used by {@link org.apache.tapestry.internal.ioc.ModuleGrinderTest}.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class SimpleModuleBuilder
+{
+    public FieService buildFred()
+    {
+        return null;
+    }
+
+    public FoeService buildBarney()
+    {
+        return null;
+    }
+
+    public void ignoredMethod()
+    {
+
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImplTest.java?rev=418774&r1=418773&r2=418774&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/pageload/ComponentTemplateSourceImplTest.java Mon Jul  3 07:23:04 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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.internal.pageload;
 
 import static org.testng.Assert.assertSame;

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/transform/SyncCostBench.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/transform/SyncCostBench.java?rev=418774&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/transform/SyncCostBench.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/transform/SyncCostBench.java Mon Jul  3 07:23:04 2006
@@ -0,0 +1,211 @@
+// Copyright 2006 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.transform;
+
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.tapestry.internal.annotations.Synchronized;
+
+import static java.lang.String.format;
+import static java.lang.System.out;
+
+/**
+ * Tests single-thread synchronization overhead using different techniques. Note that we're fudging
+ * things a bit by getting a read lock for a write operation .... it's just that I'm more concerned
+ * about read locks (which will be very common) than about write locks (very rare). Another concern
+ * is that hotspot is going to mess up our synchronization when it see we're not really doing
+ * anything multi-threaded.
+ * <p>
+ * The results show that using the {@link org.apache.tapestry.internal.annotations.Synchronized}
+ * aspect (which used a {@link java.util.concurrent.locks.ReentrantReadWriteLock} under the covers)
+ * is about 4x as expensive as just using the synchronized keyword. There are some anomolous results
+ * ... for example, ReadWriteLockRunner is consistently slower than ReadWriteLockAspectRunner (one
+ * would expect it to be the other way around ... must be something about how AspectJ weaves the
+ * code ... and it's use of static methods in many cases).
+ */
+public class SyncCostBench
+{
+    /** Calculates a fibunacci series. */
+    static class Worker implements Runnable
+    {
+        private long[] _series =
+        { 1, 1 };
+
+        public void run()
+        {
+            long value = _series[0] + _series[1];
+
+            // Now shift the values down to prepare for the next iteration.
+
+            _series[0] = _series[1];
+            _series[1] = value;
+        }
+    }
+
+    static class SimpleRunner implements Runnable
+    {
+        private final Runnable _delegate;
+
+        public SimpleRunner(Runnable delegate)
+        {
+            _delegate = delegate;
+        }
+
+        public void run()
+        {
+            _delegate.run();
+        }
+    }
+
+    static class SynchronizedRunner implements Runnable
+    {
+        private final Runnable _delegate;
+
+        public SynchronizedRunner(Runnable delegate)
+        {
+            _delegate = delegate;
+        }
+
+        public synchronized void run()
+        {
+            _delegate.run();
+        }
+    }
+
+    @Synchronized
+    static class ReadWriteLockAspectRunner implements Runnable
+    {
+        private final Runnable _delegate;
+
+        public ReadWriteLockAspectRunner(Runnable delegate)
+        {
+            _delegate = delegate;
+        }
+
+        @Synchronized.Read
+        public void run()
+        {
+            _delegate.run();
+        }
+    }
+
+    static class ReadWriteLockRunner implements Runnable
+    {
+        private final Runnable _delegate;
+
+        private final ReadWriteLock _lock = new ReentrantReadWriteLock();
+
+        public ReadWriteLockRunner(Runnable delegate)
+        {
+            _delegate = delegate;
+        }
+
+        public void run()
+        {
+
+            try
+            {
+                _lock.readLock().lock();
+
+                _delegate.run();
+            }
+            finally
+            {
+                _lock.readLock().unlock();
+            }
+
+        }
+    }
+
+    private static final int WARMUP_BLOCK_SIZE = 1000;
+
+    private static final int BLOCK_SIZE = 5 * 1000 * 1000;
+
+    static class BlockRunner implements Runnable
+    {
+        private final Runnable _delegate;
+
+        private final int _blockSize;
+
+        public BlockRunner(int blockSize, Runnable delegate)
+        {
+            _blockSize = blockSize;
+            _delegate = delegate;
+        }
+
+        public void run()
+        {
+            for (int i = 0; i < _blockSize; i++)
+                _delegate.run();
+        }
+    }
+
+    public static void main(String[] args) throws Exception
+    {
+        Runnable simple = new SimpleRunner(new Worker());
+        Runnable synched = new SynchronizedRunner(new Worker());
+        Runnable rw = new ReadWriteLockRunner(new Worker());
+        Runnable aspect = new ReadWriteLockAspectRunner(new Worker());
+
+        out.println(format("%40s %9s %9s %9s", ",simple", ",synched", ",rw", ",aspect"));
+
+        stage("warmup");
+
+        go(WARMUP_BLOCK_SIZE, simple);
+        go(WARMUP_BLOCK_SIZE, synched);
+        go(WARMUP_BLOCK_SIZE, rw);
+        go(WARMUP_BLOCK_SIZE, aspect);
+
+        out.println();
+
+        for (int i = 0; i < 10; i++)
+        {
+            Thread.sleep(5 * 1000);
+            System.gc();
+
+            stage(format("stage #%d", i + 1));
+            go(BLOCK_SIZE, simple);
+            go(BLOCK_SIZE, synched);
+            go(BLOCK_SIZE, rw);
+            go(BLOCK_SIZE, aspect);
+
+            out.println();
+        }
+    }
+
+    private static void stage(String name)
+    {
+        out.print(format("%30s", name));
+    }
+
+    private static void go(int blockSize, Runnable runner) throws InterruptedException
+    {
+
+        Thread t = new Thread(new BlockRunner(blockSize, runner));
+
+        long tick = System.nanoTime();
+
+        t.start();
+
+        // Now wait for it to finish.
+
+        t.join();
+
+        long tock = System.nanoTime();
+
+        out.print(format(",%9d", tock - tick));
+    }
+}



Mime
View raw message