public String listComponents()

in jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java [274:346]


    public String listComponents(boolean excludeSEs, boolean excludeBCs, boolean excludePojos, String requiredState,
                                 String sharedLibraryName, String serviceAssemblyName) throws Exception {
        //validate requiredState
        if (requiredState != null && requiredState.length() > 0
                && !LifeCycleMBean.UNKNOWN.equalsIgnoreCase(requiredState)
                && !LifeCycleMBean.SHUTDOWN.equalsIgnoreCase(requiredState)
                && !LifeCycleMBean.STOPPED.equalsIgnoreCase(requiredState)
                && !LifeCycleMBean.STARTED.equalsIgnoreCase(requiredState)) {
            throw ManagementSupport.failure("listComponents", "Required state '" + requiredState + "' is not a valid state.");
        }
        // Get components
        List<Component> components = new ArrayList<Component>();
        for (Component component : deployer.getComponents().values()) {
            // Check type
            if (excludeSEs && Deployer.TYPE_SERVICE_ENGINE.equals(component.getMainType())) {
                continue;
            }
            // Check type
            if (excludeBCs && Deployer.TYPE_BINDING_COMPONENT.equals(component.getMainType())) {
                continue;
            }
            // Check status
            if (requiredState != null && requiredState.length() > 0 && !requiredState.equalsIgnoreCase(component.getCurrentState())) {
                continue;
            }
            // Check shared library
            if (StringUtils.hasLength(sharedLibraryName)) {
                boolean match = false;
                for (SharedLibrary lib : component.getSharedLibraries()) {
                    if (sharedLibraryName.equals(lib.getName())) {
                        match = true;
                        break;
                    }
                }
                if (!match) {
                    continue;
                }
            }
            // Check deployed service assembly
            if (StringUtils.hasLength(serviceAssemblyName)) {
                boolean match = false;
                for (ServiceUnit su : component.getServiceUnits()) {
                    if (serviceAssemblyName.equals(su.getServiceAssembly().getName())) {
                        match = true;
                        break;
                    }
                }
                if (!match) {
                    continue;
                }
            }
            components.add(component);
        }

        StringBuffer buffer = new StringBuffer();
        buffer.append("<?xml version='1.0'?>\n");
        buffer.append("<component-info-list xmlns='http://java.sun.com/xml/ns/jbi/component-info-list' version='1.0'>\n");
        for (Component component : components) {
            buffer.append("  <component-info");
            buffer.append(" type='").append(component.getMainType()).append("'");
            buffer.append(" name='").append(component.getName()).append("'");
            buffer.append(" state='").append(component.getCurrentState()).append("'>\n");
            buffer.append("    <description>");
            if (component.getDescription() != null) {
                buffer.append(component.getDescription());
            }
            buffer.append("</description>\n");
            buffer.append("  </component-info>\n");
        }
        buffer.append("</component-info-list>");
        return buffer.toString();

    }