예제 #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();
 }
예제 #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());
  }
예제 #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();
  }
예제 #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();
  }
예제 #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();
  }
예제 #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();
  }