Package org.apache.tuscany.core.implementation

Examples of org.apache.tuscany.core.implementation.PojoConfiguration


    }

    @SuppressWarnings("unchecked")
    public static <T> JavaAtomicComponent createJavaComponent(String name, ScopeContainer scope, Class<T> clazz)
        throws NoSuchMethodException {
        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(scope);
        configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor()));
        configuration.addServiceInterface(clazz);
        configuration.setWireService(WIRE_SERVICE);
        return new JavaAtomicComponent(name, configuration, null);

    }
View Full Code Here


            createJavaComponent(targetName, targetScope, targetClass);
        String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1);
        InboundWire inboundWire = createServiceWire(serviceName, targetService, targetHeadInterceptor);
        targetContext.addInboundWire(inboundWire);

        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(sourceScope);
        configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
        configuration.addServiceInterface(sourceClass);
        configuration.setWireService(WIRE_SERVICE);
        for (Map.Entry<String, Member> entry : members.entrySet()) {
            configuration.addReferenceSite(entry.getKey(), entry.getValue());
        }
        JavaAtomicComponent sourceContext = new JavaAtomicComponent(sourceName, configuration, null);
        OutboundWire outboundWire = createReferenceWire(targetName, sourceReferenceClass, sourceHeadInterceptor);
        sourceContext.addOutboundWire(outboundWire);
        targetScope.register(targetContext);
View Full Code Here

            createJavaComponent(targetName, targetScope, targetClass);
        String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1);
        InboundWire inboundWire = createServiceWire(serviceName, targetService, null);
        targetContext.addInboundWire(inboundWire);

        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(sourceScope);
        configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
        configuration.addServiceInterface(sourceClass);
        configuration.setWireService(WIRE_SERVICE);
        for (Map.Entry<String, Member> entry : members.entrySet()) {
            configuration.addReferenceSite(entry.getKey(), entry.getValue());
        }
        JavaAtomicComponent sourceContext = new JavaAtomicComponent(sourceName, configuration, null);
        OutboundWire outboundWire = createReferenceWire(targetName, sourceReferenceClass, null);
        List<OutboundWire> factories = new ArrayList<OutboundWire>();
        factories.add(outboundWire);
View Full Code Here

                                                                     ScopeContainer targetScopeContainer)
        throws NoSuchMethodException {

        Map<String, AtomicComponent> contexts = new HashMap<String, AtomicComponent>();
        SystemAtomicComponent targetComponent = createAtomicComponent(target, targetScopeContainer, targetClass);
        PojoConfiguration sourceConfig = new PojoConfiguration();
        sourceConfig.getServiceInterfaces().addAll(sourceInterfaces);
        sourceConfig.setScopeContainer(sourceScopeContainer);
        sourceConfig.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));

        //create target wire
        Method[] sourceMethods = sourceClass.getMethods();
        Class[] interfaces = targetClass.getInterfaces();
        Method setter = null;
        for (Class interfaze : interfaces) {
            for (Method method : sourceMethods) {
                if (method.getParameterTypes().length == 1) {
                    if (interfaze.isAssignableFrom(method.getParameterTypes()[0])) {
                        setter = method;
                    }
                }
                Init init;
                if ((init = method.getAnnotation(Init.class)) != null) {
                    sourceConfig.setInitLevel(init.eager() ? 50 : 0);
                    sourceConfig.setInitInvoker(new MethodEventInvoker<Object>(method));

                } else if (method.getAnnotation(Destroy.class) != null) {
                    sourceConfig.setDestroyInvoker(new MethodEventInvoker<Object>(method));
                }
            }

        }
        if (setter == null) {
            throw new IllegalArgumentException("No setter found on source for target");
        }

        sourceConfig.addReferenceSite(setter.getName(), setter);
        SystemAtomicComponent sourceCtx = new SystemAtomicComponentImpl(source, sourceConfig);
        QualifiedName targetName = new QualifiedName(target);
        SystemOutboundWire wire = new SystemOutboundWireImpl(setter.getName(), targetName, targetClass);
        InboundWire inboundWire = new SystemInboundWireImpl(targetName.getPortName(), targetClass, targetComponent);
        wire.setTargetWire(inboundWire);
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public static SystemAtomicComponent createAtomicComponent(String name, ScopeContainer container, Class<?> clazz)
        throws NoSuchMethodException {
        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(container);
        configuration.addServiceInterface(clazz);
        configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor()));
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            Init init;
            if ((init = method.getAnnotation(Init.class)) != null) {
                configuration.setInitLevel(init.eager() ? 50 : 0);
                configuration.setInitInvoker(new MethodEventInvoker<Object>(method));

            } else if (method.getAnnotation(Destroy.class) != null) {
                configuration.setDestroyInvoker(new MethodEventInvoker<Object>(method));
            }
        }
        return new SystemAtomicComponentImpl(name, configuration);
    }
