Package org.apache.tuscany.sca.assembly

Examples of org.apache.tuscany.sca.assembly.Service


            if (component.getImplementation() == null) {
                // is null in some of our basic unit tests
                continue;
            }

            Service service = component.getImplementation().getService(componentService.getName());

            if (service != null) {
                componentService.setService(service);
            } else {
                Monitor.error(monitor,
View Full Code Here


                contract.setCallbackInterface(null);
                callbackReference.setInterfaceContract(contract);
            } catch (CloneNotSupportedException e) {
                // will not happen
            }
            Service implService = service.getService();
            if (implService != null) {

                // If the implementation service is a CompositeService, ensure that the Reference that is
                // created is a CompositeReference, otherwise create a Reference
                Reference implReference;
                if (implService instanceof CompositeService) {
                    CompositeReference implCompReference = assemblyFactory.createCompositeReference();
                    // Set the promoted component from the promoted component of the composite service
                    implCompReference.getPromotedComponents().add(((CompositeService)implService)
                        .getPromotedComponent());
                   
                    // Get the promoted component reference corresponding to the service with the callback
                    // fist checking that the promoted service is resolved lest we get a NPE trying to
                    // retrieve the promoted component. It could be unresolved if the user gets the
                    // promotes string wrong
                    // TODO - is there any danger that the callback reference name will clash with other
                    //        reference names. Old code used to qualify it with promoted component name
                    if (((CompositeService)implService).getPromotedService().isUnresolved() == false){
                        String referenceName = ((CompositeService)implService).getPromotedService().getName();
                        ComponentReference promotedReference = ((CompositeService)implService).getPromotedComponent().getReference(referenceName);
                       
                        if (promotedReference != null){
                            implCompReference.getPromotedReferences().add(promotedReference);
                        } else {
                            Monitor.error(monitor,
                                          this,
                                          Messages.ASSEMBLY_VALIDATION,
                                          "PromotedCallbackReferenceNotFound",
                                          component.getName(),
                                          service.getName(),
                                          ((CompositeService)implService).getPromotedComponent().getName(),
                                          referenceName);
                        }
                    }                
                    implReference = implCompReference;
                   
                    // Add the composite reference to the composite implementation artifact
                    Implementation implementation = component.getImplementation();
                    if (implementation != null && implementation instanceof Composite) {
                        ((Composite)implementation).getReferences().add(implCompReference);
                    }
                } else {
                    implReference = assemblyFactory.createReference();
                }

                implReference.setName(implService.getName());
                // MJE: Fixup multiplicity as 0..n for callback references in the component type
                implReference.setMultiplicity(Multiplicity.ZERO_N);
                try {
                    InterfaceContract implContract = (InterfaceContract)implService.getInterfaceContract().clone();
                    implContract.setInterface(implContract.getCallbackInterface());
                    implContract.setCallbackInterface(null);
                    implReference.setInterfaceContract(implContract);
                } catch (CloneNotSupportedException e) {
                    // will not happen
View Full Code Here

            }
            Reference implReference = reference.getReference();
            if (implReference != null) {
                // If the implementation reference is a CompositeReference, ensure that the Service that is
                // created is a CompositeService, otherwise create a Service
                Service implService;
                if (implReference instanceof CompositeReference) {
                    CompositeService implCompService = assemblyFactory.createCompositeService();
                    // TODO The reality here is that the composite reference which has the callback COULD promote more than
                    // one component reference - and there must be a separate composite callback service for each of these component
                    // references
                   
                    // Set the promoted component from the promoted component of the composite reference
                    implCompService.setPromotedComponent(((CompositeReference)implReference).getPromotedComponents().get(0));
                    implCompService.setForCallback(true);
                   
                    // Get the promoted component service corresponding to the reference with the callback
                    // fist checking that the promoted reference is resolved lest we get a NPE trying to
                    // retrieve the promoted component. It could be unresolved if the user gets the
                    // promotes string wrong
                    if (((CompositeReference)implReference).getPromotedReferences().get(0).isUnresolved() == false){
                        String serviceName = ((CompositeReference)implReference).getPromotedReferences().get(0).getName();
                        ComponentService promotedService = ((CompositeReference)implReference).getPromotedComponents().get(0).getService(serviceName);
                       
                        if (promotedService != null){
                            implCompService.setPromotedService(promotedService);
                        } else {
                            Monitor.error(monitor,
                                          this,
                                          Messages.ASSEMBLY_VALIDATION,
                                          "PromotedCallbackServiceNotFound",
                                          component.getName(),
                                          reference.getName(),
                                          ((CompositeReference)implReference).getPromotedComponents().get(0).getName(),
                                          serviceName);
                        }
                    }
                   
                    implService = implCompService;
                    // Add the composite service to the composite implementation artifact
                    Implementation implementation = component.getImplementation();
                    if (implementation != null && implementation instanceof Composite) {
                        ((Composite)implementation).getServices().add(implCompService);
                    } // end if
                    //
                } else {
                    implService = assemblyFactory.createService();
                } // end if
                //
                implService.setName(implReference.getName());
                try {
                    InterfaceContract implContract = (InterfaceContract)implReference.getInterfaceContract().clone();
                    implContract.setInterface(implContract.getCallbackInterface());
                    implContract.setCallbackInterface(null);
                    implService.setInterfaceContract(implContract);
                } catch (CloneNotSupportedException e) {
                    // will not happen
                }
                callbackService.setService(implService);
            }
View Full Code Here

            for (Class<?> interfaze : interfaces) {
                if (interfaze.isAnnotationPresent(Remotable.class)
                    || interfaze.isAnnotationPresent(WebService.class)
                    || interfaze.isAnnotationPresent(Callback.class)
                    ) {
                    Service service;
                    try {
                        service = createService(clazz, interfaze, null);
                    } catch (InvalidInterfaceException e) {
                        throw new IntrospectionException(e);
                    }
                    type.getServices().add(service);
                }
            }
            return;
        }
       
        if (annotation.value().length == 0) {
            throw new IntrospectionException("[JCA90059] The array of interfaces or classes specified by the value attribute of the @Service annotation MUST contain at least one element");
        }
        Class<?>[] interfaces = annotation.value();
        if (annotation.names().length > 0) {
            if (annotation.names().length != interfaces.length) {
                throw new IntrospectionException("[JCA90050] The number of Strings in the names attribute array of the @Service annotation MUST match the number of elements in the value attribute array");
            }
            Set<String> names = new HashSet<String>();
            names.addAll(Arrays.asList(annotation.names()));
            if (names.size() != annotation.names().length) {
                throw new IntrospectionException("[JCA90060] The value of each element in the @Service names array MUST be unique amongst all the other element values in the array");
            }
        }

        //validate no scope on servce interface
        for (Class<?> iface : interfaces) {
            if (iface.getAnnotation(org.oasisopen.sca.annotation.Scope.class) != null) {
                throw new IntrospectionException("[JCA90041] @Scope annotation not allowed on service interface " + iface
                    .getName());
            }
        }
       
        //validate service methods implemented
        Method[] ms = clazz.getMethods();
        for (Class<?> iface : interfaces) {
            for (Method m : iface.getMethods()) {
                if (!hasMethod(m, ms)) {
                    throw new IntrospectionException("[JCA90042,JCI20002] Implementation missing service method " + m.getName() + " service interface " + iface.getName());
                }
            }
        }
       
        for (int i=0; i < interfaces.length; i++) {
            try {
                String name = (annotation.names().length > 0) ? annotation.names()[i] : null;
                Service service = createService(clazz, interfaces[i], name);
                type.getServices().add(service);
            } catch (InvalidInterfaceException e) {
                throw new IntrospectionException(e);
            }
        }
View Full Code Here

        JavaElementImpl element = new JavaElementImpl(field);
        createCallback(type, element);
    }

    public Service createService(Class<?> clazz, Class<?> interfaze, String name) throws InvalidInterfaceException {
        Service service = assemblyFactory.createService();
        JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
        service.setInterfaceContract(interfaceContract);
       
        JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze);

        if (name == null) {
            String serviceName = interfaze.getSimpleName();
            // If the interface has @WebService annotation then take the
            // service name from the @name attribute if present        
            if (interfaze.isAnnotationPresent(WebService.class)){
                if (callInterface.getQName() != null){
                    serviceName = callInterface.getQName().getLocalPart();
                }
            }
           
            service.setName(serviceName);
        } else {
            service.setName(name);
        }

       
        boolean remotable = clazz.getAnnotation(Remotable.class) != null;
        if (remotable){
            callInterface.setRemotable(true);
        }
        service.getInterfaceContract().setInterface(callInterface);
       
        if (callInterface.getCallbackClass() != null) {
            JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass());
            if (remotable){
                callbackInterface.setRemotable(true);
            }
            service.getInterfaceContract().setCallbackInterface(callbackInterface);
        }
        return service;
    }
