Search in sources :

Example 1 with ServiceReferenceManager

use of org.apache.felix.ipojo.dependency.impl.ServiceReferenceManager in project felix by apache.

the class DependencyHandlerDescription method getHandlerInfo.

/**
 * Builds the Dependency Handler description.
 * @return the handler description.
 * @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
 */
public Element getHandlerInfo() {
    Element deps = super.getHandlerInfo();
    for (DependencyDescription dependency : m_dependencies) {
        String state = "resolved";
        if (dependency.getState() == DependencyModel.UNRESOLVED) {
            state = "unresolved";
        }
        if (dependency.getState() == DependencyModel.BROKEN) {
            state = "broken";
        }
        Element dep = new Element("Requires", "");
        dep.addAttribute(new Attribute("Specification", dependency.getInterface()));
        dep.addAttribute(new Attribute("Id", dependency.getId()));
        if (dependency.getFilter() != null) {
            dep.addAttribute(new Attribute("Filter", dependency.getFilter()));
        }
        if (dependency.isOptional()) {
            dep.addAttribute(new Attribute("Optional", "true"));
            if (dependency.supportsNullable()) {
                dep.addAttribute(new Attribute("Nullable", "true"));
            }
            if (dependency.getDefaultImplementation() != null) {
                dep.addAttribute(new Attribute("Default-Implementation", dependency.getDefaultImplementation()));
            }
        } else {
            dep.addAttribute(new Attribute("Optional", "false"));
        }
        if (dependency.isMultiple()) {
            dep.addAttribute(new Attribute("Aggregate", "true"));
        } else {
            dep.addAttribute(new Attribute("Aggregate", "false"));
        }
        if (dependency.isProxy()) {
            dep.addAttribute(new Attribute("Proxy", "true"));
        } else {
            dep.addAttribute(new Attribute("Proxy", "false"));
        }
        String policy = "dynamic";
        if (dependency.getPolicy() == DependencyModel.STATIC_BINDING_POLICY) {
            policy = "static";
        } else if (dependency.getPolicy() == DependencyModel.DYNAMIC_PRIORITY_BINDING_POLICY) {
            policy = "dynamic-priority";
        }
        dep.addAttribute(new Attribute("Binding-Policy", policy));
        if (dependency.getComparator() != null) {
            dep.addAttribute(new Attribute("Comparator", dependency.getComparator()));
        }
        dep.addAttribute(new Attribute("State", state));
        List<ServiceReference> set = dependency.getUsedServices();
        if (set != null) {
            for (ServiceReference ref : set) {
                Element use = new Element("Uses", "");
                computeServiceReferenceDescription(ref, use);
                dep.addElement(use);
            }
        }
        set = dependency.getServiceReferences();
        if (set != null) {
            for (ServiceReference ref : set) {
                Element use = new Element("Selected", "");
                computeServiceReferenceDescription(ref, use);
                dep.addElement(use);
            }
        }
        final ServiceReferenceManager serviceReferenceManager = dependency.getDependency().getServiceReferenceManager();
        if (serviceReferenceManager == null) {
            // Exit here, cannot compute anything else.
            deps.addElement(dep);
            continue;
        }
        set = serviceReferenceManager.getMatchingServices();
        if (set != null) {
            for (ServiceReference ref : set) {
                Element use = new Element("Matches", "");
                computeServiceReferenceDescription(ref, use);
                dep.addElement(use);
            }
        }
        // Add interceptors to the description
        List<ServiceReference> interceptors = serviceReferenceManager.getTrackingInterceptorReferences();
        for (ServiceReference ref : interceptors) {
            Element itcp = new Element("ServiceTrackingInterceptor", "");
            computeInterceptorDescription(ref, itcp);
            dep.addElement(itcp);
        }
        ServiceReference ref = serviceReferenceManager.getRankingInterceptorReference();
        if (ref != null) {
            Element itcp = new Element("ServiceRankingInterceptor", "");
            computeInterceptorDescription(ref, itcp);
            dep.addElement(itcp);
        }
        interceptors = serviceReferenceManager.getBindingInterceptorReferences();
        for (ServiceReference rf : interceptors) {
            Element itcp = new Element("ServiceBindingInterceptor", "");
            computeInterceptorDescription(rf, itcp);
            dep.addElement(itcp);
        }
        deps.addElement(dep);
    }
    return deps;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element) ServiceReferenceManager(org.apache.felix.ipojo.dependency.impl.ServiceReferenceManager) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ServiceReferenceManager (org.apache.felix.ipojo.dependency.impl.ServiceReferenceManager)1 Attribute (org.apache.felix.ipojo.metadata.Attribute)1 Element (org.apache.felix.ipojo.metadata.Element)1 ServiceReference (org.osgi.framework.ServiceReference)1