use of org.opendaylight.yangtools.yang.model.api.meta.ArgumentDefinition in project yangtools by opendaylight.
the class UnrecognizedStatementSupport method statementDefinitionOverrideOf.
@Override
public UnrecognizedStatementSupport statementDefinitionOverrideOf(final StatementDefinition childDef) {
/*
* This code wraps statements encountered inside an extension so they do not get confused with regular
* statements.
*/
final QName baseQName = getStatementName();
final QName statementName = QName.create(baseQName, childDef.getStatementName().getLocalName());
final ModelDefinedStatementDefinition def;
final Optional<ArgumentDefinition> optArgDef = childDef.getArgumentDefinition();
if (optArgDef.isPresent()) {
final ArgumentDefinition argDef = optArgDef.get();
def = new ModelDefinedStatementDefinition(statementName, argDef.getArgumentName(), argDef.isYinElement());
} else {
def = new ModelDefinedStatementDefinition(statementName);
}
return new UnrecognizedStatementSupport(def, config);
}
use of org.opendaylight.yangtools.yang.model.api.meta.ArgumentDefinition in project yangtools by opendaylight.
the class YinStatementStreamSource method processElement.
private static boolean processElement(final int childId, final Element element, final StatementWriter writer, final QNameToStatementDefinition stmtDef) {
final Optional<? extends ResumedStatement> optResumed = writer.resumeStatement(childId);
final StatementSourceReference ref;
final QName argName;
final boolean allAttrs;
final boolean allElements;
if (optResumed.isPresent()) {
final ResumedStatement resumed = optResumed.get();
if (resumed.isFullyDefined()) {
return true;
}
final StatementDefinition def = resumed.getDefinition();
ref = resumed.getSourceReference();
final Optional<ArgumentDefinition> optArgDef = def.getArgumentDefinition();
if (optArgDef.isPresent()) {
final ArgumentDefinition argDef = optArgDef.get();
argName = argDef.getArgumentName();
allAttrs = argDef.isYinElement();
allElements = !allAttrs;
} else {
argName = null;
allAttrs = false;
allElements = false;
}
} else {
ref = extractRef(element);
final StatementDefinition def = getValidDefinition(element, writer, stmtDef, ref);
if (def == null) {
LOG.debug("Skipping element {}", element);
return false;
}
final String argValue;
final Optional<ArgumentDefinition> optArgDef = def.getArgumentDefinition();
if (optArgDef.isPresent()) {
final ArgumentDefinition argDef = optArgDef.get();
argName = argDef.getArgumentName();
allAttrs = argDef.isYinElement();
allElements = !allAttrs;
argValue = getArgValue(element, argName, allAttrs);
SourceException.throwIfNull(argValue, ref, "Statement {} is missing mandatory argument %s", def.getStatementName(), argName);
} else {
argName = null;
argValue = null;
allAttrs = false;
allElements = false;
}
writer.startStatement(childId, def.getStatementName(), argValue, ref);
}
// Child counter
int childCounter = 0;
boolean fullyDefined = true;
// First process any statements defined as attributes. We need to skip argument, if present
final NamedNodeMap attributes = element.getAttributes();
if (attributes != null) {
for (int i = 0, len = attributes.getLength(); i < len; ++i) {
final Attr attr = (Attr) attributes.item(i);
if ((allAttrs || !isArgument(argName, attr)) && !processAttribute(childCounter++, attr, writer, stmtDef, ref)) {
fullyDefined = false;
}
}
}
// Now process child elements, if present
final NodeList children = element.getChildNodes();
for (int i = 0, len = children.getLength(); i < len; ++i) {
final Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE && (allElements || !isArgument(argName, child)) && !processElement(childCounter++, (Element) child, writer, stmtDef)) {
fullyDefined = false;
}
}
writer.storeStatement(childCounter, fullyDefined);
writer.endStatement(ref);
return fullyDefined;
}
use of org.opendaylight.yangtools.yang.model.api.meta.ArgumentDefinition in project yangtools by opendaylight.
the class YinXMLEventReader method addStatement.
private void addStatement(final DeclaredStatement<?> statement) {
final StatementDefinition def = statement.statementDefinition();
final QName name = def.getStatementName();
final Optional<ArgumentDefinition> optArgDef = def.getArgumentDefinition();
if (optArgDef.isPresent()) {
final ArgumentDefinition argDef = optArgDef.get();
final QName argName = argDef.getArgumentName();
if (argDef.isYinElement()) {
events.addAll(Arrays.asList(startElement(name), startElement(argName), eventFactory.createCharacters(statement.rawArgument()), endElement(argName)));
} else {
final Entry<String, String> ns = namespaceContext.prefixAndNamespaceFor(name.getModule());
events.add(eventFactory.createStartElement(ns.getKey(), ns.getValue(), name.getLocalName(), singletonIterator(attribute(argName, statement.rawArgument())), emptyIterator(), namespaceContext));
}
} else {
// No attributes: just emit a start
events.add(startElement(name));
}
stack.push(new OpenElement(name, statement.declaredSubstatements().iterator()));
}
Aggregations