View Full Code Here

     * @param element
     * @throws IllegalCallbackReferenceException
     */
    private static void createCallback(JavaImplementation type, JavaElementImpl element)
        throws IllegalCallbackReferenceException {
        Service callbackService = null;
        Class<?> callbackClass = element.getType();
        Type genericType = element.getGenericType();
        Class<?> baseType = callbackClass;
        if(ServiceReference.class.isAssignableFrom(baseType)) {
            // @Callback protected CallableReference<MyCallback> callback;
View Full Code Here

        inherit(subject1, intentType, false, subject2);
        checkMutualExclusion(subject1, context);
    }

    protected void configure(ComponentService componentService, BuilderContext context) {
        Service service = componentService.getService();
        if (service != null) {
            configure(componentService, service, null, context);
            configureBindings(componentService, service, context);
        }
    }
View Full Code Here

            activate(compositeContext, ep);

            // create the interface contract for the binding and service ends of the wire
            // that are created as forward only contracts
            // FIXME: [rfeng] We might need a better way to get the impl interface contract
            Service targetService = service.getService();
            if (targetService == null) {
                targetService = service;
            }
            // endpoint.setInterfaceContract(targetService.getInterfaceContract().makeUnidirectional(false));
        }
View Full Code Here

     * @return
     */
    private ComponentService getPromotedComponentService(CompositeService compositeService) {
        ComponentService componentService = compositeService.getPromotedService();
        if (componentService != null) {
            Service service = componentService.getService();
            if (componentService.getName() != null && service instanceof CompositeService) {

                // Continue to follow the service promotion chain
                return getPromotedComponentService((CompositeService)service);

View Full Code Here

        return returnEp;
    }

    private ComponentService getPromotedService(ComponentService componentService) {
        Service service = componentService.getService();
        if (service instanceof CompositeService) {
            return getPromotedService(((CompositeService)service).getPromotedService());
        } else {
            return componentService;
        }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.assembly.Service

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.