diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-20 00:17:14 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-20 00:17:14 +0000 |
commit | e5fe5eff23e107d68b2486add75748fdab26fbde (patch) | |
tree | 136139a6b7f50d70a108b53f11c06a026494efcc /java/sca/modules/implementation-java | |
parent | 3a90e0b350d52cea1f52d05f6d98513ac520150a (diff) |
Turn JavaClassVisitor to declarative services and remove the module activator
Add a ServiceHelper utility to simplify the instantiation of declared services
Refactor the module activator to receive ExtensionPointRegistry from constructor
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@826907 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-java')
28 files changed, 269 insertions, 305 deletions
diff --git a/java/sca/modules/implementation-java/META-INF/MANIFEST.MF b/java/sca/modules/implementation-java/META-INF/MANIFEST.MF index c7694912c8..517aaac39f 100644 --- a/java/sca/modules/implementation-java/META-INF/MANIFEST.MF +++ b/java/sca/modules/implementation-java/META-INF/MANIFEST.MF @@ -30,6 +30,7 @@ Import-Package: javax.jws, org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.definitions;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
org.apache.tuscany.sca.implementation.java;version="2.0.0",
org.apache.tuscany.sca.implementation.java.introspect;version="2.0.0",
org.apache.tuscany.sca.interfacedef;version="2.0.0",
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java index e44ebd7c91..f98a617925 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java @@ -23,11 +23,18 @@ package org.apache.tuscany.sca.implementation.java; * * @version $Rev$ $Date$ */ +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.impl.JavaImplementationFactoryImpl; public class DefaultJavaImplementationFactory extends JavaImplementationFactoryImpl implements JavaImplementationFactory { + public DefaultJavaImplementationFactory(ExtensionPointRegistry registry) { + super(registry); + } + + // For UNIT test only public DefaultJavaImplementationFactory() { + super(new DefaultExtensionPointRegistry()); } - } diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationActivator.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationActivator.java deleted file mode 100644 index f72b40d794..0000000000 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationActivator.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.tuscany.sca.implementation.java; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.ModuleActivator; -import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor; -import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor; -import org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.policy.PolicyFactory; - -/** - * A module activator for the Java implementation model. - * - * @version $Rev$ $Date$ - */ -public class JavaImplementationActivator implements ModuleActivator { - - public void start(ExtensionPointRegistry registry) { - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); - PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.class); - - BaseJavaClassVisitor[] extensions = - new BaseJavaClassVisitor[] {new ConstructorProcessor(assemblyFactory), - new AllowsPassByReferenceProcessor(assemblyFactory), - new ComponentNameProcessor(assemblyFactory), - new ContextProcessor(assemblyFactory), - new DestroyProcessor(assemblyFactory), new EagerInitProcessor(assemblyFactory), - new InitProcessor(assemblyFactory), new PropertyProcessor(assemblyFactory), - new ReferenceProcessor(assemblyFactory, javaFactory), - new ResourceProcessor(assemblyFactory), new ScopeProcessor(assemblyFactory), - new ServiceProcessor(assemblyFactory, javaFactory), - new HeuristicPojoProcessor(assemblyFactory, javaFactory), - new PolicyProcessor(assemblyFactory, policyFactory)}; - - JavaImplementationFactory javaImplementationFactory = modelFactories.getFactory(JavaImplementationFactory.class); - for (JavaClassVisitor extension : extensions) { - javaImplementationFactory.addClassVisitor(extension); - } - - } - - public void stop(ExtensionPointRegistry registry) { - } - -} diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java index d6361a5655..a1f65ecc00 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java @@ -18,14 +18,21 @@ */ package org.apache.tuscany.sca.implementation.java.impl; +import java.io.IOException; +import java.lang.reflect.Constructor; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor; + /** * A factory for the Java model. * @@ -35,9 +42,11 @@ public abstract class JavaImplementationFactoryImpl implements JavaImplementatio private List<JavaClassVisitor> visitors = new ArrayList<JavaClassVisitor>(); private JavaClassIntrospectorImpl introspector; + private boolean loaded; + protected ExtensionPointRegistry registry; - public JavaImplementationFactoryImpl() { - introspector = new JavaClassIntrospectorImpl(visitors); + public JavaImplementationFactoryImpl(ExtensionPointRegistry registry) { + this.registry = registry; } public JavaImplementation createJavaImplementation() { @@ -47,12 +56,12 @@ public abstract class JavaImplementationFactoryImpl implements JavaImplementatio public JavaImplementation createJavaImplementation(Class<?> implementationClass) throws IntrospectionException { JavaImplementation javaImplementation = createJavaImplementation(); - introspector.introspectClass(javaImplementation, implementationClass); + getIntrospector().introspectClass(javaImplementation, implementationClass); return javaImplementation; } public void createJavaImplementation(JavaImplementation javaImplementation, Class<?> implementationClass) throws IntrospectionException { - introspector.introspectClass(javaImplementation, implementationClass); + getIntrospector().introspectClass(javaImplementation, implementationClass); } public void addClassVisitor(JavaClassVisitor visitor) { @@ -71,7 +80,57 @@ public abstract class JavaImplementationFactoryImpl implements JavaImplementatio } public List<JavaClassVisitor> getClassVisitors() { + loadVisitors(); return visitors; } + + /** + * Load visitors declared under META-INF/services + */ + @SuppressWarnings("unchecked") + private synchronized void loadVisitors() { + if (loaded) + return; + + // Get the databinding service declarations + Collection<ServiceDeclaration> visitorDeclarations; + try { + visitorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(JavaClassVisitor.class, true); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load data bindings + for (ServiceDeclaration visitorDeclaration: visitorDeclarations) { + JavaClassVisitor visitor = null; + try { + Class<JavaClassVisitor> visitorClass = (Class<JavaClassVisitor>)visitorDeclaration.loadClass(); + + try { + Constructor<JavaClassVisitor> constructor = visitorClass.getConstructor(ExtensionPointRegistry.class); + visitor = constructor.newInstance(registry); + } catch (NoSuchMethodException e) { + visitor = visitorClass.newInstance(); + } + + + } catch (Exception e) { + IllegalStateException ie = new IllegalStateException(e); + throw ie; + } + + addClassVisitor(visitor); + } + + loaded = true; + } + + private synchronized JavaClassIntrospectorImpl getIntrospector() { + if (introspector != null) { + return introspector; + } + introspector = new JavaClassIntrospectorImpl(getClassVisitors()); + return introspector; + } } diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/BaseJavaClassVisitor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/BaseJavaClassVisitor.java index 39b20d41eb..26ca54df88 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/BaseJavaClassVisitor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/BaseJavaClassVisitor.java @@ -23,9 +23,12 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaParameterImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; /** * A convenience class for annotation processors which alleviates the need to @@ -35,11 +38,19 @@ import org.apache.tuscany.sca.implementation.java.JavaParameterImpl; */ public abstract class BaseJavaClassVisitor implements JavaClassVisitor { protected AssemblyFactory assemblyFactory; + protected JavaInterfaceFactory javaInterfaceFactory; protected BaseJavaClassVisitor(AssemblyFactory factory) { this.assemblyFactory = factory; } + protected BaseJavaClassVisitor(ExtensionPointRegistry registry) { + super(); + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = factories.getFactory(AssemblyFactory.class); + this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class); + } + public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException { } diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java index d70cdc114c..b951e17fd2 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java @@ -27,8 +27,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -46,8 +46,8 @@ import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper; public abstract class AbstractPropertyProcessor<A extends Annotation> extends BaseJavaClassVisitor { private final Class<A> annotationClass; - protected AbstractPropertyProcessor(AssemblyFactory assemblyFactory, Class<A> annotationClass) { - super(assemblyFactory); + protected AbstractPropertyProcessor(ExtensionPointRegistry registry, Class<A> annotationClass) { + super(registry); this.annotationClass = annotationClass; } diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java index b08a1f6182..4aa29d3b91 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java @@ -21,6 +21,7 @@ package org.apache.tuscany.sca.implementation.java.introspect.impl; import java.lang.reflect.Method; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor; @@ -37,6 +38,10 @@ public class AllowsPassByReferenceProcessor extends BaseJavaClassVisitor { super(factory); } + public AllowsPassByReferenceProcessor(ExtensionPointRegistry registry) { + super(registry); + } + @Override public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException { type.setAllowsPassByReference(clazz.isAnnotationPresent(AllowsPassByReference.class)); diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java index fd6dbcc1ed..1813a177b4 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java @@ -22,6 +22,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -42,6 +43,10 @@ public class ComponentNameProcessor extends BaseJavaClassVisitor { public ComponentNameProcessor(AssemblyFactory factory) { super(factory); } + + public ComponentNameProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException { diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java index 2d5470c08c..68f0b46f2e 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java @@ -21,13 +21,12 @@ package org.apache.tuscany.sca.implementation.java.introspect.impl; import java.lang.reflect.Constructor; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaConstructorImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaParameterImpl; import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor; -import org.oasisopen.sca.annotation.Property; -import org.oasisopen.sca.annotation.Reference; /** * Handles processing of a constructor decorated with @@ -41,6 +40,10 @@ public class ConstructorProcessor extends BaseJavaClassVisitor { public ConstructorProcessor(AssemblyFactory factory) { super(factory); } + + public ConstructorProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException { diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java index 0694def99a..651ecdbd7e 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java @@ -22,6 +22,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -44,6 +45,10 @@ public class ContextProcessor extends BaseJavaClassVisitor { public ContextProcessor(AssemblyFactory factory) { super(factory); } + + public ContextProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException { diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java index 68cfc4c189..25f31c5f12 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor; @@ -38,6 +39,10 @@ public class DestroyProcessor extends BaseJavaClassVisitor { public DestroyProcessor(AssemblyFactory factory) { super(factory); } + + public DestroyProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException { diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java index ca02c96834..9ad7e8f7a9 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.implementation.java.introspect.impl; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor; @@ -35,6 +36,10 @@ public class EagerInitProcessor extends BaseJavaClassVisitor { super(factory); } + public EagerInitProcessor(ExtensionPointRegistry registry) { + super(registry); + } + @Override public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException { diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java index 551909e9bc..87a8031ea7 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java @@ -42,6 +42,7 @@ import javax.jws.WebService; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaConstructorImpl; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; @@ -74,12 +75,15 @@ import org.oasisopen.sca.annotation.Remotable; * @version $Rev$ $Date$ */ public class HeuristicPojoProcessor extends BaseJavaClassVisitor { - private JavaInterfaceFactory javaFactory; public HeuristicPojoProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) { super(assemblyFactory); - this.javaFactory = javaFactory; + this.javaInterfaceFactory = javaFactory; } + + public HeuristicPojoProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException { @@ -442,13 +446,13 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor { throws IntrospectionException { org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference(); reference.setName(name); - JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); reference.setInterfaceContract(interfaceContract); try { - JavaInterface callInterface = javaFactory.createJavaInterface(paramType); + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(paramType); reference.getInterfaceContract().setInterface(callInterface); if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass()); + JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); reference.getInterfaceContract().setCallbackInterface(callbackInterface); } reference.setMultiplicity(Multiplicity.ZERO_ONE); @@ -469,13 +473,13 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor { org.apache.tuscany.sca.assembly.Service service = assemblyFactory.createService(); service.setName(interfaze.getSimpleName()); - JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); service.setInterfaceContract(interfaceContract); - JavaInterface callInterface = javaFactory.createJavaInterface(interfaze); + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze); service.getInterfaceContract().setInterface(callInterface); if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass()); + JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); service.getInterfaceContract().setCallbackInterface(callbackInterface); } @@ -491,7 +495,7 @@ public class HeuristicPojoProcessor extends BaseJavaClassVisitor { Class<?> callbackClass = callback.value(); JavaInterface javaInterface; try { - javaInterface = javaFactory.createJavaInterface(callbackClass); + javaInterface = javaInterfaceFactory.createJavaInterface(callbackClass); contract.getInterfaceContract().setCallbackInterface(javaInterface); } catch (InvalidInterfaceException e) { throw new InvalidServiceTypeException("Invalid callback interface "+callbackClass, interfaze); diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java index 8d12f14729..8d67236fe2 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java @@ -22,6 +22,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor; @@ -39,6 +40,10 @@ public class InitProcessor extends BaseJavaClassVisitor { super(factory); } + public InitProcessor(ExtensionPointRegistry registry) { + super(registry); + } + @Override public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException { Init annotation = method.getAnnotation(Init.class); diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java index ac7187b1c7..1b75ff938c 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java @@ -19,26 +19,29 @@ package org.apache.tuscany.sca.implementation.java.introspect.impl; import java.lang.annotation.Annotation; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Callback; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.java.IntrospectionException; +import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.introspect.BaseJavaClassVisitor; -import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.policy.PolicySet; @@ -56,57 +59,16 @@ public class PolicyProcessor extends BaseJavaClassVisitor { private PolicyFactory policyFactory; - public PolicyProcessor(AssemblyFactory assemblyFactory, PolicyFactory policyFactory) { + public PolicyProcessor(AssemblyFactory assemblyFactory, PolicyFactory policyFactory, JavaInterfaceFactory javaInterfaceFactory) { super(assemblyFactory); this.policyFactory = policyFactory; + this.javaInterfaceFactory = javaInterfaceFactory; } - - - @Override - public void visitField(Field field, JavaImplementation type) throws IntrospectionException { - org.oasisopen.sca.annotation.Reference annotation = - field.getAnnotation( org.oasisopen.sca.annotation.Reference.class); - if (annotation == null) { - return; - } - String name = annotation.name(); - if ("".equals(name)) { - name = field.getName(); - } - - Reference reference = null; - if ( (reference = getReferenceByName(name, type)) != null ) { - readIntents(field.getAnnotation(Requires.class), reference.getRequiredIntents()); - readSpecificIntents(field.getAnnotations(), reference.getRequiredIntents()); - readPolicySets(field.getAnnotation(PolicySets.class), reference.getPolicySets()); - } - } - - @Override - public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException { - Reference reference = null; - if ( (reference = getReference(method, type)) != null ) { - readIntents(method.getAnnotation(Requires.class), reference.getRequiredIntents()); - readSpecificIntents(method.getAnnotations(), reference.getRequiredIntents()); - readPolicySets(method.getAnnotation(PolicySets.class), reference.getPolicySets()); - } else { - /* - if ( type instanceof OperationsConfigurator ) { - //Read the intents specified on the given implementation method - if ( (method.getAnnotation(Requires.class) != null || - method.getAnnotation(PolicySets.class) != null ) && - (type instanceof PolicySubject )) { - ConfiguredOperation confOp = assemblyFactory.createConfiguredOperation(); - confOp.setName(method.getName()); - ((OperationsConfigurator)type).getConfiguredOperations().add(confOp); - - - readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents()); - readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets()); - } - } - */ - } + + public PolicyProcessor(ExtensionPointRegistry registry) { + super(registry); + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.policyFactory = factories.getFactory(PolicyFactory.class); } @Override @@ -118,72 +80,53 @@ public class PolicyProcessor extends BaseJavaClassVisitor { ((PolicySubject)type).getRequiredIntents(), ((PolicySubject)type).getPolicySets()); } - - // Process annotations on the service interfaces - //TODO This will have to move to a JavaInterface introspector later - for (Service service: type.getServices()) { - InterfaceContract interfaceContract = service.getInterfaceContract(); - if (interfaceContract instanceof JavaInterfaceContract) { - JavaInterfaceContract javaInterfaceContract = (JavaInterfaceContract)interfaceContract; - - // Read intents on the service interface - if (javaInterfaceContract.getInterface() != null) { - JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface(); - if (javaInterface.getJavaClass() != null) { - readIntentsAndPolicySets(javaInterface.getJavaClass(), - service.getRequiredIntents(), - service.getPolicySets()); - /* - // Read intents on the service interface methods - Method[] methods = javaInterface.getJavaClass().getMethods(); - ConfiguredOperation confOp = null; - for (Method method: methods) { - if ( method.getAnnotation(Requires.class) != null || - method.getAnnotation(PolicySets.class) != null ) { - confOp = assemblyFactory.createConfiguredOperation(); - confOp.setName(method.getName()); - confOp.setContractName(service.getName()); - - service.getConfiguredOperations().add(confOp); - readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents()); - readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets()); - } - } - */ - } - + // FIXME: [rfeng] We might want to refactor this out + // Find the business methods in the implementation class for all services + Set<Method> methods = new HashSet<Method>(); + for (Service service : type.getServices()) { + for (Operation op : service.getInterfaceContract().getInterface().getOperations()) { + Method method; + try { + method = JavaInterfaceUtil.findMethod(clazz, op); + } catch (NoSuchMethodException e1) { + throw new IntrospectionException(e1); } - - // Read intents on the callback interface - if (javaInterfaceContract.getCallbackInterface() != null) { - JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface(); - if (javaCallbackInterface.getJavaClass() != null) { - Callback callback = service.getCallback(); - if (callback == null) { - callback = assemblyFactory.createCallback(); - service.setCallback(callback); - } - readIntentsAndPolicySets(javaCallbackInterface.getJavaClass(), - callback.getRequiredIntents(), - callback.getPolicySets()); - - /* - // Read intents on the callback interface methods - Method[] methods = javaCallbackInterface.getJavaClass().getMethods(); - ConfiguredOperation confOp = null; - for (Method method: methods) { - confOp = assemblyFactory.createConfiguredOperation(); - confOp.setName(method.getName()); - callback.getConfiguredOperations().add(confOp); - readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents()); - readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets()); - } - */ - } + if (method != null) { + methods.add(method); } } } + for (Method method : methods) { + JavaOperation op = javaInterfaceFactory.createJavaOperation(method); + type.getOperations().add(op); + } + + // Read the operation-level policy settings for the implementation + for (Operation op : type.getOperations()) { + JavaOperation operation = (JavaOperation)op; + PolicySubject subject = op; + Method method = operation.getJavaMethod(); + if (subject != null) { + readIntents(method.getAnnotation(Requires.class), subject.getRequiredIntents()); + readSpecificIntents(method.getAnnotations(), subject.getRequiredIntents()); + readPolicySets(method.getAnnotation(PolicySets.class), subject.getPolicySets()); + } + } + + // Start to process annotations on the reference members + Map<String, Reference> referenceMap = new HashMap<String, Reference>(); + for(Reference ref: type.getReferences()) { + referenceMap.put(ref.getName(), ref); + } + Map<String, JavaElementImpl> members = type.getReferenceMembers(); + for(Map.Entry<String, JavaElementImpl> e: members.entrySet()) { + Reference reference = referenceMap.get(e.getKey()); + readIntents(e.getValue().getAnnotation(Requires.class), reference.getRequiredIntents()); + readSpecificIntents(e.getValue().getAnnotations(), reference.getRequiredIntents()); + readPolicySets(e.getValue().getAnnotation(PolicySets.class), reference.getPolicySets()); + } + } private void readSpecificIntents(Annotation[] annotations, List<Intent> requiredIntents) { @@ -342,44 +285,5 @@ public class PolicyProcessor extends BaseJavaClassVisitor { } return qname; } - - - /** - * - * @param name - * @param type - * @return - */ - private static Reference getReferenceByName(String name, JavaImplementation type) { - for ( Reference reference : type.getReferences() ) { - if ( reference.getName().equals(name) ) { - return reference; - } - } - return null; - } - - - /** - * - * @param method - * @param type - * @return - */ - private static Reference getReference(Method method, JavaImplementation type) { - //since the ReferenceProcessor is called ahead of the PolicyProcessor the type should have - //picked up the reference setter method - org.oasisopen.sca.annotation.Reference annotation = - method.getAnnotation(org.oasisopen.sca.annotation.Reference.class); - if (annotation != null) { - if (JavaIntrospectionHelper.isSetter(method)) { - String name = annotation.name(); - if ("".equals(name)) { - name = JavaIntrospectionHelper.toPropertyName(method.getName()); - } - return getReferenceByName(name, type); - } - } - return null; - } + } diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java index 4cbd5c013c..ed68be20b4 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java @@ -18,7 +18,7 @@ */ package org.apache.tuscany.sca.implementation.java.introspect.impl; -import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.oasisopen.sca.annotation.Property; /** @@ -29,10 +29,10 @@ import org.oasisopen.sca.annotation.Property; */ public class PropertyProcessor extends AbstractPropertyProcessor<Property> { - public PropertyProcessor(AssemblyFactory assemblyFactory) { - super(assemblyFactory, Property.class); + public PropertyProcessor(ExtensionPointRegistry registry) { + super(registry, Property.class); } - + @Override protected String getName(Property annotation) { return annotation.name(); diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java index 0733f0084c..d30ac074af 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java @@ -31,6 +31,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -52,12 +53,15 @@ import org.oasisopen.sca.annotation.Reference; * @version $Rev$ $Date$ */ public class ReferenceProcessor extends BaseJavaClassVisitor { - private JavaInterfaceFactory javaFactory; public ReferenceProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) { super(assemblyFactory); - this.javaFactory = javaFactory; + this.javaInterfaceFactory = javaFactory; } + + public ReferenceProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException { @@ -173,7 +177,7 @@ public class ReferenceProcessor extends BaseJavaClassVisitor { private org.apache.tuscany.sca.assembly.Reference createReference(JavaElementImpl element, String name) throws IntrospectionException { org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference(); - JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); reference.setInterfaceContract(interfaceContract); // reference.setMember((Member)element.getAnchor()); @@ -207,10 +211,10 @@ public class ReferenceProcessor extends BaseJavaClassVisitor { baseType = JavaIntrospectionHelper.getBusinessInterface(baseType, genericType); } try { - JavaInterface callInterface = javaFactory.createJavaInterface(baseType); + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(baseType); reference.getInterfaceContract().setInterface(callInterface); if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass()); + JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); reference.getInterfaceContract().setCallbackInterface(callbackInterface); } } catch (InvalidInterfaceException e) { diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java index 49320579d0..3abe832cb9 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java @@ -23,6 +23,7 @@ import java.lang.reflect.Member; import java.lang.reflect.Method; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -42,6 +43,10 @@ public class ResourceProcessor extends BaseJavaClassVisitor { public ResourceProcessor(AssemblyFactory factory) { super(factory); } + + public ResourceProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException { diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java index 66be4f1f1e..dfc122c715 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.implementation.java.introspect.impl; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaScopeImpl; @@ -34,6 +35,10 @@ public class ScopeProcessor extends BaseJavaClassVisitor { public ScopeProcessor(AssemblyFactory factory) { super(factory); } + + public ScopeProcessor(ExtensionPointRegistry registry) { + super(registry); + } @Override public <T> void visitClass(Class<T> clazz, diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java index 9753e4eff0..30ed5dda44 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java @@ -28,12 +28,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import java.util.logging.Logger; import javax.jws.WebService; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.IntrospectionException; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -55,12 +55,14 @@ import org.oasisopen.sca.annotation.Remotable; * @version $Rev$ $Date$ */ public class ServiceProcessor extends BaseJavaClassVisitor { - private static final Logger logger = Logger.getLogger(ServiceProcessor.class.getName()); - private JavaInterfaceFactory javaFactory; public ServiceProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) { super(assemblyFactory); - this.javaFactory = javaFactory; + this.javaInterfaceFactory = javaFactory; + } + + public ServiceProcessor(ExtensionPointRegistry registry) { + super(registry); } @Override @@ -180,7 +182,7 @@ public class ServiceProcessor extends BaseJavaClassVisitor { public Service createService(Class<?> interfaze, String name) throws InvalidInterfaceException { Service service = assemblyFactory.createService(); - JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); service.setInterfaceContract(interfaceContract); if (name == null) { @@ -189,10 +191,10 @@ public class ServiceProcessor extends BaseJavaClassVisitor { service.setName(name); } - JavaInterface callInterface = javaFactory.createJavaInterface(interfaze); + JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze); service.getInterfaceContract().setInterface(callInterface); if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass()); + JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass()); service.getInterfaceContract().setCallbackInterface(callbackInterface); } return service; diff --git a/java/sca/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/java/sca/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator deleted file mode 100644 index 856d4e55b2..0000000000 --- a/java/sca/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator +++ /dev/null @@ -1,18 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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.
-
-org.apache.tuscany.sca.implementation.java.JavaImplementationActivator
diff --git a/java/sca/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor b/java/sca/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor new file mode 100644 index 0000000000..7bddb31227 --- /dev/null +++ b/java/sca/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0
+# "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.
+#
+# NOTE: The ranking attribute is important for the JavaClassVistors
+# Some visitors need to be called after the others
+org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor;ranking=200
+org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor;ranking=190
+org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor;ranking=180
+org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor;ranking=170
+org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor;ranking=160
+org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor;ranking=150
+org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor;ranking=140
+org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor;ranking=130
+org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor;ranking=120
+org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor;ranking=110
+org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor;ranking=100
+org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor;ranking=90
+org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor;ranking=80
+org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor;ranking=70
\ No newline at end of file diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java index a4d5c6fb95..b77aea4c78 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java @@ -51,11 +51,11 @@ public abstract class AbstractProcessorTest { factory = new DefaultAssemblyFactory(registry); javaFactory = new DefaultJavaInterfaceFactory(registry); referenceProcessor = new ReferenceProcessor(factory, javaFactory); - propertyProcessor = new PropertyProcessor(factory); + propertyProcessor = new PropertyProcessor(registry); resourceProcessor = new ResourceProcessor(factory); constructorProcessor = new ConstructorProcessor(factory); referenceProcessor = new ReferenceProcessor(factory, javaFactory); - propertyProcessor = new PropertyProcessor(factory); + propertyProcessor = new PropertyProcessor(registry); } protected <T> void visitConstructor(Constructor<T> constructor, diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java index e049ad0321..512e34a0fa 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java @@ -103,7 +103,7 @@ public class ConstructorProcessorTestCase { AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(registry); JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(registry); ReferenceProcessor referenceProcessor = new ReferenceProcessor(assemblyFactory, javaFactory); - PropertyProcessor propertyProcessor = new PropertyProcessor(assemblyFactory); + PropertyProcessor propertyProcessor = new PropertyProcessor(registry); JavaParameterImpl[] parameters = type.getConstructor().getParameters(); for (int i = 0; i < parameters.length; i++) { referenceProcessor.visitConstructorParameter(parameters[i], type); @@ -179,7 +179,7 @@ public class ConstructorProcessorTestCase { AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(registry); ReferenceProcessor referenceProcessor = new ReferenceProcessor(assemblyFactory, javaFactory); - PropertyProcessor propertyProcessor = new PropertyProcessor(assemblyFactory); + PropertyProcessor propertyProcessor = new PropertyProcessor(registry); JavaParameterImpl[] parameters = type.getConstructor().getParameters(); for (int i = 0; i < parameters.length; i++) { referenceProcessor.visitConstructorParameter(parameters[i], type); diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java index 6c8c84a200..39a2980b2b 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java @@ -22,15 +22,12 @@ import static org.junit.Assert.assertEquals; import java.lang.reflect.Constructor; -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory; import org.apache.tuscany.sca.implementation.java.JavaConstructorImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; -import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; import org.junit.Before; import org.junit.Test; import org.oasisopen.sca.annotation.Property; @@ -42,7 +39,6 @@ public class HeuristicAndPropertyTestCase { private PropertyProcessor propertyProcessor; private HeuristicPojoProcessor heuristicProcessor; - private AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory(); /** @@ -63,8 +59,8 @@ public class HeuristicAndPropertyTestCase { @Before public void setUp() throws Exception { ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); - propertyProcessor = new PropertyProcessor(assemblyFactory); - heuristicProcessor = new HeuristicPojoProcessor(assemblyFactory, new DefaultJavaInterfaceFactory(registry)); + propertyProcessor = new PropertyProcessor(registry); + heuristicProcessor = new HeuristicPojoProcessor(registry); } public static class Foo { diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java index c43db2df09..e1fe484a2e 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java @@ -35,7 +35,6 @@ import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.impl.PolicyJavaInterfaceVisitor; -import org.apache.tuscany.sca.policy.DefaultPolicyFactory; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicySubject; import org.junit.Before; @@ -246,7 +245,7 @@ public class PolicyProcessorTestCase { public void setUp() throws Exception { ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); serviceProcessor = new ServiceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(registry)); - policyProcessor = new PolicyProcessor(new DefaultAssemblyFactory(), new DefaultPolicyFactory()); + policyProcessor = new PolicyProcessor(registry); visitor = new PolicyJavaInterfaceVisitor(registry); JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory(); type = javaImplementationFactory.createJavaImplementation(); diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java index b89efd8b9f..559659cdeb 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java @@ -28,7 +28,7 @@ import java.lang.reflect.Method; import java.util.Collection; import java.util.List; -import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory; import org.apache.tuscany.sca.implementation.java.JavaElementImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -50,7 +50,7 @@ public class PropertyProcessorTestCase { public void setUp() throws Exception { JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory(); type = javaImplementationFactory.createJavaImplementation(); - processor = new PropertyProcessor(new DefaultAssemblyFactory()); + processor = new PropertyProcessor(new DefaultExtensionPointRegistry()); } @Test diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/TestAbstractPropertyProcessorTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/TestAbstractPropertyProcessorTestCase.java index 6cdc9224bf..a90a6d18c7 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/TestAbstractPropertyProcessorTestCase.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/TestAbstractPropertyProcessorTestCase.java @@ -29,8 +29,8 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; -import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory; import org.apache.tuscany.sca.implementation.java.JavaConstructorImpl; import org.apache.tuscany.sca.implementation.java.JavaImplementation; @@ -129,7 +129,7 @@ public class TestAbstractPropertyProcessorTestCase { private class TestProcessor extends AbstractPropertyProcessor<Bar> { public TestProcessor() { - super(new DefaultAssemblyFactory(), Bar.class); + super(new DefaultExtensionPointRegistry(), Bar.class); } @Override |