Package org.switchyard.config.model.composite

Examples of org.switchyard.config.model.composite.ComponentModel


            }
            if (Modifier.isAbstract(serviceClass.getModifiers())) {
                continue;
            }

            ComponentModel componentModel = new V1ComponentModel();
            ComponentServiceModel serviceModel = new V1ComponentServiceModel(switchyardNamespace.uri());
            String name = serviceClass.getSimpleName();
           
            BeanComponentImplementationModel beanModel = new V1BeanComponentImplementationModel(beanNamespace.uri());
            beanModel.setClazz(serviceClass.getName());
            componentModel.setImplementation(beanModel);

            Service service = serviceClass.getAnnotation(Service.class);
            if (service != null) {
                Class<?> iface = service.value();
                if (iface == Service.class) {
                    Class<?>[] interfaces = serviceClass.getInterfaces();
                    if (interfaces.length == 1) {
                        iface = interfaces[0];
                    } else {
                        throw BeanMessages.MESSAGES.unexpectedExceptionTheServiceAnnotationHasNoValueItCannotBeOmmittedUnlessTheBeanImplementsExactlyOneInterface();
                    }
                }
                InterfaceModel csiModel = new V1InterfaceModel(InterfaceModel.JAVA);

                if (service.name().equals(Service.EMPTY)) {
                    name = iface.getSimpleName();
                } else {
                    name = service.name();
                }
               
                serviceModel.setName(name);
                serviceModel.setInterface(csiModel);
                csiModel.setInterface(iface.getName());
               
                componentModel.addService(serviceModel);
            }
           
            // Check to see if a policy requirements have been defined
            Requires requires = serviceClass.getAnnotation(Requires.class);
            if (requires != null) {
                for (SecurityPolicy secPolicy : requires.security()) {
                    if (secPolicy == SecurityPolicy.AUTHORIZATION) {
                        // authorization supports both interaction and implementation,
                        // and we want to add it as implementation to be more correct.
                        beanModel.addPolicyRequirement(secPolicy.getQName());
                    } else if (secPolicy.supports(PolicyType.INTERACTION)) {
                        serviceModel.addPolicyRequirement(secPolicy.getQName());
                    } else if (secPolicy.supports(PolicyType.IMPLEMENTATION)) {
                        beanModel.addPolicyRequirement(secPolicy.getQName());
                    } else {
                        throw BeanMessages.MESSAGES.unknownPolicy(secPolicy.toString());
                    }
                }
                for (TransactionPolicy txPolicy : requires.transaction()) {
                    if (txPolicy.supports(PolicyType.INTERACTION)) {
                        serviceModel.addPolicyRequirement(txPolicy.getQName());
                    } else if (txPolicy.supports(PolicyType.IMPLEMENTATION)) {
                        beanModel.addPolicyRequirement(txPolicy.getQName());
                    } else {
                        throw BeanMessages.MESSAGES.unknownPolicy(txPolicy.toString());
                    }
                }
                // Make sure we don't have conflicting policies
                QName ptx = TransactionPolicy.PROPAGATES_TRANSACTION.getQName();
                QName stx = TransactionPolicy.SUSPENDS_TRANSACTION.getQName();
                if (serviceModel.hasPolicyRequirement(ptx) && serviceModel.hasPolicyRequirement(stx)) {
                    throw BeanMessages.MESSAGES.transactionPoliciesCannotCoexistService(ptx, stx, name);
                }
                QName gtx = TransactionPolicy.MANAGED_TRANSACTION_GLOBAL.getQName();
                QName ltx = TransactionPolicy.MANAGED_TRANSACTION_LOCAL.getQName();
                QName ntx = TransactionPolicy.NO_MANAGED_TRANSACTION.getQName();
                if (beanModel.hasPolicyRequirement(gtx) && beanModel.hasPolicyRequirement(ltx)
                        || beanModel.hasPolicyRequirement(gtx) && beanModel.hasPolicyRequirement(ntx)
                        || beanModel.hasPolicyRequirement(ltx) && beanModel.hasPolicyRequirement(ntx)) {
                    throw BeanMessages.MESSAGES.transactionPoliciesCannotCoexistImplementation(gtx, ltx, ntx, name);
                }
            }

            // Add any references
            for (ComponentReferenceModel reference : getReferences(switchyardNamespace, serviceClass, name)) {
                componentModel.addReference(reference);
            }
           
            compositeModel.addComponent(componentModel);
            componentModel.setName(getComponentName(name, service));
            compositeModel.addComponent(componentModel);
        }

        if (!compositeModel.getModelChildren().isEmpty()) {
            switchyardModel.setComposite(compositeModel);
View Full Code Here


        Assert.assertEquals("m1app", composite.getName());
        Assert.assertEquals(new QName(tns, "m1app"), composite.getQName());
        CompositeServiceModel compositeService = composite.getServices().iterator().next();
        Assert.assertEquals("M1AppService", compositeService.getName());
        Assert.assertEquals(new QName(tns, "M1AppService"), compositeService.getQName());
        ComponentModel component = composite.getComponents().iterator().next();
        Assert.assertEquals("SimpleService", component.getName());
        Assert.assertEquals(new QName(tns, "SimpleService"), component.getQName());
        ComponentServiceModel componentService = component.getServices().iterator().next();
        Assert.assertEquals("SimpleService", componentService.getName());
        Assert.assertEquals(new QName(tns, "SimpleService"), componentService.getQName());
        ComponentReferenceModel componentReference = component.getReferences().iterator().next();
        Assert.assertEquals("anotherService", componentReference.getName());
        Assert.assertEquals(new QName(tns, "anotherService"), componentReference.getQName());
    }
