Search in sources :

Example 1 with ReferenceDTO

use of org.osgi.service.component.runtime.dto.ReferenceDTO in project karaf by apache.

the class DetailsAction method doScrAction.

@SuppressWarnings("rawtypes")
@Override
protected Object doScrAction(ServiceComponentRuntime serviceComponentRuntime) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing the Details Action");
    }
    System.out.println(SimpleAnsi.INTENSITY_BOLD + "Component Details" + SimpleAnsi.INTENSITY_NORMAL);
    for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
        for (ComponentConfigurationDTO config : serviceComponentRuntime.getComponentConfigurationDTOs(component)) {
            if (name.equals(component.name)) {
                printDetail("  Name                : ", component.name);
                printDetail("  State               : ", ScrUtils.getState(config.state));
                Map<String, Object> map = new TreeMap<>(component.properties);
                if (!map.isEmpty()) {
                    System.out.println(SimpleAnsi.INTENSITY_BOLD + "  Properties          : " + SimpleAnsi.INTENSITY_NORMAL);
                    for (Object key : map.keySet()) {
                        Object value = map.get(key);
                        printDetail("    ", key + "=" + value);
                    }
                }
                ReferenceDTO[] references = component.references;
                System.out.println(SimpleAnsi.INTENSITY_BOLD + "References" + SimpleAnsi.INTENSITY_NORMAL);
                for (ReferenceDTO reference : ScrUtils.emptyIfNull(ReferenceDTO.class, references)) {
                    ServiceReferenceDTO[] boundServices = null;
                    boolean satisfied = true;
                    for (SatisfiedReferenceDTO satRef : config.satisfiedReferences) {
                        if (satRef.name.equals(reference.name)) {
                            boundServices = satRef.boundServices;
                            satisfied = true;
                        }
                    }
                    for (UnsatisfiedReferenceDTO satRef : config.unsatisfiedReferences) {
                        if (satRef.name.equals(reference.name)) {
                            boundServices = satRef.targetServices;
                            satisfied = false;
                        }
                    }
                    printDetail("  Reference           : ", reference.name);
                    printDetail("    State             : ", satisfied ? "satisfied" : "unsatisfied");
                    printDetail("    Cardinality       : ", reference.cardinality);
                    printDetail("    Policy            : ", reference.policy);
                    printDetail("    PolicyOption      : ", reference.policyOption);
                    // list bound services
                    for (ServiceReferenceDTO serviceReference : ScrUtils.emptyIfNull(ServiceReferenceDTO.class, boundServices)) {
                        final StringBuffer b = new StringBuffer();
                        b.append("Bound Service ID ");
                        b.append(serviceReference.properties.get(Constants.SERVICE_ID));
                        String componentName = (String) serviceReference.properties.get(ComponentConstants.COMPONENT_NAME);
                        if (componentName == null) {
                            componentName = (String) serviceReference.properties.get(Constants.SERVICE_PID);
                            if (componentName == null) {
                                componentName = (String) serviceReference.properties.get(Constants.SERVICE_DESCRIPTION);
                            }
                        }
                        if (componentName != null) {
                            b.append(" (");
                            b.append(componentName);
                            b.append(")");
                        }
                        printDetail("    Service Reference : ", b.toString());
                    }
                    if (ScrUtils.emptyIfNull(ServiceReferenceDTO.class, boundServices).length == 0) {
                        printDetail("    Service Reference : ", "No Services bound");
                    }
                }
            }
        }
    }
    return null;
}
Also used : ReferenceDTO(org.osgi.service.component.runtime.dto.ReferenceDTO) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) TreeMap(java.util.TreeMap) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)

Aggregations

TreeMap (java.util.TreeMap)1 ServiceReferenceDTO (org.osgi.framework.dto.ServiceReferenceDTO)1 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)1 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)1 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)1 SatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO)1 UnsatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)1