hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r523821 - in /hivemind/hivemind2/trunk/annotations/src: java/org/apache/hivemind/annotations/definition/ java/org/apache/hivemind/annotations/definition/processors/ java/org/apache/hivemind/annotations/internal/ test/org/apache/hivemind/ann...
Date Thu, 29 Mar 2007 20:01:18 GMT
Author: ahuegen
Date: Thu Mar 29 13:01:16 2007
New Revision: 523821

URL: http://svn.apache.org/viewvc?view=rev&rev=523821
Log:
Implementation annotation added

Added:
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/Implementation.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ImplementationProcessor.java
    hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/OverrideServiceModule.java
Modified:
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
    hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
    hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java

Added: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/Implementation.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/Implementation.java?view=auto&rev=523821
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/Implementation.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/Implementation.java
Thu Mar 29 13:01:16 2007
@@ -0,0 +1,38 @@
+// 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.hivemind.annotations.definition;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.hivemind.internal.ServiceModel;
+
+/**
+ * Marks a method in an annotated module as the implementation of a service point.
+ * The return type of the method must match the corresponding service interface. 
+ * The method is used factory method for the construction of service implementations.
+ * 
+ * @author Achim Huegen
+ */
+@Documented
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = ElementType.METHOD)
+public @interface Implementation {
+    String serviceId();
+    String serviceModel() default ServiceModel.SINGLETON;
+}

Added: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ImplementationProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ImplementationProcessor.java?view=auto&rev=523821
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ImplementationProcessor.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ImplementationProcessor.java
Thu Mar 29 13:01:16 2007
@@ -0,0 +1,51 @@
+package org.apache.hivemind.annotations.definition.processors;
+
+import java.lang.reflect.Method;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hivemind.annotations.definition.Implementation;
+import org.apache.hivemind.annotations.definition.impl.AnnotatedModuleDefinitionImpl;
+import org.apache.hivemind.annotations.internal.CheckTools;
+import org.apache.hivemind.annotations.internal.MethodCallImplementationConstructor;
+import org.apache.hivemind.definition.ImplementationConstructor;
+import org.apache.hivemind.definition.ImplementationDefinition;
+import org.apache.hivemind.definition.impl.ImplementationDefinitionImpl;
+import org.apache.hivemind.util.IdUtils;
+
+public class ImplementationProcessor implements AnnotationProcessor
+{
+    private static final Log _log = LogFactory.getLog(ImplementationProcessor.class);
+
+    /**
+     * @see org.apache.hivemind.annotations.definition.processors.AnnotationProcessor#processAnnotation(org.apache.hivemind.annotations.definition.processors.AnnotationProcessingContext)
+     */
+    public boolean processAnnotation(AnnotationProcessingContext context)
+    {
+        Method method = (Method) context.getAnnotatedElement();
+        AnnotatedModuleDefinitionImpl module = context.getModule();
+        Implementation implementationAnnotation = (Implementation) context.getTargetAnnotation();

+        
+        CheckTools.checkMethodModifiers(method, 0, "implementation");
+        
+        if (_log.isDebugEnabled())
+        {
+            _log.debug("Method " + method.getName() + "classified as implementation.");
+        }
+        
+        // Create implementation constructor that calls the annotated method 
+        ImplementationConstructor constructor = new MethodCallImplementationConstructor(context.getLocation(),

+                method, context.getModuleInstanceProvider());
+
+        ImplementationDefinition id = new ImplementationDefinitionImpl(module, context.getLocation(),

+                constructor, implementationAnnotation.serviceModel(), true);
+        
+        String qualifiedServiceId = IdUtils.qualify(
+                module.getId(), implementationAnnotation.serviceId());
+
+        module.addImplementation(qualifiedServiceId, id);
+
+        return true;
+    }
+
+}

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java?view=diff&rev=523821&r1=523820&r2=523821
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/definition/processors/ServiceProcessor.java
Thu Mar 29 13:01:16 2007
@@ -47,7 +47,7 @@
                 method, context.getModuleInstanceProvider());
 
         ImplementationDefinition sid = new ImplementationDefinitionImpl(module, context.getLocation(),

-                constructor, serviceAnnotation.serviceModel(), true);
+                constructor, serviceAnnotation.serviceModel(), false);
 
         spd.addImplementation(sid);
 

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java?view=diff&rev=523821&r1=523820&r2=523821
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotatedModuleProcessor.java
Thu Mar 29 13:01:16 2007
@@ -67,6 +67,7 @@
     {
         _registryDefinition = registryDefinition;
         _classResolver = classResolver;
+        _annotationProcessorRegistry = annotationProcessorRegistry;
         _annotationProcessorFactory = new AnnotationProcessorFactory(annotationProcessorRegistry);
     }
     

