You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/04/06 19:30:47 UTC
svn commit: r526232 [3/5] - in /incubator/tuscany/java/sca/modules: ./
idl/src/main/java/org/apache/tuscany/idl/util/
impl-java-xml/src/main/java/org/apache/tuscany/api/
impl-java-xml/src/main/java/org/apache/tuscany/api/annotation/
impl-java-xml/src/m...
Copied: incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ReferenceProcessor.java (from r525324, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ReferenceProcessor.java?view=diff&rev=526232&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessor.java&r1=525324&p2=incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ReferenceProcessor.java&r2=526232
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ReferenceProcessor.java Fri Apr 6 10:30:44 2007
@@ -16,29 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.implementation.processor;
+package org.apache.tuscany.implementation.java.processor;
-import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+import static org.apache.tuscany.implementation.java.processor.JavaIntrospectionHelper.getBaseType;
import java.lang.reflect.Field;
-import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
-import java.net.URI;
import java.util.Collection;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.idl.InvalidServiceContractException;
-import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
-import org.apache.tuscany.spi.implementation.java.JavaElement;
-import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
-import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
-import org.apache.tuscany.spi.implementation.java.JavaMappedService;
-import org.apache.tuscany.spi.implementation.java.Parameter;
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.implementation.java.ProcessingException;
-import org.apache.tuscany.spi.model.Multiplicity;
-import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.assembly.Multiplicity;
+import org.apache.tuscany.assembly.impl.ReferenceImpl;
+import org.apache.tuscany.idl.InvalidInterfaceException;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Parameter;
+import org.apache.tuscany.implementation.java.introspection.ImplementationProcessorExtension;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
import org.osoa.sca.annotations.Reference;
/**
@@ -50,32 +44,29 @@
*/
public class ReferenceProcessor extends ImplementationProcessorExtension {
- public void visitMethod(Method method,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitMethod(Method method, JavaImplementationDefinition type) throws ProcessingException {
Reference annotation = method.getAnnotation(Reference.class);
if (annotation == null) {
return; // Not a reference annotation.
}
if (method.getParameterTypes().length != 1) {
- throw new IllegalReferenceException("Setter must have one parameter", method.toString());
+ throw new IllegalReferenceException("Setter must have one parameter", method);
}
String name = annotation.name();
if ("".equals(name)) {
- name = toPropertyName(method.getName());
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
}
- if (type.getReferences().get(name) != null) {
+ if (type.getReferenceMembers().get(name) != null) {
throw new DuplicateReferenceException(name);
}
JavaElement element = new JavaElement(method, 0);
- JavaMappedReference reference = createReference(element, name);
- type.getReferences().put(name, reference);
+ org.apache.tuscany.assembly.Reference reference = createReference(element, name);
+ type.getReferences().add(reference);
+ type.getReferenceMembers().put(name, element);
}
- public void visitField(Field field,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitField(Field field, JavaImplementationDefinition type) throws ProcessingException {
Reference annotation = field.getAnnotation(Reference.class);
if (annotation == null) {
return;
@@ -84,29 +75,29 @@
if ("".equals(name)) {
name = field.getName();
}
- if (type.getReferences().get(name) != null) {
+ if (type.getReferenceMembers().get(name) != null) {
throw new DuplicateReferenceException(name);
}
JavaElement element = new JavaElement(field);
- JavaMappedReference reference = createReference(element, name);
- type.getReferences().put(name, reference);
+ org.apache.tuscany.assembly.Reference reference = createReference(element, name);
+ type.getReferences().add(reference);
+ type.getReferenceMembers().put(name, element);
}
- public void visitConstructorParameter(Parameter parameter,
- PojoComponentType<JavaMappedService,
- JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitConstructorParameter(Parameter parameter, JavaImplementationDefinition type)
+ throws ProcessingException {
Reference refAnnotation = parameter.getAnnotation(Reference.class);
if (refAnnotation == null) {
return;
}
String paramName = parameter.getName();
String name = getReferenceName(paramName, parameter.getIndex(), refAnnotation.name());
- if (type.getReferences().get(name) != null) {
+ if (type.getReferenceMembers().get(name) != null) {
throw new DuplicateReferenceException(name);
}
- JavaMappedReference reference = createReference(parameter, name);
- type.getReferences().put(name, reference);
+ org.apache.tuscany.assembly.Reference reference = createReference(parameter, name);
+ type.getReferences().add(reference);
+ type.getReferenceMembers().put(name, parameter);
parameter.setClassifer(Reference.class);
parameter.setName(name);
}
@@ -125,39 +116,37 @@
}
}
- private JavaMappedReference createReference(JavaElement element, String name) throws ProcessingException {
- JavaMappedReference reference = new JavaMappedReference();
- reference.setMember((Member)element.getAnchor());
+ private org.apache.tuscany.assembly.Reference createReference(JavaElement element, String name) throws ProcessingException {
+ org.apache.tuscany.assembly.Reference reference = new ReferenceImpl();
+ // reference.setMember((Member)element.getAnchor());
boolean required = false;
Reference ref = element.getAnnotation(Reference.class);
if (ref != null) {
required = ref.required();
}
- reference.setRequired(required);
- reference.setUri(URI.create("#" + name));
- ServiceContract contract;
- try {
- Class<?> rawType = element.getType();
- if (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) {
- if (required) {
- reference.setMultiplicity(Multiplicity.ONE_N);
- } else {
- reference.setMultiplicity(Multiplicity.ZERO_N);
- }
+ // reference.setRequired(required);
+ reference.setName(name);
+ Class<?> rawType = element.getType();
+ if (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_N);
+ } else {
+ reference.setMultiplicity(Multiplicity.ZERO_N);
+ }
+ } else {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_ONE);
} else {
- if (required) {
- reference.setMultiplicity(Multiplicity.ONE_ONE);
- } else {
- reference.setMultiplicity(Multiplicity.ZERO_ONE);
- }
+ reference.setMultiplicity(Multiplicity.ZERO_ONE);
}
- Type genericType = element.getGenericType();
- Class<?> baseType = getBaseType(rawType, genericType);
- contract = interfaceProcessorRegistry.introspect(baseType);
- } catch (InvalidServiceContractException e) {
+ }
+ Type genericType = element.getGenericType();
+ Class<?> baseType = getBaseType(rawType, genericType);
+ try {
+ interfaceProcessorRegistry.introspect(reference, baseType);
+ } catch (InvalidInterfaceException e) {
throw new ProcessingException(e);
}
- reference.setServiceContract(contract);
return reference;
}
}
Copied: incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ResourceProcessor.java (from r525324, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ResourceProcessor.java?view=diff&rev=526232&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java&r1=525324&p2=incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ResourceProcessor.java&r2=526232
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ResourceProcessor.java Fri Apr 6 10:30:44 2007
@@ -16,24 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.implementation.processor;
-
-import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+package org.apache.tuscany.implementation.java.processor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
-import org.apache.tuscany.spi.implementation.java.JavaElement;
-import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
-import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
-import org.apache.tuscany.spi.implementation.java.JavaMappedService;
-import org.apache.tuscany.spi.implementation.java.Parameter;
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.implementation.java.ProcessingException;
-import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Parameter;
+import org.apache.tuscany.implementation.java.impl.Resource;
+import org.apache.tuscany.implementation.java.introspection.ImplementationProcessorExtension;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
/**
* Processes an {@link @Resource} annotation, updating the component type with
@@ -46,20 +40,18 @@
public ResourceProcessor() {
}
- public void visitMethod(Method method,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitMethod(Method method, JavaImplementationDefinition type) throws ProcessingException {
org.apache.tuscany.api.annotation.Resource annotation = method
.getAnnotation(org.apache.tuscany.api.annotation.Resource.class);
if (annotation == null) {
return;
}
if (method.getParameterTypes().length != 1) {
- throw new IllegalResourceException("Resource setter must have one parameter", method.toString());
+ throw new IllegalResourceException("Resource setter must have one parameter", method);
}
String name = annotation.name();
if (name.length() < 1) {
- name = toPropertyName(method.getName());
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
}
if (type.getResources().get(name) != null) {
throw new DuplicateResourceException(name);
@@ -74,9 +66,7 @@
type.add(resource);
}
- public void visitField(Field field,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitField(Field field, JavaImplementationDefinition type) throws ProcessingException {
org.apache.tuscany.api.annotation.Resource annotation = field
.getAnnotation(org.apache.tuscany.api.annotation.Resource.class);
@@ -106,10 +96,8 @@
return new Resource<T>(name, (Class<T>)element.getType(), (Member)element.getAnchor());
}
- public void visitConstructorParameter(Parameter parameter,
- PojoComponentType<JavaMappedService,
- JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitConstructorParameter(Parameter parameter, JavaImplementationDefinition type)
+ throws ProcessingException {
org.apache.tuscany.api.annotation.Resource resourceAnnotation = parameter
.getAnnotation(org.apache.tuscany.api.annotation.Resource.class);
if (resourceAnnotation != null) {
@@ -118,7 +106,7 @@
name = parameter.getName();
}
if ("".equals(name)) {
- throw new InvalidResourceException("Missing resource name", parameter.toString());
+ throw new InvalidResourceException("Missing resource name", (Member)parameter.getAnchor());
}
if (!"".equals(parameter.getName()) && !name.equals(parameter.getName())) {
Copied: incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ScopeProcessor.java (from r525324, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ScopeProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ScopeProcessor.java?view=diff&rev=526232&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ScopeProcessor.java&r1=525324&p2=incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ScopeProcessor.java&r2=526232
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ScopeProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ScopeProcessor.java Fri Apr 6 10:30:44 2007
@@ -16,16 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.implementation.processor;
+package org.apache.tuscany.implementation.java.processor;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
-import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
-import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
-import org.apache.tuscany.spi.implementation.java.JavaMappedService;
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.implementation.java.ProcessingException;
-import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Scope;
+import org.apache.tuscany.implementation.java.introspection.ImplementationProcessorExtension;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
/**
* Processes the {@link Scope} annotation and updates the component type with the corresponding implmentation scope
@@ -35,12 +31,11 @@
public class ScopeProcessor extends ImplementationProcessorExtension {
public <T> void visitClass(Class<T> clazz,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context)
+ JavaImplementationDefinition type)
throws ProcessingException {
org.osoa.sca.annotations.Scope annotation = clazz.getAnnotation(org.osoa.sca.annotations.Scope.class);
if (annotation == null) {
- type.setImplementationScope(Scope.STATELESS);
+ type.setScope(Scope.STATELESS);
return;
}
String name = annotation.value();
@@ -58,6 +53,6 @@
} else {
scope = new Scope(name);
}
- type.setImplementationScope(scope);
+ type.setScope(scope);
}
}
Copied: incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceProcessor.java (from r525324, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceProcessor.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceProcessor.java?view=diff&rev=526232&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceProcessor.java&r1=525324&p2=incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceProcessor.java&r2=526232
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceProcessor.java Fri Apr 6 10:30:44 2007
@@ -16,53 +16,48 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.implementation.processor;
+package org.apache.tuscany.implementation.java.processor;
-import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getAllInterfaces;
-import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+import static org.apache.tuscany.implementation.java.processor.JavaIntrospectionHelper.getAllInterfaces;
+import static org.apache.tuscany.implementation.java.processor.JavaIntrospectionHelper.toPropertyName;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.net.URI;
import java.util.Set;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.idl.InvalidServiceContractException;
-import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
-import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
-import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
-import org.apache.tuscany.spi.implementation.java.JavaMappedService;
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.implementation.java.ProcessingException;
-import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.assembly.Service;
+import org.apache.tuscany.idl.InvalidInterfaceException;
+import org.apache.tuscany.idl.java.JavaInterface;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.ImplementationProcessorExtension;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
import org.osoa.sca.annotations.Callback;
import org.osoa.sca.annotations.Remotable;
/**
* Processes an {@link org.osoa.sca.annotations.Service} annotation and updates
- * the component type with corresponding {@link JavaMappedService}s. Also
- * processes related {@link org.osoa.sca.annotations.Callback} annotations.
+ * the component type with corresponding {@link Service}s. Also processes
+ * related {@link org.osoa.sca.annotations.Callback} annotations.
*
* @version $Rev$ $Date$
*/
public class ServiceProcessor extends ImplementationProcessorExtension {
- public <T> void visitClass(Class<T> clazz,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public <T> void visitClass(Class<T> clazz, JavaImplementationDefinition type) throws ProcessingException {
org.osoa.sca.annotations.Service annotation = clazz.getAnnotation(org.osoa.sca.annotations.Service.class);
if (annotation == null) {
// scan intefaces for remotable
Set<Class> interfaces = getAllInterfaces(clazz);
for (Class<?> interfaze : interfaces) {
if (interfaze.isAnnotationPresent(Remotable.class) || interfaze.isAnnotationPresent(Callback.class)) {
- JavaMappedService service;
+ Service service;
try {
service = createService(interfaze);
- } catch (InvalidServiceContractException e) {
+ } catch (InvalidInterfaceException e) {
throw new ProcessingException(e);
}
- type.getServices().put(service.getUri().getFragment(), service);
+ type.getServices().add(service);
}
}
return;
@@ -79,76 +74,68 @@
}
for (Class<?> interfaze : interfaces) {
if (!interfaze.isInterface()) {
- throw new InvalidServiceType("Service must be an interface", interfaze.getName());
+ throw new InvalidServiceType("Service must be an interface", interfaze);
}
- JavaMappedService service;
+ Service service;
try {
service = createService(interfaze);
- } catch (InvalidServiceContractException e) {
+ } catch (InvalidInterfaceException e) {
throw new ProcessingException(e);
}
- type.getServices().put(service.getUri().getFragment(), service);
+ type.getServices().add(service);
}
}
- public void visitMethod(Method method,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitMethod(Method method, JavaImplementationDefinition type) throws ProcessingException {
Callback annotation = method.getAnnotation(Callback.class);
if (annotation == null) {
return;
}
if (method.getParameterTypes().length != 1) {
- throw new IllegalCallbackReferenceException("Setter must have one parameter", method.toString());
+ throw new IllegalCallbackReferenceException("Setter must have one parameter", method);
}
String name = toPropertyName(method.getName());
- JavaMappedService callbackService = null;
+ Service callbackService = null;
Class<?> callbackClass = method.getParameterTypes()[0];
- for (JavaMappedService service : type.getServices().values()) {
- ServiceContract serviceContract = service.getServiceContract();
- if (serviceContract.getCallbackClass().equals(callbackClass)) {
+ for (Service service : type.getServices()) {
+ JavaInterface javaInterface = (JavaInterface)service.getCallbackInterface();
+ if (callbackClass == javaInterface.getJavaClass()) {
callbackService = service;
}
}
if (callbackService == null) {
throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
}
- callbackService.setCallbackReferenceName(name);
- callbackService.setCallbackMember(method);
+ type.getCallbackMembers().put(name, new JavaElement(method, 0));
}
- public void visitField(Field field,
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
- DeploymentContext context) throws ProcessingException {
+ public void visitField(Field field, JavaImplementationDefinition type) throws ProcessingException {
Callback annotation = field.getAnnotation(Callback.class);
if (annotation == null) {
return;
}
String name = field.getName();
- JavaMappedService callbacksService = null;
+ Service callbackService = null;
Class<?> callbackClass = field.getType();
- for (JavaMappedService service : type.getServices().values()) {
- ServiceContract serviceContract = service.getServiceContract();
- if (serviceContract.getCallbackClass().equals(callbackClass)) {
- callbacksService = service;
+ for (Service service : type.getServices()) {
+ JavaInterface javaInterface = (JavaInterface)service.getCallbackInterface();
+ if (callbackClass == javaInterface.getJavaClass()) {
+ callbackService = service;
}
}
- if (callbacksService == null) {
+ if (callbackService == null) {
throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
}
- callbacksService.setCallbackReferenceName(name);
- callbacksService.setCallbackMember(field);
+ type.getCallbackMembers().put(name, new JavaElement(field));
}
- public JavaMappedService createService(Class<?> interfaze) throws InvalidServiceContractException {
- JavaMappedService service = new JavaMappedService();
+ public Service createService(Class<?> interfaze) throws InvalidInterfaceException {
+ Service service = factory.createService();
// create a relative URI
- service.setUri(URI.create("#" + interfaze.getSimpleName()));
- service.setRemotable(interfaze.getAnnotation(Remotable.class) != null);
- ServiceContract<?> contract = interfaceProcessorRegistry.introspect(interfaze);
- service.setServiceContract(contract);
+ service.setName(interfaze.getSimpleName());
+ interfaceProcessorRegistry.introspect(service, interfaze);
return service;
}
Copied: incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceTypeNotFoundException.java (from r525324, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceTypeNotFoundException.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceTypeNotFoundException.java?view=diff&rev=526232&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceTypeNotFoundException.java&r1=525324&p2=incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceTypeNotFoundException.java&r2=526232
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceTypeNotFoundException.java (original)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/ServiceTypeNotFoundException.java Fri Apr 6 10:30:44 2007
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.implementation.processor;
+package org.apache.tuscany.implementation.java.processor;
-import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
/**
* Thrown when a service interface cannot be determined based on a heuristic evaluation of an implementation
Copied: incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/UnknownContextTypeException.java (from r525324, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/UnknownContextTypeException.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/UnknownContextTypeException.java?view=diff&rev=526232&p1=incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/UnknownContextTypeException.java&r1=525324&p2=incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/UnknownContextTypeException.java&r2=526232
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/UnknownContextTypeException.java (original)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/main/java/org/apache/tuscany/implementation/java/processor/UnknownContextTypeException.java Fri Apr 6 10:30:44 2007
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.core.implementation.processor;
+package org.apache.tuscany.implementation.java.processor;
/**
* Thrown when a method or field marked with {@link org.osoa.sca.annotations.Context} takes an unknown type
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractProcessorTest.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractProcessorTest.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractProcessorTest.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
+import org.apache.tuscany.idl.java.introspection.impl.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Parameter;
+import org.apache.tuscany.implementation.java.introspection.ProcessingException;
+import org.apache.tuscany.implementation.java.processor.ConstructorProcessor;
+import org.apache.tuscany.implementation.java.processor.PropertyProcessor;
+import org.apache.tuscany.implementation.java.processor.ReferenceProcessor;
+import org.apache.tuscany.implementation.java.processor.ResourceProcessor;
+
+
+/**
+ * Base class to simulate the processor sequences
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractProcessorTest extends TestCase {
+ protected AssemblyFactory factory = new DefaultAssemblyFactory();
+ protected ConstructorProcessor constructorProcessor;
+ private ReferenceProcessor referenceProcessor = new ReferenceProcessor();
+ private PropertyProcessor propertyProcessor = new PropertyProcessor();
+ private ResourceProcessor resourceProcessor = new ResourceProcessor();
+ // private MonitorProcessor monitorProcessor = new MonitorProcessor(new NullMonitorFactory());
+
+
+ protected AbstractProcessorTest() {
+ constructorProcessor = new ConstructorProcessor();
+ referenceProcessor = new ReferenceProcessor();
+ referenceProcessor.setInterfaceProcessorRegistry(new JavaInterfaceProcessorRegistryImpl());
+ propertyProcessor = new PropertyProcessor();
+ }
+
+ protected <T> void visitConstructor(Constructor<T> constructor,
+ JavaImplementationDefinition type) throws ProcessingException {
+ constructorProcessor.visitConstructor(constructor, type);
+ ConstructorDefinition<?> definition = type.getConstructorDefinition();
+ if (definition == null) {
+ definition = new ConstructorDefinition<T>(constructor);
+ type.getConstructors().put(constructor, definition);
+ }
+ Parameter[] parameters = definition.getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ resourceProcessor.visitConstructorParameter(parameters[i], type);
+ // monitorProcessor.visitConstructorParameter(parameters[i], type);
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractProcessorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractPropertyProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractPropertyProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractPropertyProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractPropertyProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,164 @@
+/*
+ * 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.core.implementation.processor;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getProperty;
+
+import java.lang.annotation.Retention;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Parameter;
+import org.apache.tuscany.implementation.java.introspection.DuplicatePropertyException;
+import org.apache.tuscany.implementation.java.introspection.IllegalPropertyException;
+import org.apache.tuscany.implementation.java.introspection.ImplementationProcessor;
+import org.apache.tuscany.implementation.java.processor.AbstractPropertyProcessor;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractPropertyProcessorTestCase extends TestCase {
+
+ private ImplementationProcessor processor;
+
+ public void testVisitMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ processor.visitMethod(method, type);
+ Property prop = getProperty(type, "test");
+ assertNotNull(prop);
+ }
+
+ public void testVisitNoParamsMethod() throws Exception {
+ Method method = Foo.class.getMethod("setNoParamsBar");
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testVisitNonVoidMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBadBar", String.class);
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ processor.visitMethod(method, type);
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("d");
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ processor.visitField(field, type);
+ Property prop = getProperty(type, "test");
+ assertNotNull(prop);
+ }
+
+ public void testVisitConstructor() throws Exception {
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ ConstructorDefinition<Foo> def = new ConstructorDefinition<Foo>(ctor);
+ Parameter parameter = def.getParameters()[0];
+ processor.visitConstructorParameter(parameter, type);
+ assertEquals("test", def.getParameters()[0].getName());
+ assertNotNull(getProperty(type, "test"));
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor = new TestProcessor();
+ }
+
+ @Retention(RUNTIME)
+ private @interface Bar {
+
+ }
+
+ private class TestProcessor extends AbstractPropertyProcessor<Bar> {
+
+ public TestProcessor() {
+ super(Bar.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void initProperty(Property property, Bar annotation) {
+ // property.setDefaultValueFactory(EasyMock.createMock(ObjectFactory.class));
+ property.setName("test");
+ }
+
+ protected String getName(Bar annotation) {
+ return "test";
+ }
+ }
+
+ private static class Foo {
+
+ @Bar
+ protected String d;
+
+ public Foo(String a, @Bar
+ String b) {
+ }
+
+ public Foo(@Bar
+ String d) {
+ this.d = d;
+ }
+
+ @Bar
+ public void setBar(String d) {
+ this.d = d;
+ }
+
+ @Bar
+ public void setNoParamsBar() {
+ }
+
+ @Bar
+ public String setBadBar(String d) {
+ return null;
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractPropertyProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AbstractPropertyProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,66 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.AllowsPassByReferenceProcessor;
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AllowsPassByReferenceProcessorTestCase extends TestCase {
+
+ JavaImplementationDefinition type;
+ AllowsPassByReferenceProcessor processor;
+
+ public void testClassAnnotation() throws Exception {
+ processor.visitClass(Foo.class, type);
+ assertEquals(true, type.isAllowsPassByReference());
+
+ processor.visitClass(Bar.class, type);
+ assertEquals(false, type.isAllowsPassByReference());
+
+ Method m1 = Bar.class.getMethod("m1", new Class[] {});
+ processor.visitMethod(m1, type);
+ assertTrue(type.isAllowsPassByReference(m1));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new JavaImplementationDefinition();
+ processor = new AllowsPassByReferenceProcessor();
+ }
+
+ @AllowsPassByReference
+ private class Foo {
+ }
+
+ // no annotation
+ private class Bar {
+ @AllowsPassByReference
+ public void m1() {
+
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,188 @@
+/*
+ * 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.core.implementation.processor;
+
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getProperty;
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.Multiplicity;
+import org.apache.tuscany.idl.java.introspection.impl.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.impl.Parameter;
+import org.apache.tuscany.implementation.java.processor.ConstructorProcessor;
+import org.apache.tuscany.implementation.java.processor.DuplicateConstructorException;
+import org.apache.tuscany.implementation.java.processor.InvalidConstructorException;
+import org.apache.tuscany.implementation.java.processor.PropertyProcessor;
+import org.apache.tuscany.implementation.java.processor.ReferenceProcessor;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorTestCase extends TestCase {
+ private ConstructorProcessor processor = new ConstructorProcessor();
+
+ public void testDuplicateConstructor() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ try {
+ processor.visitClass(BadFoo.class, type);
+ fail();
+ } catch (DuplicateConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorAnnotation() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor1, type);
+ assertEquals("foo", type.getConstructorDefinition().getParameters()[0].getName());
+ }
+
+ public void testNoAnnotation() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<NoAnnotation> ctor1 = NoAnnotation.class.getConstructor();
+ processor.visitConstructor(ctor1, type);
+ assertNull(type.getConstructorDefinition());
+ }
+
+ public void testBadAnnotation() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<BadAnnotation> ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class);
+ try {
+ processor.visitConstructor(ctor1, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testMixedParameters() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<Mixed> ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class);
+ processor.visitConstructor(ctor1, type);
+
+ ReferenceProcessor referenceProcessor = new ReferenceProcessor();
+ referenceProcessor.setInterfaceProcessorRegistry(new JavaInterfaceProcessorRegistryImpl());
+ PropertyProcessor propertyProcessor = new PropertyProcessor();
+ Parameter[] parameters = type.getConstructorDefinition().getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ }
+
+ assertEquals("_ref0", parameters[0].getName());
+ assertEquals("foo", parameters[1].getName());
+ assertEquals("bar", parameters[2].getName());
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadFoo(String foo) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor( {"foo", "bar"})
+ public BadFoo(String foo, String bar) {
+
+ }
+ }
+
+ private static class Foo {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public Foo(String foo) {
+
+ }
+ }
+
+ private static class NoAnnotation {
+ public NoAnnotation() {
+ }
+ }
+
+ private static class BadAnnotation {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadAnnotation(String foo, Foo ref) {
+ }
+ }
+
+ public static final class Mixed {
+ @org.osoa.sca.annotations.Constructor
+ public Mixed(@Reference
+ String param1, @Property(name = "foo")
+ String param2, @Reference(name = "bar")
+ String param3) {
+ }
+ }
+
+ public static final class Multiple {
+ @org.osoa.sca.annotations.Constructor
+ public Multiple(@Reference
+ Collection<String> param1, @Property(name = "foo")
+ String[] param2, @Reference(name = "bar", required = true)
+ List<String> param3, @Property(name = "abc")
+ Set<String> param4, @Reference(name = "xyz")
+ String[] param5) {
+ }
+ }
+
+ public void testMultiplicity() throws Exception {
+ JavaImplementationDefinition type = new JavaImplementationDefinition();
+ Constructor<Multiple> ctor1 = Multiple.class.getConstructor(Collection.class,
+ String[].class,
+ List.class,
+ Set.class,
+ String[].class);
+ processor.visitConstructor(ctor1, type);
+ ReferenceProcessor referenceProcessor = new ReferenceProcessor();
+ referenceProcessor.setInterfaceProcessorRegistry(new JavaInterfaceProcessorRegistryImpl());
+ PropertyProcessor propertyProcessor = new PropertyProcessor();
+ Parameter[] parameters = type.getConstructorDefinition().getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ }
+
+ org.apache.tuscany.assembly.Reference ref0 = getReference(type, "_ref0");
+ assertNotNull(ref0);
+ assertEquals(Multiplicity.ZERO_N, ref0.getMultiplicity());
+ org.apache.tuscany.assembly.Reference ref1 = getReference(type, "bar");
+ assertNotNull(ref1);
+ assertEquals(Multiplicity.ONE_N, ref1.getMultiplicity());
+ org.apache.tuscany.assembly.Reference ref2 = getReference(type, "xyz");
+ assertNotNull(ref2);
+ assertEquals(Multiplicity.ZERO_N, ref2.getMultiplicity());
+ org.apache.tuscany.assembly.Property prop1 = getProperty(type, "foo");
+ assertNotNull(prop1);
+ assertTrue(prop1.isMany());
+ org.apache.tuscany.assembly.Property prop2 = getProperty(type, "abc");
+ assertNotNull(prop2);
+ assertTrue(prop2.isMany());
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,163 @@
+/*
+ * 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.core.implementation.processor;
+
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.DuplicatePropertyException;
+import org.apache.tuscany.implementation.java.processor.InvalidConstructorException;
+import org.apache.tuscany.implementation.java.processor.InvalidPropertyException;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorPropertyTestCase extends AbstractProcessorTest {
+
+ public void testProperty() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.assembly.Property property = getProperty(type, "myProp");
+ assertTrue(property.isMustSupply());
+ assertEquals("myProp", property.getName());
+ }
+
+ public void testTwoPropertiesSameType() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getProperty(type, "myProp1"));
+ assertNotNull(getProperty(type, "myProp2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getProperty(type, "myProp"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public Foo(@Property Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp1")String prop1, @Property(name = "myProp2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property List prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property(name = "myProp")String prop1, @Property(name = "myProp")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Property Integer prop, @Property Integer prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Property List ref, @Property(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,171 @@
+/*
+ * 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.core.implementation.processor;
+
+import static org.apache.tuscany.core.implementation.processor.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.assembly.Multiplicity;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.DuplicateReferenceException;
+import org.apache.tuscany.implementation.java.processor.InvalidConstructorException;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorReferenceTestCase extends AbstractProcessorTest {
+
+ public void testReference() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.assembly.Reference reference = getReference(type, "myRef");
+ assertEquals(Multiplicity.ONE_ONE, reference.getMultiplicity());
+ assertEquals("myRef", reference.getName());
+ }
+
+ public void testTwoReferencesSameType() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "myRef1"));
+ assertNotNull(getReference(type, "myRef2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<NoNameFoo> ctor = NoNameFoo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "_ref0"));
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "myRef"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef1")String prop1, @Reference(name = "myRef2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public Foo(@Reference Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference List prop) {
+
+ }
+ }
+
+ private static class NoNameFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public NoNameFoo(@Reference String prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference(name = "myRef")String prop1, @Reference(name = "myRef")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public BadFoo(@Reference Integer ref, @Reference Integer ref2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Reference List ref, @Reference(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,159 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.api.annotation.Resource;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.DuplicateResourceException;
+import org.apache.tuscany.implementation.java.processor.InvalidConstructorException;
+import org.apache.tuscany.implementation.java.processor.InvalidResourceException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorResourceTestCase extends AbstractProcessorTest {
+
+ public void testResource() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.implementation.java.impl.Resource resource = type.getResources().get("myResource");
+ assertFalse(resource.isOptional());
+ }
+
+ public void testTwoResourcesSameType() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(type.getResources().get("myResource1"));
+ assertNotNull(type.getResources().get("myResource2"));
+ }
+
+ public void testDuplicateResource() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicateResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(type.getResources().get("myResource"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource") String resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myResource")
+ public Foo(@Resource Integer resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource1") String res1, @Resource(name = "myResource2") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource List res) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource(name = "myResource") String res1, @Resource(name = "myResource") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource String res) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Resource Integer res, @Resource Integer res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRes", "myRes2"})
+ public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) {
+
+ }
+
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java?view=auto&rev=526232
==============================================================================
--- incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java Fri Apr 6 10:30:44 2007
@@ -0,0 +1,194 @@
+/*
+ * 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.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.assembly.Component;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.ContextProcessor;
+import org.apache.tuscany.implementation.java.processor.IllegalContextException;
+import org.apache.tuscany.implementation.java.processor.UnknownContextTypeException;
+import org.easymock.EasyMock;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.Context;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextProcessorTestCase extends TestCase {
+ private ContextProcessor processor;
+ private Component composite;
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class);
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitMethod(composite, method, type);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("context");
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitField(composite, field, type);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ public void testRequestContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setRequestContext", RequestContext.class);
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitMethod(method, type);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testRequestContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("requestContext");
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitField(field, type);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testInvalidParamType() throws Exception {
+ Method method = Foo.class.getMethod("setContext", String.class);
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidParamTypeField() throws Exception {
+ Field field = Foo.class.getDeclaredField("badContext");
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ try {
+ processor.visitField(field, type);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+
+ public void testInvalidParamNum() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class);
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidNoParams() throws Exception {
+ Method method = Foo.class.getMethod("setContext");
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testNoContext() throws Exception {
+ Method method = Foo.class.getMethod("noContext", ComponentContext.class);
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitMethod(method, type);
+ assertEquals(0, type.getResources().size());
+ }
+
+ public void testNoContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("noContext");
+ JavaImplementationDefinition type =
+ new JavaImplementationDefinition();
+ processor.visitField(field, type);
+ assertEquals(0, type.getResources().size());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor = new ContextProcessor();
+ // processor.setWorkContext(EasyMock.createNiceMock(WorkContext.class));
+ composite = EasyMock.createNiceMock(Component.class);
+ }
+
+ private class Foo {
+ @Context
+ protected ComponentContext context;
+
+ @Context
+ protected Object badContext;
+
+ protected ComponentContext noContext;
+
+ @Context
+ protected RequestContext requestContext;
+
+ @Context
+ public void setContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setContext(String context) {
+
+ }
+
+ @Context
+ public void setContext(ComponentContext context, String string) {
+
+ }
+
+ @Context
+ public void setContext() {
+
+ }
+
+ public void noContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setRequestContext(RequestContext requestContext) {
+ this.requestContext = requestContext;
+ }
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/impl-java-xml/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org