View Full Code Here

                                                              InvalidServiceContractException {
        ConnectorImpl connector = new ConnectorImpl();

        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);

        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(scope);
        configuration.setInstanceFactory(new PojoObjectFactory<TargetImpl>(TargetImpl.class.getConstructor()));
        configuration.addServiceInterface(Target.class);
        configuration.setParent(parent);

        JavaAtomicComponent source = new JavaAtomicComponent("source", configuration, null);
        OutboundWire outboundWire = createOutboundWire(new QualifiedName("target/Target"), Target.class);
        outboundWire.setContainer(source);
        source.addOutboundWire(outboundWire);
View Full Code Here

    public void testServiceLocate() throws Exception {
        ScopeContainer scope = createMock(ScopeContainer.class);
        scope.register(EasyMock.isA(JavaAtomicComponent.class));
        expect(scope.getScope()).andReturn(Scope.MODULE);
        replay(scope);
        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(scope);
        configuration.setInstanceFactory(new PojoObjectFactory<TargetImpl>(TargetImpl.class.getConstructor()));
        configuration.addServiceInterface(Target.class);
        configuration.setWireService(new JDKWireService());
        final JavaAtomicComponent component = new JavaAtomicComponent("target", configuration, null);

        InboundWire wire = createMock(InboundWire.class);

        JavaServiceContract contract = new JavaServiceContract(Target.class);
View Full Code Here

    private EventInvoker<Object> initInvoker;

    public void testDefaultCreationAndInit() throws Exception {
        PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor((Class[]) null));
        PojoConfiguration configuration = new PojoConfiguration();
        configuration.addServiceInterface(Foo.class);
        configuration.setInstanceFactory(factory);
        configuration.setInitInvoker(initInvoker);
        SystemAtomicComponentImpl component = new SystemAtomicComponentImpl("foo", configuration);
        Foo foo = (Foo) component.createInstance();
        component.init(foo);
        assertTrue(foo.initialized);
    }
View Full Code Here

        assertTrue(foo.initialized);
    }

    public void testReferenceAndPropertyConstructor() throws Exception {
        PojoObjectFactory<Bar> factory = new PojoObjectFactory<Bar>(Bar.class.getConstructor(String.class, Foo.class));
        PojoConfiguration configuration = new PojoConfiguration();
        configuration.addServiceInterface(Foo.class);
        configuration.setInstanceFactory(factory);
        configuration.setInitInvoker(initInvoker);
        configuration.addConstructorParamName("foo");
        configuration.addConstructorParamName("ref");
        SystemAtomicComponentImpl component = new SystemAtomicComponentImpl("foo", configuration);
        component.addPropertyFactory("foo", new SingletonObjectFactory<String>("baz"));
        Foo target = new Foo();
        SystemOutboundWire wire = EasyMock.createMock(SystemOutboundWire.class);
        EasyMock.expect(wire.getTargetService()).andReturn(target);
View Full Code Here

    protected void tearDown() throws Exception {
        super.tearDown();
    }

    private SystemAtomicComponent createContext(ScopeContainer scopeContainer) {
        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(scopeContainer);
        configuration.addServiceInterface(RequestScopeInitDestroyComponent.class);
        configuration.setInstanceFactory(factory);
        configuration.setInitInvoker(initInvoker);
        configuration.setDestroyInvoker(destroyInvoker);
        SystemAtomicComponentImpl component = new SystemAtomicComponentImpl("foo", configuration);
        scopeContainer.register(component);
        return component;
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.core.implementation.PojoConfiguration

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.