Search in sources :

Example 1 with LeafCNode

use of com.yahoo.config.codegen.LeafCNode in project vespa by vespa-engine.

the class ConfigDefinitionBuilder method addNode.

/**
 * @param def a ConfigDefinition object
 * @param node the node to be added to the config definition
 */
private static void addNode(ConfigDefinition def, CNode node) {
    String name = node.getName();
    if (node instanceof LeafCNode) {
        if (node.isArray) {
            // System.out.println("Adding array node " + name);
            String enumValues = null;
            String type = ((LeafCNode) node).getType();
            if ("enum".equals(type)) {
                enumValues = convertToEnumValueCommaSeparated(((LeafCNode.EnumLeaf) node).getLegalValues());
            }
            def.arrayDef(name).setTypeSpec(new ConfigDefinition.TypeSpec(name, ((LeafCNode) node).getType(), null, enumValues, null, null));
        } else if (node.isMap) {
            // System.out.println("Adding leaf map node " + name);
            def.leafMapDef(name).setTypeSpec(new ConfigDefinition.TypeSpec(name, ((LeafCNode) node).getType(), null, null, null, null));
        } else {
            // System.out.println("Adding basic node " + name);
            if (node instanceof LeafCNode.IntegerLeaf) {
                addNode(def, (LeafCNode.IntegerLeaf) node);
            } else if (node instanceof LeafCNode.LongLeaf) {
                addNode(def, (LeafCNode.LongLeaf) node);
            } else if (node instanceof LeafCNode.BooleanLeaf) {
                addNode(def, (LeafCNode.BooleanLeaf) node);
            } else if (node instanceof LeafCNode.DoubleLeaf) {
                addNode(def, (LeafCNode.DoubleLeaf) node);
            // Need to come before StringLeaf, since it is a subclass of StringLeaf
            } else if (node instanceof LeafCNode.ReferenceLeaf) {
                addNode(def, (LeafCNode.ReferenceLeaf) node);
            } else if (node instanceof LeafCNode.FileLeaf) {
                addNode(def, (LeafCNode.FileLeaf) node);
            } else if (node instanceof LeafCNode.PathLeaf) {
                addNode(def, (LeafCNode.PathLeaf) node);
            } else if (node instanceof LeafCNode.StringLeaf) {
                addNode(def, (LeafCNode.StringLeaf) node);
            } else if (node instanceof LeafCNode.EnumLeaf) {
                addNode(def, (LeafCNode.EnumLeaf) node);
            } else {
                System.err.println("Unknown node type for node with name " + name);
            }
        }
    } else {
        ConfigDefinition newDef;
        if (node.isArray) {
            if (node.getChildren() != null && node.getChildren().length > 0) {
                // System.out.println("\tAdding inner array node " + name);
                newDef = def.innerArrayDef(name);
                for (CNode childNode : node.getChildren()) {
                    // System.out.println("\tChild node " + childNode.getName());
                    addNode(newDef, childNode);
                }
            }
        } else if (node.isMap) {
            // System.out.println("Adding struct map node " + name);
            newDef = def.structMapDef(name);
            if (node.getChildren() != null && node.getChildren().length > 0) {
                for (CNode childNode : node.getChildren()) {
                    // System.out.println("\tChild node " + childNode.getName());
                    addNode(newDef, childNode);
                }
            }
        } else {
            // System.out.println("Adding struct node " + name);
            newDef = def.structDef(name);
            if (node.getChildren() != null && node.getChildren().length > 0) {
                for (CNode childNode : node.getChildren()) {
                    // System.out.println("\tChild node " + childNode.getName());
                    addNode(newDef, childNode);
                }
            }
        }
    }
}
Also used : LeafCNode(com.yahoo.config.codegen.LeafCNode) CNode(com.yahoo.config.codegen.CNode) LeafCNode(com.yahoo.config.codegen.LeafCNode)

Example 2 with LeafCNode

use of com.yahoo.config.codegen.LeafCNode in project vespa by vespa-engine.

the class ConfigFileFormat method field.

@Override
public void field(String fieldName, Inspector inspector) {
    try {
        Node parent = nodeStack.peek();
        CNode child = parent.node.getChild(fieldName);
        if (child == null) {
            // Skip this field to optimistic
            return;
        }
        if (!child.isArray && !child.isMap && child instanceof LeafCNode) {
            nodeStack.push(new Node(child));
            encode(inspector, child);
            nodeStack.pop();
        } else {
            encode(inspector, child);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CNode(com.yahoo.config.codegen.CNode) LeafCNode(com.yahoo.config.codegen.LeafCNode) InnerCNode(com.yahoo.config.codegen.InnerCNode) LeafCNode(com.yahoo.config.codegen.LeafCNode) CNode(com.yahoo.config.codegen.CNode) LeafCNode(com.yahoo.config.codegen.LeafCNode) InnerCNode(com.yahoo.config.codegen.InnerCNode)

Aggregations

CNode (com.yahoo.config.codegen.CNode)2 LeafCNode (com.yahoo.config.codegen.LeafCNode)2 InnerCNode (com.yahoo.config.codegen.InnerCNode)1