From 8fa39d402acf47d516f6af27bc9bfec164d7e9c6 Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 22 Sep 2011 12:22:20 +0000 Subject: TUSCANY-3950 - Catch up with some differences in the OASIS SCA API classes. Tuscany now matches OASIS svn r286 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1174086 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/introspect/impl/ConstructorProcessor.java | 8 ----- .../impl/ConstructorProcessorTestCase.java | 14 +++++---- .../impl/ConstructorPropertyTestCase.java | 16 +++++----- .../impl/ConstructorReferenceTestCase.java | 8 ++--- .../impl/ConstructorResourceTestCase.java | 16 +++++----- .../src/main/java/org/oasisopen/sca/Constants.java | 2 +- .../org/oasisopen/sca/annotation/Constructor.java | 13 ++++---- .../sca/annotation/ManagedTransaction.java | 4 +-- .../org/oasisopen/sca/client/SCAClientFactory.java | 3 +- .../sca/client/SCAClientFactoryFinder.java | 3 +- .../client/impl/SCAClientFactoryFinderImpl.java | 36 ++++++++++++++++------ 11 files changed, 69 insertions(+), 54 deletions(-) (limited to 'sca-java-2.x/trunk') diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java index 52a3fbd89a..2017a9d75e 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java @@ -76,11 +76,6 @@ public class ConstructorProcessor extends BaseJavaClassVisitor { type.setConstructor(definition); } JavaParameterImpl[] parameters = definition.getParameters(); - String[] value = annotation.value(); - boolean isDefault = value.length == 0 || (value.length == 1 && "".equals(value[0])); - if (!isDefault && value.length != parameters.length) { - throw new InvalidConstructorException("Invalid Number of names in @Constructor"); - } for (JavaParameterImpl p : parameters) { if (!hasAnnotation(p)) { @@ -88,9 +83,6 @@ public class ConstructorProcessor extends BaseJavaClassVisitor { } } - for (int i = 0; i < parameters.length; i++) { - parameters[i].setName(i < value.length ? value[i] : ""); - } type.setConstructor(definition); } diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java index 512e34a0fa..c5ef426860 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java @@ -42,6 +42,7 @@ import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; import org.apache.tuscany.sca.implementation.java.JavaParameterImpl; import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.junit.Ignore; import org.junit.Test; import org.oasisopen.sca.annotation.Property; import org.oasisopen.sca.annotation.Reference; @@ -65,6 +66,7 @@ public class ConstructorProcessorTestCase { } } + @Ignore("TUSCANY-3950") // no names in constructor annotation now @Test public void testConstructorAnnotation() throws Exception { JavaImplementation type = javaImplementationFactory.createJavaImplementation(); @@ -117,19 +119,19 @@ public class ConstructorProcessorTestCase { private static class BadFoo { - @org.oasisopen.sca.annotation.Constructor("foo") + @org.oasisopen.sca.annotation.Constructor() public BadFoo(String foo) { } - @org.oasisopen.sca.annotation.Constructor( {"foo", "bar"}) - public BadFoo(String foo, String bar) { + @org.oasisopen.sca.annotation.Constructor() + public BadFoo(@Property String foo, @Property String bar) { } } private static class Foo { - @org.oasisopen.sca.annotation.Constructor("foo") + @org.oasisopen.sca.annotation.Constructor() public Foo(@Property String foo) { } @@ -141,8 +143,8 @@ public class ConstructorProcessorTestCase { } private static class BadAnnotation { - @org.oasisopen.sca.annotation.Constructor("foo") - public BadAnnotation(String foo, Foo ref) { + @org.oasisopen.sca.annotation.Constructor() + public BadAnnotation(@Property String foo, Foo ref) { } } diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java index 83e26dff84..cf0943a0d3 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java @@ -31,6 +31,7 @@ import java.util.List; import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +import org.junit.Ignore; import org.junit.Test; import org.oasisopen.sca.annotation.Property; @@ -99,11 +100,12 @@ public class ConstructorPropertyTestCase extends AbstractProcessorTest { try { visitConstructor(ctor, type); fail(); - } catch (InvalidConstructorException e) { + } catch (InvalidPropertyException e) { // expected } } + @Ignore("TUSCANY-3950") // no names in constructor annotation now @Test public void testNoMatchingNames() throws Exception { JavaImplementation type = javaImplementationFactory.createJavaImplementation(); @@ -129,8 +131,8 @@ public class ConstructorPropertyTestCase extends AbstractProcessorTest { } - @org.oasisopen.sca.annotation.Constructor("myProp") - public Foo(@Property Integer prop) { + @org.oasisopen.sca.annotation.Constructor() + public Foo(@Property(name = "myProp") Integer prop) { } @@ -157,13 +159,13 @@ public class ConstructorPropertyTestCase extends AbstractProcessorTest { } - @org.oasisopen.sca.annotation.Constructor("myProp") - public BadFoo(@Property Integer prop, @Property Integer prop2) { + @org.oasisopen.sca.annotation.Constructor() + public BadFoo(@Property(name = "myProp") Integer prop, @Property Integer prop2) { } - @org.oasisopen.sca.annotation.Constructor({"myRef", "myRef2"}) - public BadFoo(@Property List ref, @Property(name = "myOtherRef")List ref2) { + @org.oasisopen.sca.annotation.Constructor() + public BadFoo(@Property(name = "myRef") List ref, @Property(name = "myOtherRef")List ref2) { } diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java index eeeee851e4..dda8049d6d 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java @@ -105,7 +105,7 @@ public class ConstructorReferenceTestCase extends AbstractProcessorTest { try { visitConstructor(ctor, type); fail(); - } catch (InvalidConstructorException e) { + } catch (InvalidReferenceException e) { // expected } } @@ -139,7 +139,7 @@ public class ConstructorReferenceTestCase extends AbstractProcessorTest { } - @org.oasisopen.sca.annotation.Constructor("myRef2") + @org.oasisopen.sca.annotation.Constructor() public Foo(@Reference(name = "myRef2") Integer prop) { } @@ -170,12 +170,12 @@ public class ConstructorReferenceTestCase extends AbstractProcessorTest { } - @org.oasisopen.sca.annotation.Constructor("myRef") + @org.oasisopen.sca.annotation.Constructor() public BadFoo(@Reference Integer ref, @Reference Integer ref2) { } - @org.oasisopen.sca.annotation.Constructor({"myRef", "myRef2"}) + @org.oasisopen.sca.annotation.Constructor() public BadFoo(@Reference List ref, @Reference(name = "myOtherRef")List ref2) { } diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java index e8d26f6103..b73dc6cf76 100644 --- a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java +++ b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java @@ -28,6 +28,7 @@ import java.util.List; import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory; import org.apache.tuscany.sca.implementation.java.JavaImplementation; import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +import org.junit.Ignore; import org.junit.Test; /** @@ -96,11 +97,12 @@ public class ConstructorResourceTestCase extends AbstractProcessorTest { try { visitConstructor(ctor, type); fail(); - } catch (InvalidConstructorException e) { + } catch (InvalidResourceException e) { // expected } } + @Ignore("TUSCANY-3950") // no names in constructor annotation now @Test public void testNoMatchingNames() throws Exception { JavaImplementation type = javaImplementationFactory.createJavaImplementation(); @@ -121,8 +123,8 @@ public class ConstructorResourceTestCase extends AbstractProcessorTest { } - @org.oasisopen.sca.annotation.Constructor("myResource") - public Foo(@Resource Integer resource) { + @org.oasisopen.sca.annotation.Constructor() + public Foo(@Resource(name = "myResource") Integer resource) { } @@ -149,13 +151,13 @@ public class ConstructorResourceTestCase extends AbstractProcessorTest { } - @org.oasisopen.sca.annotation.Constructor("myProp") - public BadFoo(@Resource Integer res, @Resource Integer res2) { + @org.oasisopen.sca.annotation.Constructor() + public BadFoo(@Resource(name = "myResource") Integer res, @Resource Integer res2) { } - @org.oasisopen.sca.annotation.Constructor({"myRes", "myRes2"}) - public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) { + @org.oasisopen.sca.annotation.Constructor() + public BadFoo(@Resource(name = "myResource") List res, @Resource(name = "myOtherRes") List res2) { } diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/Constants.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/Constants.java index f32289dcb1..294b254229 100644 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/Constants.java +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/Constants.java @@ -11,7 +11,7 @@ package org.oasisopen.sca; *

