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

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


            name = field.getName();
        }
        if (type.getReferences().get(name) != null) {
            throw new DuplicateReferenceException(name);
        }
        JavaMappedReference reference = new JavaMappedReference();
        reference.setMember(field);
        reference.setRequired(required);
        reference.setAutowire(autowire);
        reference.setName(name);
        ServiceContract contract;
        try {
            contract = regsitry.introspect(field.getType());
        } catch (InvalidServiceContractException e) {
            throw new ProcessingException(e);
        }
        reference.setServiceContract(contract);
        type.getReferences().put(name, reference);
    }
View Full Code Here


        PojoComponentType componentType = new PojoComponentType();
        componentType.setImplementationScope(Scope.MODULE);
        componentType
            .setConstructorDefinition(
                new ConstructorDefinition<SourceImpl>(SourceImpl.class.getConstructor((Class[]) null)));
        JavaMappedReference reference;
        try {
            reference = new JavaMappedReference();
            reference.setName("target");
            reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
            JavaServiceContract contract = new JavaServiceContract();
            contract.setInterfaceClass(Target.class);
            reference.setServiceContract(contract);
            componentType.add(reference);
        } catch (NoSuchMethodException e) {
            throw new AssertionError(e);
        }
        impl.setComponentType(componentType);
View Full Code Here

     */
    public static ComponentDefinition<SystemImplementation> createSourceWithTargetAutowire() {
        SystemImplementation impl = new SystemImplementation();
        PojoComponentType componentType = new PojoComponentType();
        componentType.setImplementationScope(Scope.MODULE);
        JavaMappedReference reference;
        try {
            reference = new JavaMappedReference();
            reference.setName("target");
            reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
            reference.setAutowire(true);
            ServiceContract<?> contract = new JavaServiceContract();
            contract.setInterfaceClass(Target.class);
            reference.setServiceContract(contract);
            componentType.add(reference);
        } catch (NoSuchMethodException e) {
            throw new AssertionError(e);
        }
        impl.setComponentType(componentType);
View Full Code Here

    private ComponentDefinition<JavaImplementation> createInnerSourceComponentDef() throws Exception {

        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> sourceType =
            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
        sourceType.setImplementationScope(Scope.MODULE);
        JavaMappedReference reference = new JavaMappedReference();
        reference.setName("targetReference");
        JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
        ServiceContract<?> targetContract = registry.introspect(Target.class);
        targetContract.setCallbackClass(OtherTarget.class);
        targetContract.setCallbackName("OtherTarget");
        reference.setServiceContract(targetContract);
        reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
        sourceType.add(reference);

        ServiceContract<?> sourceContract = registry.introspect(Source.class);

        JavaMappedService sourceServiceDefinition = new JavaMappedService();
View Full Code Here

     * Verifies a single constructor is chosen with a reference as the type
     */
    public void testSingleConstructorWithRef() throws Exception {
        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
        JavaMappedReference ref = new JavaMappedReference();
        ref.setName("foo");
        ServiceContract contract = new JavaServiceContract(String.class);
        ref.setServiceContract(contract);
        type.getReferences().put("foo", ref);
        processor.visitEnd(null, Foo1.class, type, null);
        assertNotNull(type.getConstructorDefinition().getConstructor());
        assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
    }
View Full Code Here

        JavaMappedProperty<String> prop = new JavaMappedProperty<String>();
        prop.setName("foo");
        prop.setJavaType(String.class);
        type.getProperties().put("foo", prop);

        JavaMappedReference ref = new JavaMappedReference();
        ref.setName("ref");
        ServiceContract contract = new JavaServiceContract(Foo1.class);
        ref.setServiceContract(contract);
        type.getReferences().put("ref", ref);
        processor.visitEnd(null, Foo2.class, type, null);
        assertNotNull(type.getConstructorDefinition().getConstructor());
        assertEquals(2, type.getConstructorDefinition().getInjectionNames().size());
    }
View Full Code Here

    }

    public void testSingleConstructorAmbiguousRef() throws Exception {
        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
        JavaMappedReference ref = new JavaMappedReference();
        ref.setName("ref");
        ServiceContract contract = new JavaServiceContract(Foo1.class);
        ref.setServiceContract(contract);
        type.getReferences().put("ref", ref);
        JavaMappedReference ref2 = new JavaMappedReference();
        ref2.setName("ref2");
        ref2.setServiceContract(contract);
        type.getReferences().put("ref2", ref2);
        try {
            processor.visitEnd(null, Foo4.class, type, null);
            fail();
        } catch (AmbiguousConstructorException e) {
View Full Code Here

        Method method = FooClient.class.getMethod("setFoo", Foo.class);
        JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
        ServiceContract<?> contract = registry.introspect(Foo.class);
        contract.setCallbackClass(FooCallback.class);
        contract.setCallbackName("callback");
        JavaMappedReference mappedReference = new JavaMappedReference("foo", contract, method);
        type.getReferences().put("foo", mappedReference);
        ReferenceTarget refTarget = new ReferenceTarget();
        refTarget.setReferenceName("foo");
        refTarget.getTargets().add(new URI("foo"));
        JavaImplementation impl = new JavaImplementation();
View Full Code Here

     * Verifies a service inteface is calculated when only props and refs are given
     */
    public void testExcludedPropertyAndReference() throws Exception {
        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
        JavaMappedReference ref = new JavaMappedReference();
        ref.setName("reference");
        type.add(ref);
        JavaMappedReference ref2 = new JavaMappedReference();
        ref2.setName("reference2");
        type.add(ref2);
        JavaMappedProperty<?> prop1 = new JavaMappedProperty();
        prop1.setName("string1");
        type.add(prop1);
        JavaMappedProperty<?> prop2 = new JavaMappedProperty();
View Full Code Here

    public void testReference() throws Exception {
        PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
            new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
        Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
        processor.visitConstructor(null, ctor, type, null);
        JavaMappedReference reference = type.getReferences().get("myRef");
        assertTrue(reference.isRequired());
        assertEquals("myRef", reference.getName());
    }
View Full Code Here

TOP

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

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.