View Full Code Here

            if (reference != null) {
                _references.add(reference);
            }
        }
        for (Configuration component_config : config.getChildren(ComponentModel.COMPONENT)) {
            ComponentModel component = (ComponentModel)readModel(component_config);
            if (component != null) {
                _components.add(component);
            }
        }
        for (Configuration property_config : config.getChildren(PropertyModel.PROPERTY)) {
View Full Code Here

        _model = puller.pull(POLICY_XML, getClass());
    }

    @Test
    public void requiresOnService() throws Exception {
        ComponentModel comp = _model.getComponents().get(0);
        ComponentServiceModel svc = comp.getServices().get(0);
        Assert.assertTrue(svc.hasPolicyRequirement(POLICY_FOO));
        Assert.assertTrue(svc.hasPolicyRequirement(POLICY_BAR));
    }
View Full Code Here

        Assert.assertTrue(svc.hasPolicyRequirement(POLICY_BAR));
    }

    @Test
    public void requiresOnReference() throws Exception {
        ComponentModel comp = _model.getComponents().get(0);
        ComponentReferenceModel ref = comp.getReferences().get(0);
        Assert.assertTrue(ref.hasPolicyRequirement(POLICY_BAR));
    }
View Full Code Here

    @Test
    public void testAddedRequirements() throws Exception {
        _model.getModelConfiguration().setAttribute("xmlns:cstm", CUSTOM_NS);
        // a re-pull is necessary because of how we're setting the attribute above
        _model =  new ModelPuller<CompositeModel>().pull(new StringReader(_model.toString()));
        ComponentModel comp = _model.getComponents().get(0);
        ComponentServiceModel svc = comp.getServices().get(0);
        svc.addPolicyRequirement(POLICY_THINGAMAGIG);
        svc.addPolicyRequirement(POLICY_NONAMESPACE_CLIENT_AUTHENTICATION);
        svc.addPolicyRequirement(POLICY_QUALIFIED_AUTHORIZATION);
        Assert.assertTrue(svc.hasPolicyRequirement(POLICY_FOO));
        Assert.assertTrue(svc.hasPolicyRequirement(POLICY_BAR));
View Full Code Here

        // Verify composite service binding
        SOAPBindingModel binding = (SOAPBindingModel)service.getBindings().get(0);
        PortModel port = binding.getPort();
        Assert.assertEquals("MyWebService/SOAPPort", port.getPort());
        Assert.assertEquals("service.wsdl", binding.getWSDL().getLocation());
        ComponentModel component = port.getBinding().getService().getComposite().getComponents().get(0);
        ComponentServiceModel componentService = component.getServices().get(0);
        Assert.assertEquals("SimpleService", componentService.getName());
        Assert.assertTrue(componentService.hasPolicyRequirement(new QName("clientAuthentication")));
        Assert.assertEquals("theSecurityName", componentService.getSecurity());
        ComponentReferenceModel componentReference = component.getReferences().get(0);
        Assert.assertEquals("anotherService", componentReference.getName());
        Assert.assertTrue(componentReference.hasPolicyRequirement(new QName("clientAuthentication")));
        Assert.assertEquals("theSecurityName", componentReference.getSecurity());
        String name = component.getName();
        Assert.assertEquals("SimpleService", name);
        // Verify transform configuration
        TransformsModel transforms = switchyard.getTransforms();
        JavaTransformModel java_transform = (JavaTransformModel)transforms.getTransforms().get(0);
        Assert.assertEquals("msgA", java_transform.getFrom().getLocalPart());
View Full Code Here

      Assert.assertTrue(_model.isModelValid());
    }

    @Test
    public void testServiceInterface() {
        ComponentModel comp = _model.getComposite().getComponents().get(0);
        EsbInterfaceModel serviceInterface = (EsbInterfaceModel)comp.getServices().get(0).getInterface();
        Assert.assertNotNull(serviceInterface);
        Assert.assertEquals(EsbInterfaceModel.ESB, serviceInterface.getType());
    }
View Full Code Here

        Assert.assertEquals(EsbInterfaceModel.ESB, serviceInterface.getType());
    }

    @Test
    public void testReferenceInterface() {
        ComponentModel comp = _model.getComposite().getComponents().get(0);
        EsbInterfaceModel referenceInterface = (EsbInterfaceModel)comp.getReferences().get(0).getInterface();
        Assert.assertNotNull(referenceInterface);
        Assert.assertEquals(EsbInterfaceModel.ESB, referenceInterface.getType());
        Assert.assertEquals(new QName("urn:123", "abc"), referenceInterface.getInputType());
        Assert.assertEquals("xyz", referenceInterface.getOutputType().toString());
        Assert.assertEquals("omg", referenceInterface.getFaultType().toString());
View Full Code Here

TOP

Related Classes of org.switchyard.config.model.composite.ComponentModel

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.