The serialized QNames are used with the @Requires annotation * to specify a policy intent. The policy intent strings in this * interface do not have a corresponding Java annotation, so these - * policy intents have ot be specified through the use of the + * policy intents have to be specified through the use of the * @Requires annotation. */ public interface Constants { diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/Constructor.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/Constructor.java index c1c99de683..0b068febd3 100644 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/Constructor.java +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/Constructor.java @@ -1,22 +1,23 @@ /* - * Copyright(C) OASIS(R) 2005,2009. All Rights Reserved. + * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved. * OASIS trademark, IPR and other policies apply. */ package org.oasisopen.sca.annotation; import static java.lang.annotation.ElementType.CONSTRUCTOR; import static java.lang.annotation.RetentionPolicy.RUNTIME; - import java.lang.annotation.Retention; import java.lang.annotation.Target; /** - * Used to indicate the constructor the runtime is to use when instantiating a component implementation instance - * - * @version $Rev$ $Date$ + * The @Constructor annotation is used to mark a particular + * constructor to use when instantiating a Java component + * implementation. If this constructor has parameters, each + * of these parameters MUST have either a @Property annotation + * or a @Reference annotation. */ @Target(CONSTRUCTOR) @Retention(RUNTIME) public @interface Constructor { - String[] value() default ""; + } diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/ManagedTransaction.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/ManagedTransaction.java index 6fca1ab5df..db28ea043c 100644 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/ManagedTransaction.java +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/annotation/ManagedTransaction.java @@ -33,12 +33,12 @@ public @interface ManagedTransaction { * The serialized QName of the managedTransaction.local policy intent, * for use with the SCA @Requires annotation. */ - String MANAGEDTRANSACTION_MESSAGE = MANAGEDTRANSACTION + ".local"; + String MANAGEDTRANSACTION_LOCAL = MANAGEDTRANSACTION + ".local"; /** * The serialized QName of the managedTransaction.global policy intent, * for use with the SCA @Requires annotation. */ - String MANAGEDTRANSACTION_TRANSPORT = MANAGEDTRANSACTION + ".global"; + String MANAGEDTRANSACTION_GLOBAL = MANAGEDTRANSACTION + ".global"; /** * List of managedTransaction qualifiers (such as "global" or "local"). diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java index 9e25d407a5..0922bf3e64 100644 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactory.java @@ -145,8 +145,7 @@ public abstract class SCAClientFactory { * @return a proxy to the target service, in the specified SCA Domain * that implements the business interface . * @throws NoSuchServiceException Service requested was not found - * @throws NoSuchDomainException Domain requested was not found */ public abstract T getService(Class interfaze, String serviceURI) - throws NoSuchServiceException, NoSuchDomainException; + throws NoSuchServiceException; } diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java index 54a73fc023..c6bcfd6c28 100644 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/SCAClientFactoryFinder.java @@ -10,7 +10,8 @@ import java.util.Properties; import org.oasisopen.sca.NoSuchDomainException; -/* A Service Provider Interface representing a SCAClientFactory finder. +/** + * A Service Provider Interface representing a SCAClientFactory finder. * SCA provides a default reference implementation of this interface. * SCA runtime vendors can create alternative implementations of this * interface that use different class loading or lookup mechanisms. diff --git a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java index 398360813d..14a02c8b8f 100644 --- a/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java +++ b/sca-java-2.x/trunk/modules/sca-api/src/main/java/org/oasisopen/sca/client/impl/SCAClientFactoryFinderImpl.java @@ -4,6 +4,8 @@ */ package org.oasisopen.sca.client.impl; +import org.oasisopen.sca.client.SCAClientFactoryFinder; + import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; @@ -19,7 +21,6 @@ import java.util.Properties; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.ServiceRuntimeException; import org.oasisopen.sca.client.SCAClientFactory; -import org.oasisopen.sca.client.SCAClientFactoryFinder; /** * This is a default implementation of an SCAClientFactoryFinder which is @@ -61,6 +62,7 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { * instance of the SCAClient * @param classLoader ClassLoader that may be used when creating a new * instance of the SCAClient + * @param domainURI URI for the Domain to which this client instance is connected * @return new instance of the SCAClientFactory * @throws ServiceRuntimeException Failed to create SCAClientFactory * Implementation. @@ -79,7 +81,7 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { classLoader); final SCAClientFactory factory = instantiateSCAClientFactoryClass(factoryImplClass, - domainURI ); + domainURI, properties ); return factory; } @@ -89,11 +91,12 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { * @return The Context ClassLoader for the current Thread. */ private static ClassLoader getThreadContextClassLoader () { - return AccessController.doPrivileged(new PrivilegedAction() { - public ClassLoader run() { - return Thread.currentThread().getContextClassLoader(); - } - }); + return AccessController.doPrivileged( + new PrivilegedAction() { + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); } /** @@ -101,6 +104,10 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { * implementation from the specified Properties, the System Properties * or the specified ClassLoader. * + * @param properties Properties that may be used when creating a new + * instance of the SCAClient + * @param classLoader ClassLoader that may be used when creating a new + * instance of the SCAClient * @return The class name of the SCAClientFactorySPI implementation * @throw ServiceRuntimeException Failed to find implementation for * SCAClientFactorySPI. @@ -134,6 +141,8 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { * Attempts to find the class name for the SCAClientFactorySPI * implementation from the specified Properties. * + * @param properties Properties that may be used when creating a new + * instance of the SCAClient * @return The class name for the SCAClientFactorySPI implementation * or null if not found. */ @@ -156,6 +165,8 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { * Attempts to find the class name for the SCAClientFactorySPI * implementation from the META-INF/services directory * + * @param cl ClassLoader that may be used when creating a new + * instance of the SCAClient * @return The class name for the SCAClientFactorySPI implementation or * null if not found. */ @@ -218,6 +229,8 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { * * @param factoryImplClassName The name of the SCAClientFactory * Implementation class to load + * @param classLoader ClassLoader that may be used when creating a new + * instance of the SCAClient * @return The specified SCAClientFactory Implementation class * @throws ServiceRuntimeException Failed to load the SCAClientFactory * Implementation class @@ -252,20 +265,23 @@ public class SCAClientFactoryFinderImpl implements SCAClientFactoryFinder { * * @param factoryImplClass The SCAClientFactorySPI Implementation * class to instantiate. + * @param domainURI URI for the Domain to which this client instance is connected + * @param properties Properties that may be used when creating a new + * instance of the SCAClient * @return An instance of the SCAClientFactorySPI Implementation class * @throws ServiceRuntimeException Failed to instantiate the specified * specified SCAClientFactorySPI Implementation class */ private static SCAClientFactory instantiateSCAClientFactoryClass( Class factoryImplClass, - URI domainURI) + URI domainURI, Properties properties) throws NoSuchDomainException, ServiceRuntimeException { try { Constructor URIConstructor = - factoryImplClass.getConstructor(URI.class); + factoryImplClass.getConstructor(URI.class, Properties.class); SCAClientFactory provider = - URIConstructor.newInstance( domainURI ); + URIConstructor.newInstance( domainURI, properties ); return provider; } catch (Throwable ex) { throw new ServiceRuntimeException( -- cgit v1.2.3