private static void parseClause()

in repository/service/src/main/java/org/apache/karaf/cave/repository/service/bundlerepository/StaxParser.java [335:408]


    private static void parseClause(XMLStreamReader reader, String[] namespace, Map<String, String> directives, Map<String, Object> attributes) throws XMLStreamException {
        namespace[0] = null;
        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
            String name = reader.getAttributeLocalName(i);
            String value = reader.getAttributeValue(i);
            if (NAMESPACE.equals(name)) {
                namespace[0] = value;
            } else {
                throw new IllegalStateException("Unexpected attribute: '" + name + "'. Expected 'namespace'");
            }
        }
        if (namespace[0] == null) {
            throw new IllegalStateException("Expected attribute 'namespace'");
        }
        while (reader.nextTag() == START_ELEMENT) {
            String element = reader.getLocalName();
            switch (element) {
                case DIRECTIVE: {
                    String name = null;
                    String value = null;
                    for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
                        String attName = reader.getAttributeLocalName(i);
                        String attValue = reader.getAttributeValue(i);
                        switch (attName) {
                            case NAME:
                                name = attValue;
                                break;
                            case VALUE:
                                value = attValue;
                                break;
                            default:
                                throw new IllegalStateException("Unexpected attribute: '" + attName + "'. Expected 'name', or 'value'.");
                        }
                    }
                    if (name == null || value == null) {
                        throw new IllegalStateException("Expected attribute 'name' and 'value'");
                    }
                    directives.put(name, value);
                    sanityCheckEndElement(reader, reader.nextTag(), DIRECTIVE);
                    break;
                }
                case ATTRIBUTE: {
                    String name = null;
                    String value = null;
                    String type = "String";
                    for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) {
                        String attName = reader.getAttributeLocalName(i);
                        String attValue = reader.getAttributeValue(i);
                        switch (attName) {
                            case NAME:
                                name = attValue;
                                break;
                            case VALUE:
                                value = attValue;
                                break;
                            case TYPE:
                                type = attValue;
                                break;
                            default:
                                throw new IllegalStateException("Unexpected attribute: '" + attName + "'. Expected 'name', 'value' or 'type'.");
                        }
                    }
                    if (name == null || value == null) {
                        throw new IllegalStateException("Expected attribute 'name' and 'value'");
                    }
                    attributes.put(name, parseAttribute(value, type));
                    sanityCheckEndElement(reader, reader.nextTag(), ATTRIBUTE);
                    break;
                }
                default:
                    throw new IllegalStateException("Unexpected element: '" + element + ". Expected 'directive' or 'attribute'");
            }
        }
    }