Modified: hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java?view=diff&rev=523821&r1=523820&r2=523821
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/java/org/apache/hivemind/annotations/internal/AnnotationProcessorRegistryFactory.java
Thu Mar 29 13:01:16 2007
@@ -3,10 +3,12 @@
 import org.apache.hivemind.ClassResolver;
 import org.apache.hivemind.annotations.definition.Configuration;
 import org.apache.hivemind.annotations.definition.Contribution;
+import org.apache.hivemind.annotations.definition.Implementation;
 import org.apache.hivemind.annotations.definition.Service;
 import org.apache.hivemind.annotations.definition.Submodule;
 import org.apache.hivemind.annotations.definition.processors.ConfigurationProcessor;
 import org.apache.hivemind.annotations.definition.processors.ContributionProcessor;
+import org.apache.hivemind.annotations.definition.processors.ImplementationProcessor;
 import org.apache.hivemind.annotations.definition.processors.ServiceProcessor;
 import org.apache.hivemind.annotations.definition.processors.SubmoduleProcessor;
 
@@ -37,6 +39,7 @@
         processorRegistry.registerProcessor(Configuration.class, ConfigurationProcessor.class);
         processorRegistry.registerProcessor(Contribution.class, ContributionProcessor.class);
         processorRegistry.registerProcessor(Submodule.class, SubmoduleProcessor.class);
+        processorRegistry.registerProcessor(Implementation.class, ImplementationProcessor.class);
     }
     
 }

Added: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/OverrideServiceModule.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/OverrideServiceModule.java?view=auto&rev=523821
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/OverrideServiceModule.java
(added)
+++ hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/OverrideServiceModule.java
Thu Mar 29 13:01:16 2007
@@ -0,0 +1,37 @@
+// 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.hivemind.annotations;
+
+import hivemind.test.services.StringHolder;
+import hivemind.test.services.impl.StringHolderImpl;
+
+import org.apache.hivemind.annotations.definition.Implementation;
+import org.apache.hivemind.annotations.definition.Module;
+import org.apache.hivemind.annotations.definition.Service;
+import org.apache.hivemind.internal.ServiceModel;
+
+@Module(id = "testModule")
+public class OverrideServiceModule extends AbstractAnnotatedModule
+{
+    @Service(id = "Test")
+    public StringHolder getStringHolder() {
+        return null;
+    }
+
+    @Implementation(serviceId = "Test", serviceModel=ServiceModel.PRIMITIVE)
+    public StringHolder getStringHolderImpl() {
+        return new StringHolderImpl();
+    }
+}

Modified: hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
URL: http://svn.apache.org/viewvc/hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java?view=diff&rev=523821&r1=523820&r2=523821
==============================================================================
--- hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
(original)
+++ hivemind/hivemind2/trunk/annotations/src/test/org/apache/hivemind/annotations/TestAnnotatedModules.java
Thu Mar 29 13:01:16 2007
@@ -16,6 +16,7 @@
 
 import hivemind.test.services.ServiceAutowireTarget;
 import hivemind.test.services.StringHolder;
+import hivemind.test.services.impl.StringHolderImpl;
 
 public class TestAnnotatedModules extends AnnotationTestCase
 {
@@ -31,6 +32,14 @@
         TypedRegistry registry = constructRegistry(Supermodule.class);
         StringHolder service = registry.getService("super.sub.StringHolder", StringHolder.class);
         assertNotNull(service);
+    }
+
+    public void testOverrideServiceImplementation()
+    {
+        TypedRegistry registry = constructRegistry(OverrideServiceModule.class);
+        StringHolder service = registry.getService("testModule.Test", StringHolder.class);
+        assertNotNull(service);
+        assertEquals(service.getClass(), StringHolderImpl.class);
     }
 
 }



Mime
View raw message