Search in sources :

Example 6 with AnydataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project yangtools by opendaylight.

the class NormalizedNodeStreamWriterStack method startAnydataNode.

public void startAnydataNode(final NodeIdentifier name) {
    final SchemaNode schema = enterDataTree(name);
    checkArgument(schema instanceof AnydataSchemaNode, "Node %s is not anydata", schema);
    schemaStack.push(schema);
}
Also used : AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) AugmentationSchemaNode(org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode)

Example 7 with AnydataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project yangtools by opendaylight.

the class YangParserSimpleTest method testParseAnyData.

@Test
public void testParseAnyData() {
    final AnydataSchemaNode anydata = (AnydataSchemaNode) MODULE.findDataChildByName(QName.create(MODULE.getQNameModule(), "data2")).orElse(null);
    assertNotNull("'anydata data not found'", anydata);
    assertEquals("RegularAnydataEffectiveStatement{argument=(urn:opendaylight:simple-nodes?revision=2013-07-30)data2}", anydata.toString());
    // test SchemaNode args
    assertEquals(QName.create(SN, "data2"), anydata.getQName());
    assertEquals(Optional.of("anydata desc"), anydata.getDescription());
    assertEquals(Optional.of("data ref"), anydata.getReference());
    assertEquals(Status.OBSOLETE, anydata.getStatus());
    assertEquals(0, anydata.getUnknownSchemaNodes().size());
    // test DataSchemaNode args
    assertFalse(anydata.isAugmenting());
    assertEquals(Optional.of(Boolean.FALSE), anydata.effectiveConfig());
    assertTrue(anydata.isMandatory());
    assertTrue(anydata.getWhenCondition().isPresent());
    assertEquals("class != 'wheel'", anydata.getWhenCondition().orElseThrow().toString());
    final Collection<? extends MustDefinition> mustConstraints = anydata.getMustConstraints();
    assertEquals(2, mustConstraints.size());
    final String must1 = "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)";
    final String must2 = "ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)";
    boolean found1 = false;
    boolean found2 = false;
    for (final MustDefinition must : mustConstraints) {
        if (must1.equals(must.getXpath().toString())) {
            found1 = true;
            assertEquals(Optional.of("An ethernet MTU must be 1500"), must.getErrorMessage());
        } else if (must2.equals(must.getXpath().toString())) {
            found2 = true;
            assertEquals(Optional.of("An atm MTU must be  64 .. 17966"), must.getErrorMessage());
            assertEquals(Optional.of("anydata data error-app-tag"), must.getErrorAppTag());
            assertEquals(Optional.of("an error occured in data"), must.getDescription());
            assertEquals(Optional.of("data must ref"), must.getReference());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
}
Also used : AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) MustDefinition(org.opendaylight.yangtools.yang.model.api.MustDefinition) Test(org.junit.Test)

Example 8 with AnydataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project yangtools by opendaylight.

the class DeviationResolutionTest method testDeviateAdd.

@Test
public void testDeviateAdd() throws Exception {
    final EffectiveModelContext schemaContext = TestUtils.parseYangSource("/deviation-resolution-test/deviation-add/foo.yang", "/deviation-resolution-test/deviation-add/bar.yang");
    assertNotNull(schemaContext);
    final Module barModule = schemaContext.findModule("bar", Revision.of("2017-01-20")).get();
    final LeafListSchemaNode myLeafList = (LeafListSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-leaf-list"));
    assertNotNull(myLeafList);
    assertEquals(Optional.of(Boolean.FALSE), myLeafList.effectiveConfig());
    assertEquals(3, myLeafList.getDefaults().size());
    final ElementCountConstraint constraint = myLeafList.getElementCountConstraint().get();
    assertEquals((Object) 10, constraint.getMaxElements());
    assertEquals((Object) 5, constraint.getMinElements());
    assertNotNull(myLeafList.getType().getUnits());
    final ListSchemaNode myList = (ListSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-list"));
    assertNotNull(myList);
    assertEquals(2, myList.getUniqueConstraints().size());
    final ChoiceSchemaNode myChoice = (ChoiceSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-choice"));
    assertNotNull(myChoice);
    assertEquals("c2", myChoice.getDefaultCase().get().getQName().getLocalName());
    final RpcDefinition myRpc = barModule.getRpcs().iterator().next();
    final InputSchemaNode input = myRpc.getInput();
    assertEquals(2, input.getMustConstraints().size());
    final OutputSchemaNode output = myRpc.getOutput();
    assertEquals(2, output.getMustConstraints().size());
    final NotificationDefinition myNotification = barModule.getNotifications().iterator().next();
    assertEquals(2, myNotification.getMustConstraints().size());
    final AnyxmlSchemaNode myAnyxml = (AnyxmlSchemaNode) barModule.getDataChildByName(QName.create(barModule.getQNameModule(), "my-anyxml"));
    assertNotNull(myAnyxml);
    assertTrue(myAnyxml.isMandatory());
    final AnydataSchemaNode myAnyData = (AnydataSchemaNode) barModule.findDataChildByName(QName.create(barModule.getQNameModule(), "my-anydata")).orElse(null);
    assertNotNull(myAnyData);
    assertTrue(myAnyData.isMandatory());
}
Also used : LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ElementCountConstraint(org.opendaylight.yangtools.yang.model.api.ElementCountConstraint) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) OutputSchemaNode(org.opendaylight.yangtools.yang.model.api.OutputSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) Module(org.opendaylight.yangtools.yang.model.api.Module) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) Test(org.junit.Test)

Example 9 with AnydataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project yangtools by opendaylight.

the class XmlParserStream method parse.

/**
 * This method parses the XML source and emits node events into a NormalizedNodeStreamWriter based on the
 * YANG-modeled data contained in the XML source.
 *
 * @param reader
 *              StAX reader which is to used to walk through the XML source
 * @return
 *              instance of XmlParserStream
 * @throws XMLStreamException
 *              if a well-formedness error or an unexpected processing condition occurs while parsing the XML
 * @throws URISyntaxException
 *              if the namespace URI of an XML element contains a syntax error
 * @throws IOException
 *              if an error occurs while parsing the value of an anyxml node
 * @throws SAXException
 *              if an error occurs while parsing the value of an anyxml node
 */
public XmlParserStream parse(final XMLStreamReader reader) throws XMLStreamException, URISyntaxException, IOException, SAXException {
    if (reader.hasNext()) {
        reader.nextTag();
        final AbstractNodeDataWithSchema<?> nodeDataWithSchema;
        if (parentNode instanceof ContainerLike) {
            nodeDataWithSchema = new ContainerNodeDataWithSchema((ContainerLike) parentNode);
        } else if (parentNode instanceof ListSchemaNode) {
            nodeDataWithSchema = new ListNodeDataWithSchema((ListSchemaNode) parentNode);
        } else if (parentNode instanceof AnyxmlSchemaNode) {
            nodeDataWithSchema = new AnyXmlNodeDataWithSchema((AnyxmlSchemaNode) parentNode);
        } else if (parentNode instanceof LeafSchemaNode) {
            nodeDataWithSchema = new LeafNodeDataWithSchema((LeafSchemaNode) parentNode);
        } else if (parentNode instanceof LeafListSchemaNode) {
            nodeDataWithSchema = new LeafListNodeDataWithSchema((LeafListSchemaNode) parentNode);
        } else if (parentNode instanceof AnydataSchemaNode) {
            nodeDataWithSchema = new AnydataNodeDataWithSchema((AnydataSchemaNode) parentNode);
        } else {
            throw new IllegalStateException("Unsupported schema node type " + parentNode.getClass() + ".");
        }
        read(reader, nodeDataWithSchema, reader.getLocalName());
        nodeDataWithSchema.write(writer);
    }
    return this;
}
Also used : ContainerLike(org.opendaylight.yangtools.yang.model.api.ContainerLike) LeafListNodeDataWithSchema(org.opendaylight.yangtools.yang.data.util.LeafListNodeDataWithSchema) ListNodeDataWithSchema(org.opendaylight.yangtools.yang.data.util.ListNodeDataWithSchema) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) AnydataNodeDataWithSchema(org.opendaylight.yangtools.yang.data.util.AnydataNodeDataWithSchema) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) LeafNodeDataWithSchema(org.opendaylight.yangtools.yang.data.util.LeafNodeDataWithSchema) ContainerNodeDataWithSchema(org.opendaylight.yangtools.yang.data.util.ContainerNodeDataWithSchema) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) LeafListNodeDataWithSchema(org.opendaylight.yangtools.yang.data.util.LeafListNodeDataWithSchema) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) AnyXmlNodeDataWithSchema(org.opendaylight.yangtools.yang.data.util.AnyXmlNodeDataWithSchema)

