Package org.apache.tuscany.spi.implementation.java

Examples of org.apache.tuscany.spi.implementation.java.JavaMappedService


            // heuristically determine the service
            // TODO finish algorithm
            Set<Class> interfaces = getAllInterfaces(clazz);
            if (interfaces.size() == 0) {
                // class is the interface
                JavaMappedService service;
                try {
                    service = implService.createService(clazz);
                } catch (InvalidServiceContractException e) {
                    throw new ProcessingException(e);
                }
                type.getServices().put(service.getName(), service);
            } else if (interfaces.size() == 1) {
                JavaMappedService service;
                try {
                    service = implService.createService(interfaces.iterator().next());
                } catch (InvalidServiceContractException e) {
                    throw new ProcessingException(e);
                }
                type.getServices().put(service.getName(), service);
            }
        }
        Set<Method> methods = getAllUniquePublicProtectedMethods(clazz);
        if (!type.getReferences().isEmpty() || !type.getProperties().isEmpty()) {
            // references and properties have been explicitly defined
View Full Code Here


        if (interfaces.length == 0) {
            return;
        }
        for (Class interfaze : interfaces) {
            if (analyzeInterface(interfaze, nonPropRefMethods)) {
                JavaMappedService service;
                try {
                    service = implService.createService(interfaze);
                } catch (InvalidServiceContractException e) {
                    throw new ProcessingException(e);
                }
                type.getServices().put(service.getName(), service);
            }
        }
    }
View Full Code Here

    public void testMethodCallbackInterface() throws Exception {
        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
        processor.visitClass(null, FooImpl.class, type, null);
        JavaMappedService service = type.getServices().get("ServiceCallbackTestCase$Foo");
        assertNotNull(service);
        Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
        processor.visitMethod(null, method, type, null);
        assertEquals(method, service.getCallbackMember());
    }
View Full Code Here

    public void testFieldCallbackInterface() throws Exception {
        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
        processor.visitClass(null, FooImpl.class, type, null);
        JavaMappedService service = type.getServices().get("ServiceCallbackTestCase$Foo");
        assertNotNull(service);
        Field field = FooImpl.class.getDeclaredField("callback");
        processor.visitField(null, field, type, null);
        assertEquals(field, service.getCallbackMember());
    }
View Full Code Here

    private PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;

    public void testMultipleInterfaces() throws Exception {
        processor.visitClass(null, FooMultiple.class, type, null);
        assertEquals(2, type.getServices().size());
        JavaMappedService service = type.getServices().get("ServiceProcessorTestCase$Baz");
        ServiceContract contract = service.getServiceContract();
        assertEquals(Baz.class, contract.getInterfaceClass());
        assertEquals(Bar.class, contract.getCallbackClass());
        assertEquals("ServiceProcessorTestCase$Bar", contract.getCallbackName());
        assertNotNull(type.getServices().get("ServiceProcessorTestCase$Bar"));
    }
View Full Code Here

    }

    public void testRemotableNoService() throws Exception {
        processor.visitClass(null, FooRemotableNoService.class, type, null);
        assertEquals(1, type.getServices().size());
        JavaMappedService service = type.getServices().get("ServiceProcessorTestCase$BazRemotable");
        ServiceContract contract = service.getServiceContract();
        assertEquals(BazRemotable.class, contract.getInterfaceClass());
    }
View Full Code Here

    public ImplementationProcessorServiceImpl(@Autowire JavaInterfaceProcessorRegistry registry) {
        this.registry = registry;
    }

    public JavaMappedService createService(Class<?> interfaze) throws InvalidServiceContractException {
        JavaMappedService service = new JavaMappedService();
        service.setName(getBaseName(interfaze));
        service.setRemotable(interfaze.getAnnotation(Remotable.class) != null);
        ServiceContract<?> contract = registry.introspect(interfaze);
        service.setServiceContract(contract);
        return service;
    }
View Full Code Here

        if (annotation == null) {
            // scan intefaces for remotable
            Set<Class> interfaces = getAllInterfaces(clazz);
            for (Class<?> interfaze : interfaces) {
                if (interfaze.getAnnotation(Remotable.class) != null) {
                    JavaMappedService service;
                    try {
                        service = implService.createService(interfaze);
                    } catch (InvalidServiceContractException e) {
                        throw new ProcessingException(e);
                    }
                    type.getServices().put(service.getName(), service);
                }
            }
            return;
        }
        Class<?>[] interfaces = annotation.interfaces();
        if (interfaces.length == 0) {
            Class<?> interfaze = annotation.value();
            if (Void.class.equals(interfaze)) {
                throw new IllegalServiceDefinitionException("No interfaces specified");
            } else {
                interfaces = new Class<?>[1];
                interfaces[0] = interfaze;
            }
        }
        for (Class<?> interfaze : interfaces) {
            if (!interfaze.isInterface()) {
                InvalidServiceType e = new InvalidServiceType("Service must be an interface");
                e.setIdentifier(interfaze.getName());
                throw e;
            }
            JavaMappedService service;
            try {
                service = implService.createService(interfaze);
            } catch (InvalidServiceContractException e) {
                throw new ProcessingException(e);
            }
            type.getServices().put(service.getName(), service);
        }
    }
View Full Code Here

                new IllegalCallbackReferenceException("Setter must have one parameter");
            e.setIdentifier(method.toString());
            throw e;
        }
        String name = toPropertyName(method.getName());
        JavaMappedService callbackService = null;
        Class<?> callbackClass = method.getParameterTypes()[0];
        for (JavaMappedService service : type.getServices().values()) {
            ServiceContract serviceContract = service.getServiceContract();
            if (serviceContract.getCallbackClass().equals(callbackClass)) {
                callbackService = service;
            }
        }
        if (callbackService == null) {
            throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
        }
        callbackService.setCallbackReferenceName(name);
        callbackService.setCallbackMember(method);
    }
View Full Code Here

        Callback annotation = field.getAnnotation(Callback.class);
        if (annotation == null) {
            return;
        }
        String name = field.getName();
        JavaMappedService callbacksService = null;
        Class<?> callbackClass = field.getType();
        for (JavaMappedService service : type.getServices().values()) {
            ServiceContract serviceContract = service.getServiceContract();
            if (serviceContract.getCallbackClass().equals(callbackClass)) {
                callbacksService = service;
            }
        }
        if (callbacksService == null) {
            throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
        }
        callbacksService.setCallbackReferenceName(name);
        callbacksService.setCallbackMember(field);
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.implementation.java.JavaMappedService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.