Exemplo n.º 1
0
 public static Module loadYinModule(final InputStream stream)
     throws SourceException, ReactorException {
   final CrossSourceStatementReactor.BuildAction reactor =
       YangInferencePipeline.RFC6020_REACTOR.newBuild();
   addYinSources(reactor, new YinStatementSourceImpl(stream));
   EffectiveSchemaContext ctx = reactor.buildEffective();
   return ctx.getModules().iterator().next();
 }
Exemplo n.º 2
0
  @Test
  public void listAndLeavesTest() throws ReactorException {
    CrossSourceStatementReactor.BuildAction reactor =
        YangInferencePipeline.RFC6020_REACTOR.newBuild();
    StmtTestUtils.addSources(reactor, LIST_MODULE);

    EffectiveSchemaContext result = reactor.buildEffective();
    assertNotNull(result);

    Module testModule = result.findModuleByName("list-test", null);
    assertNotNull(testModule);

    ListSchemaNode list = (ListSchemaNode) testModule.getDataChildByName("simple-list");
    assertNotNull(list);

    assertTrue(list.isUserOrdered());
    assertTrue(list.isConfiguration());
    List<QName> keys = list.getKeyDefinition();
    assertEquals(2, keys.size());

    assertEquals("key1", keys.get(0).getLocalName());
    assertEquals("key2", keys.get(1).getLocalName());

    assertEquals(1, list.getConstraints().getMinElements().intValue());
    assertEquals(10, list.getConstraints().getMaxElements().intValue());

    assertEquals(5, list.getChildNodes().size());

    LeafSchemaNode leaf = (LeafSchemaNode) list.getDataChildByName("key1");
    assertNotNull(leaf);
    assertTrue(leaf.getConstraints().isMandatory());
    assertEquals("int32", leaf.getType().getQName().getLocalName());

    leaf = (LeafSchemaNode) list.getDataChildByName("key2");
    assertNotNull(leaf);
    assertTrue(leaf.getConstraints().isMandatory());
    assertEquals("int16", leaf.getType().getQName().getLocalName());

    leaf = (LeafSchemaNode) list.getDataChildByName("old-leaf");
    assertNotNull(leaf);
    assertFalse(leaf.getConstraints().isMandatory());
    assertEquals("string", leaf.getType().getQName().getLocalName());

    leaf = (LeafSchemaNode) list.getDataChildByName("young-leaf");
    assertNotNull(leaf);
    assertFalse(leaf.getConstraints().isMandatory());
    assertEquals("young-leaf", leaf.getType().getQName().getLocalName());
    assertEquals("default-value", leaf.getDefault());

    LeafListSchemaNode leafList = (LeafListSchemaNode) list.getDataChildByName("list-of-leaves");
    assertNotNull(leafList);
    assertTrue(leafList.getConstraints().isMandatory());
    assertTrue(leafList.isUserOrdered());
    assertEquals(2, leafList.getConstraints().getMinElements().intValue());
    assertEquals(20, leafList.getConstraints().getMaxElements().intValue());
    assertEquals("string", leafList.getType().getQName().getLocalName());
  }
Exemplo n.º 3
0
  public static SchemaContext parseYangSources(final StatementStreamSource... sources)
      throws SourceException, ReactorException {

    CrossSourceStatementReactor.BuildAction reactor =
        YangInferencePipeline.RFC6020_REACTOR.newBuild();
    reactor.addSources(sources);

    return reactor.buildEffective();
  }
Exemplo n.º 4
0
  public static Set<Module> loadYinModules(final List<InputStream> streams)
      throws SourceException, ReactorException {
    final CrossSourceStatementReactor.BuildAction reactor =
        YangInferencePipeline.RFC6020_REACTOR.newBuild();
    for (InputStream inputStream : streams) {
      addYinSources(reactor, new YinStatementSourceImpl(inputStream));
    }

    EffectiveSchemaContext ctx = reactor.buildEffective();
    return ctx.getModules();
  }
Exemplo n.º 5
0
  public static Set<Module> loadYinModules(final URI resourceDirectory) throws ReactorException {
    final CrossSourceStatementReactor.BuildAction reactor =
        YangInferencePipeline.RFC6020_REACTOR.newBuild();

    for (File file : new File(resourceDirectory).listFiles()) {
      addYinSources(reactor, new YinStatementSourceImpl(file.getPath(), true));
    }

    EffectiveSchemaContext ctx = reactor.buildEffective();
    return ctx.getModules();
  }
Exemplo n.º 6
0
  public static Set<Module> loadModules(final URI resourceDirectory)
      throws SourceException, ReactorException {
    final CrossSourceStatementReactor.BuildAction reactor =
        YangInferencePipeline.RFC6020_REACTOR.newBuild();
    File[] files = new File(resourceDirectory).listFiles();

    for (File file : files) {
      if (file.getName().endsWith(".yang")) {
        addSources(reactor, new YangStatementSourceImpl(file.getPath(), true));
      } else {
        LOG.info("Ignoring non-yang file {}", file);
      }
    }

    EffectiveSchemaContext ctx = reactor.buildEffective();
    return ctx.getModules();
  }