Example 10 with AnydataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode in project yangtools by opendaylight.

the class XmlParserStream method translateValueByType.

private Object translateValueByType(final Object value, final DataSchemaNode node, final NamespaceContext namespaceCtx) {
    if (node instanceof AnyxmlSchemaNode) {
        checkArgument(value instanceof Document);
        /*
             * FIXME: Figure out some YANG extension dispatch, which will reuse JSON parsing or XML parsing -
             *        anyxml is not well-defined in JSON.
             */
        return new DOMSource(((Document) value).getDocumentElement());
    }
    if (node instanceof AnydataSchemaNode) {
        checkArgument(value instanceof Document);
        return new DOMSourceAnydata(new DOMSource(((Document) value).getDocumentElement()));
    }
    checkArgument(node instanceof TypedDataSchemaNode);
    checkArgument(value instanceof String);
    return codecs.codecFor((TypedDataSchemaNode) node, stack).parseValue(namespaceCtx, (String) value);
}
Also used : TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) DOMSource(javax.xml.transform.dom.DOMSource) Document(org.w3c.dom.Document) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)

Aggregations

AnydataSchemaNode (org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode)13 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)10 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)7 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)7 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)7 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)6 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)5 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)5 Test (org.junit.Test)4 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)4 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)3 DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)3 TypedDataSchemaNode (org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1