Package org.jboss.as.cli.util

Examples of org.jboss.as.cli.util.SimpleTable


                    if (Util.isSuccess(resourceOutcome)) {
                        if (resourceOutcome.hasDefined(Util.RESULT)) {
                            final ModelNode resourceResult = resourceOutcome.get(Util.RESULT);
                            final List<Property> props = resourceResult.asPropertyList();
                            if (!props.isEmpty()) {
                                final SimpleTable attrTable;
                                if (attrDescriptions == null) {
                                    attrTable = null;
                                } else {
                                    if (additionalProps != null) {
                                        String[] headers = new String[3 + additionalProps.length];
                                        headers[0] = "ATTRIBUTE";
                                        headers[1] = "VALUE";
                                        headers[2] = "TYPE";
                                        int i = 3;
                                        for (String additional : additionalProps) {
                                            headers[i++] = additional.toUpperCase();
                                        }
                                        attrTable = new SimpleTable(headers);
                                    } else {
                                        attrTable = new SimpleTable(new String[] { "ATTRIBUTE", "VALUE", "TYPE" });
                                    }
                                }
                                SimpleTable childrenTable = childDescriptions == null ? null : new SimpleTable(new String[] { "CHILD", "MIN-OCCURS", "MAX-OCCURS" });
                                if (typeNames == null && attrTable == null && childrenTable == null) {
                                    typeNames = new ArrayList<String>();
                                }

                                for (Property prop : props) {
                                    final StringBuilder buf = new StringBuilder();
                                    if (typeNames == null || !typeNames.contains(prop.getName())) {
                                        if (attrDescriptions == null) {
                                            buf.append(prop.getName());
                                            buf.append('=');
                                            buf.append(prop.getValue().asString());
                                            // TODO the value should be formatted nicer but the current
                                            // formatter uses new lines for complex value which doesn't work here
                                            // final ModelNode value = prop.getValue();
                                            // ModelNodeFormatter.Factory.forType(value.getType()).format(buf, 0, value);
                                            typeNames.add(buf.toString());
                                            buf.setLength(0);
                                        } else {
                                            final String[] line = new String[attrTable.columnsTotal()];
                                            line[0] = prop.getName();
                                            line[1] = prop.getValue().asString();
                                            if (attrDescriptions.hasDefined(prop.getName())) {
                                                final ModelNode attrDescr = attrDescriptions.get(prop.getName());
                                                line[2] = getAsString(attrDescr, Util.TYPE);
                                                if (additionalProps != null) {
                                                    int i = 3;
                                                    for (String additional : additionalProps) {
                                                        line[i++] = getAsString(attrDescr, additional);
                                                    }
                                                }
                                            } else {
                                                for (int i = 2; i < line.length; ++i) {
                                                    line[i] = "n/a";
                                                }
                                            }
                                            attrTable.addLine(line);
                                        }
                                    } else if (childDescriptions != null) {
                                        if (childDescriptions.hasDefined(prop.getName())) {
                                            final ModelNode childDescr = childDescriptions.get(prop.getName());
                                            final Integer maxOccurs = getAsInteger(childDescr, Util.MAX_OCCURS);
                                            childrenTable.addLine(new String[] {prop.getName(), getAsString(childDescr, Util.MIN_OCCURS), maxOccurs == null ? "n/a"
                                                                    : (maxOccurs == Integer.MAX_VALUE ? "unbounded" : maxOccurs.toString()) });
                                        } else {
                                            childrenTable.addLine(new String[] {prop.getName(), "n/a", "n/a" });
                                        }
                                    }
                                }

                                StringBuilder buf = null;
                                if (attrTable != null && !attrTable.isEmpty()) {
                                    buf = new StringBuilder();
                                    attrTable.append(buf, true);
                                }
                                if (childrenTable != null
                                        && !childrenTable.isEmpty()) {
                                    if (buf == null) {
                                        buf = new StringBuilder();
                                    } else {
                                        buf.append("\n\n");
                                    }
                                    childrenTable.append(buf, true);
                                }
                                if (buf != null) {
                                    ctx.printLine(buf.toString());
                                }
                            }
View Full Code Here


        }

        final ModelNode result = response.get(Util.RESULT);

        if(composite) {
            final SimpleTable table = new SimpleTable(2);
            final StringBuilder valueBuf = new StringBuilder();
            if(result.hasDefined(Util.STEP_1)) {
                final ModelNode stepOutcome = result.get(Util.STEP_1);
                if(Util.isSuccess(stepOutcome)) {
                    if(stepOutcome.hasDefined(Util.RESULT)) {
                        final ModelNode valueResult = stepOutcome.get(Util.RESULT);
                        final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(valueResult.getType());
                        formatter.format(valueBuf, 0, valueResult);
                    } else {
                        valueBuf.append("n/a");
                    }
                    table.addLine(new String[]{"value", valueBuf.toString()});
                } else {
                    throw new CommandFormatException("Failed to get resource description: " + response);
                }
            }

            if(result.hasDefined(Util.STEP_2)) {
                final ModelNode stepOutcome = result.get(Util.STEP_2);
                if(Util.isSuccess(stepOutcome)) {
                    if(stepOutcome.hasDefined(Util.RESULT)) {
                        final ModelNode descrResult = stepOutcome.get(Util.RESULT);
                        if(descrResult.hasDefined(Util.ATTRIBUTES)) {
                            ModelNode attributes = descrResult.get(Util.ATTRIBUTES);
                            final String name = this.name.getValue(ctx.getParsedCommandLine());
                            if(name == null) {
                                throw new CommandFormatException("Attribute name is not available in handleResponse.");
                            } else if(attributes.hasDefined(name)) {
                                final ModelNode descr = attributes.get(name);
                                for(String prop : descr.keys()) {
                                    table.addLine(new String[]{prop, descr.get(prop).asString()});
                                }
                            } else {
                                throw new CommandFormatException("Attribute description is not available.");
                            }
                        } else {
                            throw new CommandFormatException("The resource doesn't provide attribute descriptions.");
                        }
                    } else {
                        throw new CommandFormatException("Result is not available for read-resource-description request: " + response);
                    }
                } else {
                    throw new CommandFormatException("Failed to get resource description: " + response);
                }
            }
            ctx.printLine(table.toString(true));
        } else {
            final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(result.getType());
            final StringBuilder buf = new StringBuilder();
            formatter.format(buf, 0, result);
            ctx.printLine(buf.toString());
View Full Code Here

                final StrictSizeTable table = new StrictSizeTable(1);
                table.addCell(Util.NAME, stepResponse.get(Util.NAME).asString());
                table.addCell(Util.RUNTIME_NAME, stepResponse.get(Util.RUNTIME_NAME).asString());
                ctx.printLine(table.toString());

                final SimpleTable groups = new SimpleTable(new String[]{"SERVER GROUP", "STATE"});
                if(addedServerGroups == null) {
                    if(steps.hasNext()) {
                        throw new CommandFormatException("Didn't expect results for server groups but received " + (result.asPropertyList().size() - 1) + " more steps.");
                    }
                } else {
                    for(String sg : addedServerGroups) {
                        final Property prop = steps.next();
                        stepResponse = prop.getValue();
                        if(stepResponse.has(prop.getName())) { // TODO remove when the structure is consistent
                            stepResponse = stepResponse.get(prop.getName());
                        }

                        if(stepResponse.hasDefined(Util.RESULT)) {
                            final ModelNode stepResult = stepResponse.get(Util.RESULT);
                            if(stepResult.hasDefined(Util.ENABLED)) {
                                groups.addLine(new String[]{sg, stepResult.get(Util.ENABLED).asBoolean() ? Util.ENABLED : "added"});
                            } else {
                                groups.addLine(new String[]{sg, "n/a"});
                            }
                        } else {
                            groups.addLine(new String[]{sg, "no response"});
                        }
                    }
                }

                if(otherServerGroups != null) {
                    for(String sg : otherServerGroups) {
                        groups.addLine(new String[]{sg, "not added"});
                    }
                }
                ctx.printLine(groups.toString(true));
        } else {
            final StrictSizeTable table = new StrictSizeTable(1);
            table.addCell(Util.NAME, result.get(Util.NAME).asString());
            table.addCell(Util.RUNTIME_NAME, result.get(Util.RUNTIME_NAME).asString());
            table.addCell(Util.PERSISTENT, result.get(Util.PERSISTENT).asString());
View Full Code Here

                    for(Property prop : props) {
                        buf.append('\n');
                        buf.append(prop.getName()).append("\n\n");

                        final List<Property> propProps = prop.getValue().asPropertyList();
                        final SimpleTable table = new SimpleTable(2);
                        for(Property propProp : propProps) {
                            if(propProp.getName().equals(Util.DESCRIPTION)) {
                                buf.append('\t').append(propProp.getValue().asString()).append("\n\n");
                            } else if(!propProp.getName().equals(Util.VALUE_TYPE)) {
                                // TODO not detailing the value-type here, it's readability/formatting issue
                                table.addLine(new String[]{'\t' + propProp.getName() + ':', propProp.getValue().asString()});
                            }
                        }
                        table.append(buf, false);
                        buf.append('\n');
                    }
                }
            } else {
                buf.append("\n\tn/a\n");
            }
            ctx.printLine(buf.toString());

            buf.setLength(0);
            buf.append("\nRESPONSE\n");

            if(result.has(Util.REPLY_PROPERTIES)) {
                final List<Property> props = result.get(Util.REPLY_PROPERTIES).asPropertyList();
                if(props.isEmpty()) {
                    buf.append("\n\tn/a\n");
                } else {
                    buf.append('\n');

                    final SimpleTable table = new SimpleTable(2);
                    StringBuilder vtBuf = null;
                    for(Property prop : props) {
                        if(prop.getName().equals(Util.DESCRIPTION)) {
                            buf.append('\t').append(prop.getValue().asString()).append("\n\n");
                        } else if(prop.getName().equals(Util.VALUE_TYPE)) {
                            final List<Property> vtProps = prop.getValue().asPropertyList();
                            if(!vtProps.isEmpty()) {
                                vtBuf = new StringBuilder();
                                for(Property vtProp : vtProps) {
                                    vtBuf.append('\n').append(vtProp.getName()).append("\n\n");
                                    final List<Property> vtPropProps = vtProp.getValue().asPropertyList();
                                    final SimpleTable vtTable = new SimpleTable(2);
                                    for(Property vtPropProp : vtPropProps) {
                                        if(vtPropProp.getName().equals(Util.DESCRIPTION)) {
                                            vtBuf.append('\t').append(vtPropProp.getValue().asString()).append("\n\n");
                                        } else if(!vtPropProp.getName().equals(Util.VALUE_TYPE)) {
                                            // TODO not detailing the value-type here, it's readability/formatting issue
                                            vtTable.addLine(new String[]{'\t' + vtPropProp.getName() + ':', vtPropProp.getValue().asString()});
                                        }
                                    }
                                    vtTable.append(vtBuf, false);
                                    vtBuf.append('\n');
                                }
                            }
                        } else {
                            table.addLine(new String[]{'\t' + prop.getName() + ':', prop.getValue().asString()});
View Full Code Here

        }

        final ModelNode result = response.get(Util.RESULT);

        if(composite) {
            final SimpleTable table = new SimpleTable(2);
            final StringBuilder valueBuf = new StringBuilder();
            if(result.hasDefined(Util.STEP_1)) {
                final ModelNode stepOutcome = result.get(Util.STEP_1);
                if(Util.isSuccess(stepOutcome)) {
                    if(stepOutcome.hasDefined(Util.RESULT)) {
                        final ModelNode valueResult = stepOutcome.get(Util.RESULT);
                        final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(valueResult.getType());
                        formatter.format(valueBuf, 0, valueResult);
                    } else {
                        valueBuf.append("n/a");
                    }
                    table.addLine(new String[]{"value", valueBuf.toString()});
                } else {
                    ctx.printLine("Failed to get resource description: " + response);
                }
            }

            if(result.hasDefined(Util.STEP_2)) {
                final ModelNode stepOutcome = result.get(Util.STEP_2);
                if(Util.isSuccess(stepOutcome)) {
                    if(stepOutcome.hasDefined(Util.RESULT)) {
                        final ModelNode descrResult = stepOutcome.get(Util.RESULT);
                        if(descrResult.hasDefined(Util.ATTRIBUTES)) {
                            ModelNode attributes = descrResult.get(Util.ATTRIBUTES);
                            final String name = this.name.getValue(ctx.getParsedCommandLine());
                            if(name == null) {
                                ctx.printLine("Attribute name is not available in handleResponse.");
                            } else if(attributes.hasDefined(name)) {
                                final ModelNode descr = attributes.get(name);
                                for(String prop : descr.keys()) {
                                    table.addLine(new String[]{prop, descr.get(prop).asString()});
                                }
                            } else {
                                ctx.printLine("Attribute description is not available.");
                            }
                        } else {
                            ctx.printLine("The resource doesn't provide attribute descriptions.");
                        }
                    } else {
                        ctx.printLine("Result is not available for read-resource-description request: " + response);
                    }
                } else {
                    ctx.printLine("Failed to get resource description: " + response);
                }
            }
            ctx.printLine(table.toString(true));
        } else {
            final ModelNodeFormatter formatter = ModelNodeFormatter.Factory.forType(result.getType());
            final StringBuilder buf = new StringBuilder();
            formatter.format(buf, 0, result);
            ctx.printLine(buf.toString());
View Full Code Here

                            if(Util.isSuccess(resourceOutcome)) {
                                if(resourceOutcome.hasDefined(Util.RESULT)) {
                                    final ModelNode resourceResult = resourceOutcome.get(Util.RESULT);
                                    final List<Property> props = resourceResult.asPropertyList();
                                    if (!props.isEmpty()) {
                                        final SimpleTable attrTable;
                                        if(attrDescriptions == null) {
                                            attrTable = null;
                                        } else {
                                            if(additionalProps != null) {
                                                String[] headers = new String[3 + additionalProps.length];
                                                headers[0] = "ATTRIBUTE";
                                                headers[1] = "VALUE";
                                                headers[2] = "TYPE";
                                                int i = 3;
                                                for(String additional : additionalProps) {
                                                    headers[i++] = additional.toUpperCase();
                                                }
                                                attrTable = new SimpleTable(headers);
                                            } else {
                                                attrTable = new SimpleTable(new String[]{"ATTRIBUTE", "VALUE", "TYPE"});
                                            }
                                        }
                                        SimpleTable childrenTable = childDescriptions == null ? null :
                                            new SimpleTable(new String[]{"CHILD", "MIN-OCCURS", "MAX-OCCURS"});
                                        if(typeNames == null && attrTable == null && childrenTable == null) {
                                            typeNames = new ArrayList<String>();
                                        }

                                        for (Property prop : props) {
                                            final StringBuilder buf = new StringBuilder();
                                            if(typeNames == null || !typeNames.contains(prop.getName())) {
                                                if(attrDescriptions == null) {
                                                    buf.append(prop.getName());
                                                    buf.append('=');
                                                    buf.append(prop.getValue().asString());
// TODO the value should be formatted nicer but the current fomatter uses new lines for complex value which doesn't work here
//                                                    final ModelNode value = prop.getValue();
//                                                    ModelNodeFormatter.Factory.forType(value.getType()).format(buf, 0, value);
                                                    typeNames.add(buf.toString());
                                                    buf.setLength(0);
                                                } else {
                                                    final String[] line = new String[attrTable.columnsTotal()];
                                                    line[0] = prop.getName();
                                                    line[1] = prop.getValue().asString();
                                                    if(attrDescriptions.hasDefined(prop.getName())) {
                                                        final ModelNode attrDescr = attrDescriptions.get(prop.getName());
                                                        line[2] = getAsString(attrDescr, Util.TYPE);
                                                        if(additionalProps != null) {
                                                            int i = 3;
                                                            for(String additional : additionalProps) {
                                                                line[i++] = getAsString(attrDescr, additional);
                                                            }
                                                        }
                                                    } else {
                                                        for(int i = 2; i < line.length; ++i) {
                                                            line[i] = "n/a";
                                                        }
                                                    }
                                                    attrTable.addLine(line);
                                                }
                                            } else if(childDescriptions != null) {
                                                if(childDescriptions.hasDefined(prop.getName())) {
                                                    final ModelNode childDescr = childDescriptions.get(prop.getName());
                                                    final Integer maxOccurs = getAsInteger(childDescr, Util.MAX_OCCURS);
                                                    childrenTable.addLine(new String[]{prop.getName(),
                                                            getAsString(childDescr, Util.MIN_OCCURS),
                                                            maxOccurs == null ? "n/a" : (maxOccurs == Integer.MAX_VALUE ? "unbounded" : maxOccurs.toString())
                                                            });
                                                } else {
                                                    childrenTable.addLine(new String[]{prop.getName(), "n/a", "n/a"});
                                                }
                                            }
                                        }

                                        StringBuilder buf = null;
                                        if(attrTable != null && !attrTable.isEmpty()) {
                                            buf = new StringBuilder();
                                            attrTable.append(buf, true);
                                        }
                                        if(childrenTable != null && !childrenTable.isEmpty()) {
                                            if(buf == null) {
                                                buf = new StringBuilder();
                                            } else {
                                                buf.append("\n\n");
                                            }
                                            childrenTable.append(buf, true);
                                        }
                                        if(buf != null) {
                                            ctx.printLine(buf.toString());
                                        }
                                    }
View Full Code Here

    }

    public static void main(String[] args) throws Exception {

        //System.out.printf("%-8s %-11s %-8s %-11s", "name", "type", "required", "access-type");
        SimpleTable t = new SimpleTable(new String[]{"NAME", "TYPE", "REQUIRED", "ACCESS-TYPE", "VALUE"});
        t.addLine(new String[]{"name1", "big_integer", "true", "read-write", "12"});
        t.addLine(new String[]{"some name", "int", "false", "read-only", null});
        System.out.println(t.toString());
    }
View Full Code Here

        if(!result.isDefined()) {
            throw new CommandLineException("The operation result is not defined: " + result);
        }
        final List<ModelNode> list = result.asList();
        if (!name.isPresent(ctx.getParsedCommandLine())) {
            final SimpleTable table = new SimpleTable(new String[] { "NAME", "SOURCE" });
            for (ModelNode node : list) {
                final ModelNode driverName = node.get(Util.DRIVER_NAME);
                if (!driverName.isDefined()) {
                    throw new CommandLineException(Util.DRIVER_NAME + " is not available: " + node);
                }
                final String source;
                if (node.hasDefined(Util.DEPLOYMENT_NAME)) {
                    source = node.get(Util.DEPLOYMENT_NAME).asString();
                } else if (node.hasDefined(Util.DRIVER_MODULE_NAME)) {
                    final StringBuilder buf = new StringBuilder();
                    buf.append(node.get(Util.DRIVER_MODULE_NAME).asString());
                    if(node.hasDefined(Util.MODULE_SLOT)) {
                        buf.append('/').append(node.get(Util.MODULE_SLOT).asString());
                    }
                    source = buf.toString();
                } else {
                    source = "n/a";
                }
                table.addLine(new String[] { driverName.asString(), source });
            }
            ctx.printLine(table.toString(true));
        } else {
            final String name = this.name.getValue(ctx.getParsedCommandLine());
            final SimpleTable table = new SimpleTable(2);
            for (ModelNode node : list) {
                final ModelNode driverName = node.get(Util.DRIVER_NAME);
                if (!driverName.isDefined()) {
                    throw new CommandLineException(Util.DRIVER_NAME + " is not available: " + node);
                }
                if(name.equals(driverName.asString())) {
                    for(String propName : node.keys()) {
                        final ModelNode value = node.get(propName);
                        table.addLine(new String[] { propName, value.isDefined() ? value.asString() : "n/a" });
                    }
                }
            }
            ctx.printLine(table.toString(false));
        }
    }
View Full Code Here

                    if (Util.isSuccess(resourceOutcome)) {
                        if (resourceOutcome.hasDefined(Util.RESULT)) {
                            final ModelNode resourceResult = resourceOutcome.get(Util.RESULT);
                            final List<Property> props = resourceResult.asPropertyList();
                            if (!props.isEmpty()) {
                                final SimpleTable attrTable;
                                if (attrDescriptions == null) {
                                    attrTable = null;
                                } else {
                                    if (additionalProps != null) {
                                        String[] headers = new String[3 + additionalProps.length];
                                        headers[0] = "ATTRIBUTE";
                                        headers[1] = "VALUE";
                                        headers[2] = "TYPE";
                                        int i = 3;
                                        for (String additional : additionalProps) {
                                            headers[i++] = additional.toUpperCase(Locale.ENGLISH);
                                        }
                                        attrTable = new SimpleTable(headers);
                                    } else {
                                        attrTable = new SimpleTable(new String[] { "ATTRIBUTE", "VALUE", "TYPE" });
                                    }
                                }
                                SimpleTable childrenTable = childDescriptions == null ? null : new SimpleTable(new String[] { "CHILD", "MIN-OCCURS", "MAX-OCCURS" });
                                if (typeNames == null && attrTable == null && childrenTable == null) {
                                    typeNames = new ArrayList<String>();
                                }

                                for (Property prop : props) {
                                    final StringBuilder buf = new StringBuilder();
                                    if (typeNames == null || !typeNames.contains(prop.getName())) {
                                        if (attrDescriptions == null) {
                                            buf.append(prop.getName());
                                            buf.append('=');
                                            buf.append(prop.getValue().asString());
                                            // TODO the value should be formatted nicer but the current
                                            // formatter uses new lines for complex value which doesn't work here
                                            // final ModelNode value = prop.getValue();
                                            // ModelNodeFormatter.Factory.forType(value.getType()).format(buf, 0, value);
                                            typeNames.add(buf.toString());
                                            buf.setLength(0);
                                        } else {
                                            final String[] line = new String[attrTable.columnsTotal()];
                                            line[0] = prop.getName();
                                            line[1] = prop.getValue().asString();
                                            if (attrDescriptions.hasDefined(prop.getName())) {
                                                final ModelNode attrDescr = attrDescriptions.get(prop.getName());
                                                line[2] = getAsString(attrDescr, Util.TYPE);
                                                if (additionalProps != null) {
                                                    int i = 3;
                                                    for (String additional : additionalProps) {
                                                        line[i++] = getAsString(attrDescr, additional);
                                                    }
                                                }
                                            } else {
                                                for (int i = 2; i < line.length; ++i) {
                                                    line[i] = "n/a";
                                                }
                                            }
                                            attrTable.addLine(line);
                                        }
                                    } else if (childDescriptions != null) {
                                        if (childDescriptions.hasDefined(prop.getName())) {
                                            final ModelNode childDescr = childDescriptions.get(prop.getName());
                                            final Integer maxOccurs = getAsInteger(childDescr, Util.MAX_OCCURS);
                                            childrenTable.addLine(new String[] {prop.getName(), getAsString(childDescr, Util.MIN_OCCURS), maxOccurs == null ? "n/a"
                                                                    : (maxOccurs == Integer.MAX_VALUE ? "unbounded" : maxOccurs.toString()) });
                                        } else {
                                            childrenTable.addLine(new String[] {prop.getName(), "n/a", "n/a" });
                                        }
                                    }
                                }

                                StringBuilder buf = null;
                                if (attrTable != null && !attrTable.isEmpty()) {
                                    buf = new StringBuilder();
                                    attrTable.append(buf, true);
                                }
                                if (childrenTable != null
                                        && !childrenTable.isEmpty()) {
                                    if (buf == null) {
                                        buf = new StringBuilder();
                                    } else {
                                        buf.append("\n\n");
                                    }
                                    childrenTable.append(buf, true);
                                }
                                if (buf != null) {
                                    ctx.printLine(buf.toString());
                                }
                            }
View Full Code Here

            }
        }
        if(opResponse.hasDefined(Util.RESPONSE_HEADERS)) {
            final ModelNode headers = opResponse.get(Util.RESPONSE_HEADERS);
            final Set<String> keys = headers.keys();
            final SimpleTable table = new SimpleTable(2);
            for(String key : keys) {
                table.addLine(new String[]{key, headers.get(key).asString()});
            }
            if(buf == null) {
                buf = new StringBuilder();
            } else {
                buf.append(Util.LINE_SEPARATOR);
            }
            table.append(buf, false);
        }
        return buf;
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.cli.util.SimpleTable

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.