本文整理汇总了Java中org.opendaylight.yangtools.yang.model.util.SchemaContextUtil类的典型用法代码示例。如果您正苦于以下问题:Java SchemaContextUtil类的具体用法?Java SchemaContextUtil怎么用?Java SchemaContextUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SchemaContextUtil类属于org.opendaylight.yangtools.yang.model.util包,在下文中一共展示了SchemaContextUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseDefaultConfigFile
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
private NormalizedNode<?, ?> parseDefaultConfigFile(final ConfigFileProcessor config, final String filename)
throws IOException, XMLStreamException {
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
try (InputStream resourceAsStream = new FileInputStream(new File(this.path, filename))) {
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
final SchemaNode schemaNode = SchemaContextUtil
.findDataSchemaNode(this.schemaContext, config.getSchemaPath());
try (XmlParserStream xmlParser = XmlParserStream.create(streamWriter, this.schemaContext, schemaNode)) {
xmlParser.parse(reader);
} catch (final URISyntaxException | XMLStreamException | IOException | ParserConfigurationException
| SAXException e) {
LOG.warn("Failed to parse xml", e);
} finally {
reader.close();
}
}
return result.getResult();
}
开发者ID:opendaylight,项目名称:bgpcep,代码行数:24,代码来源:ConfigLoaderImpl.java
示例2: findDataSchemaNodeTest
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
final Module module = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
final Module importedModule = context.findModule(new URI("uri:imported-module"),
Revision.of("2014-10-07")).get();
final SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName(QName.create(
importedModule.getQNameModule(), "my-imported-container"))).getDataChildByName(QName.create(
importedModule.getQNameModule(), "my-imported-leaf"));
final RevisionAwareXPath xpath = new RevisionAwareXPathImpl("imp:my-imported-container/imp:my-imported-leaf",
true);
final SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
assertNotNull(foundNode);
assertNotNull(testNode);
assertEquals(testNode, foundNode);
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:22,代码来源:SchemaContextUtilTest.java
示例3: findDataSchemaNodeTest2
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void findDataSchemaNodeTest2() throws URISyntaxException, IOException, YangSyntaxErrorException,
ReactorException {
// findDataSchemaNode(final SchemaContext context, final Module module,
// final RevisionAwareXPath nonCondXPath) {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
final Module module = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
final GroupingDefinition grouping = getGroupingByName(module, "my-grouping");
final SchemaNode testNode = grouping.getDataChildByName(QName.create(module.getQNameModule(),
"my-leaf-in-gouping2"));
final RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
final SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
assertNotNull(foundNode);
assertNotNull(testNode);
assertEquals(testNode, foundNode);
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:23,代码来源:SchemaContextUtilTest.java
示例4: findNodeInSchemaContextTheSameNameOfSiblingsTest
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void findNodeInSchemaContextTheSameNameOfSiblingsTest() throws URISyntaxException, IOException,
YangSyntaxErrorException, ReactorException {
final SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
final ChoiceSchemaNode choice = (ChoiceSchemaNode) getRpcByName(myModule, "my-name").getInput()
.getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"));
final SchemaNode testNode = choice.findCaseNodes("case-two").iterator().next()
.getDataChildByName(QName.create(myModule.getQNameModule(), "two"));
final SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-name"),
QName.create(myModule.getQNameModule(), "input"), QName.create(myModule.getQNameModule(), "my-choice"),
QName.create(myModule.getQNameModule(), "case-two"), QName.create(myModule.getQNameModule(), "two"));
final SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
assertNotNull(testNode);
assertNotNull(foundNode);
assertEquals(testNode, foundNode);
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:22,代码来源:SchemaContextUtilTest.java
示例5: nodeTest
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void nodeTest() throws Exception {
SchemaContext context = StmtTestUtils.parseYangSources(
"/semantic-statement-parser/multiple-revisions/node-test");
assertNotNull(context);
QName root = QName.create("foo", "2016-04-06", "foo-root");
QName container20160404 = QName.create("foo", "2016-04-06", "con20160404");
SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root,
container20160404));
assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
QName container20160405 = QName.create("foo", "2016-04-06", "con20160405");
findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root,
container20160405));
assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
QName container20160406 = QName.create("foo", "2016-04-06", "con20160406");
findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root,
container20160406));
assertNull(findDataSchemaNode);
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:23,代码来源:MoreRevisionsTest.java
示例6: testDeviationsSupportedInSomeModules
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void testDeviationsSupportedInSomeModules() throws Exception {
final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations =
ImmutableSetMultimap.<QNameModule, QNameModule>builder()
.put(foo, bar)
.put(foo, baz)
.put(bar, baz)
.build();
final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
.addSources(FOO_MODULE, BAR_MODULE, BAZ_MODULE, FOOBAR_MODULE)
.setModulesWithSupportedDeviations(modulesWithSupportedDeviations)
.buildEffective();
assertNotNull(schemaContext);
assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContA)));
assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContB)));
assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContC)));
assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myBarContA)));
assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myBarContB)));
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:22,代码来源:Bug8307Test.java
示例7: testBug6961SchemaContext
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void testBug6961SchemaContext() throws Exception {
final Optional<Revision> revision = Revision.ofNullable("2016-01-01");
final SourceIdentifier foo = RevisionSourceIdentifier.create("foo", revision);
final SourceIdentifier sub1Foo = RevisionSourceIdentifier.create("sub1-foo", revision);
final SourceIdentifier sub2Foo = RevisionSourceIdentifier.create("sub2-foo", revision);
final SourceIdentifier bar = RevisionSourceIdentifier.create("bar", revision);
final SourceIdentifier sub1Bar = RevisionSourceIdentifier.create("sub1-bar", revision);
final SourceIdentifier baz = RevisionSourceIdentifier.create("baz", revision);
final Set<SourceIdentifier> testSet = ImmutableSet.of(foo, sub1Foo, sub2Foo, bar, sub1Bar, baz);
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6961/");
assertNotNull(context);
final Set<SourceIdentifier> allModuleIdentifiers = SchemaContextUtil.getConstituentModuleIdentifiers(context);
assertNotNull(allModuleIdentifiers);
assertEquals(6, allModuleIdentifiers.size());
final SchemaContext schemaContext = SimpleSchemaContext.forModules(context.getModules());
assertNotNull(schemaContext);
final Set<SourceIdentifier> allModuleIdentifiersResolved = SchemaContextUtil.getConstituentModuleIdentifiers(
schemaContext);
assertNotNull(allModuleIdentifiersResolved);
assertEquals(6, allModuleIdentifiersResolved.size());
assertEquals(allModuleIdentifiersResolved, allModuleIdentifiers);
assertEquals(allModuleIdentifiers, testSet);
assertTrue(allModuleIdentifiers.contains(foo));
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:26,代码来源:Bug6961Test.java
示例8: choiceCaseTest
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void choiceCaseTest() throws Exception {
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/choice-case");
assertNotNull(context);
final QName myChoice = QName.create(NS, "my-choice");
final QName caseOne = QName.create(NS, "one");
final QName caseTwo = QName.create(NS, "two");
final QName caseThree = QName.create(NS, "three");
final QName containerOne = QName.create(NS, "container-one");
final QName containerTwo = QName.create(NS, "container-two");
final QName containerThree = QName.create(NS, "container-three");
verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
SchemaPath.create(true, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B)));
verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
SchemaPath.create(true, ROOT, myChoice, caseTwo, containerTwo, LEAF_CONT_B)));
verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
SchemaPath.create(true, ROOT, myChoice, caseThree, containerThree, INNER_CONTAINER, LEAF_CONT_B)));
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:21,代码来源:Bug6771Test.java
示例9: test
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void test() throws Exception {
SchemaContext context = TestUtils.parseYangSources("/bugs/bug4231");
assertNotNull(context);
QNameModule foo = QNameModule.create(new URI("foo"), Revision.of("2015-09-02"));
SchemaPath targetPath = SchemaPath
.create(true, QName.create(foo, "augment-target"))
.createChild(QName.create(foo, "my-container-in-grouping"))
.createChild(QName.create(foo, "l2"));
SchemaNode targetNode = SchemaContextUtil.findNodeInSchemaContext(
context, targetPath.getPathFromRoot());
assertNotNull(targetNode);
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:18,代码来源:Bug4231Test.java
示例10: createComplexCodecFor
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
private T createComplexCodecFor(final TypedDataSchemaNode schema, final TypeDefinition<?> type) {
if (type instanceof UnionTypeDefinition) {
return createComplexUnion(schema, (UnionTypeDefinition) type);
} else if (type instanceof LeafrefTypeDefinition) {
final TypeDefinition<?> target = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) type,
schemaContext, schema);
verifyNotNull(target, "Unable to find base type for leafref node %s type %s.", schema.getPath(),
target);
final T ret = getSimpleCodecFor(target);
return ret != null ? ret : createComplexCodecFor(schema, target);
} else if (type instanceof IdentityrefTypeDefinition) {
return identityRefCodec((IdentityrefTypeDefinition) type, schema.getQName().getModule());
} else {
throw new IllegalArgumentException("Unsupported type " + type);
}
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:18,代码来源:AbstractCodecFactory.java
示例11: testDeviationsSupportedInSomeModules
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void testDeviationsSupportedInSomeModules() throws Exception {
final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations =
ImmutableSetMultimap.<QNameModule, QNameModule>builder()
.put(foo, bar)
.put(foo, baz)
.put(bar, baz)
.build();
final ListenableFuture<SchemaContext> lf = createSchemaContext(modulesWithSupportedDeviations, FOO, BAR, BAZ,
FOOBAR);
assertTrue(lf.isDone());
final SchemaContext schemaContext = lf.get();
assertNotNull(schemaContext);
assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContA)));
assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContB)));
assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myFooContC)));
assertNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myBarContA)));
assertNotNull(SchemaContextUtil.findDataSchemaNode(schemaContext, SchemaPath.create(true, myBarContB)));
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:22,代码来源:SchemaContextFactoryDeviationsTest.java
示例12: identityToGenType
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
private GeneratedType identityToGenType(final String basePackageName, final IdentitySchemaNode identity,
final SchemaContext context) {
if (identity == null) {
return null;
}
final String packageName = packageNameForGeneratedType(basePackageName, identity.getPath());
final String genTypeName = parseToClassName(identity.getQName().getLocalName());
final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, genTypeName);
IdentitySchemaNode baseIdentity = identity.getBaseIdentity();
if (baseIdentity != null) {
Module baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity);
final String returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule);
final String returnTypeName = parseToClassName(baseIdentity.getQName().getLocalName());
GeneratedTransferObject gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance();
newType.setExtendsType(gto);
} else {
newType.setExtendsType(Types.getBaseIdentityTO());
}
newType.setAbstract(true);
return newType.toInstance();
}
开发者ID:lbchen,项目名称:ODL,代码行数:26,代码来源:BindingGeneratorImpl.java
示例13: addKeyValue
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
/**
* Adds a Key Value to the map for a specific uri value.
* @param map - current QName to Object mapping
* @param node - DataSchemaNode
* @param uriValue - uri value to add
* @throws Exception if error occurs during Uri decoding.
*/
private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue)
throws Exception {
Preconditions.checkNotNull(uriValue);
Preconditions.checkArgument((node instanceof LeafSchemaNode));
final String urlDecoded = urlPathArgDecode(uriValue);
TypeDefinition<?> typedef = ((LeafSchemaNode) node).getType();
final TypeDefinition<?> baseType = resolveBaseTypeFrom(typedef);
if (baseType instanceof LeafrefTypeDefinition) {
typedef = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) baseType, globalSchema, node);
}
Object decoded = deserialize(typedef, urlDecoded);
String additionalInfo = "";
if (decoded == null) {
if ((baseType instanceof IdentityrefTypeDefinition)) {
decoded = toQName(urlDecoded);
additionalInfo = "For key which is of type identityref it should be in format module_name:identity_name.";
}
}
if (decoded == null) {
throw new Exception(uriValue + " from URI can't be resolved. " + additionalInfo);
}
map.put(node.getQName(), decoded);
}
开发者ID:opendaylight,项目名称:fpc,代码行数:35,代码来源:NameResolver.java
示例14: findQNameFromGrouping
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
/**
* Find "proper" qname of unknown node in case it comes from a grouping
*/
private static QName findQNameFromGrouping(final DataNodeContainer subtree, final SchemaContext ctx, final UnknownSchemaNode unknownSchemaNode, final String localIdentityName) {
QName identityQName = null;
for (UsesNode usesNode : subtree.getUses()) {
SchemaNode dataChildByName = SchemaContextUtil.findDataSchemaNode(ctx, usesNode.getGroupingPath());
Module m = SchemaContextUtil.findParentModule(ctx, dataChildByName);
List<UnknownSchemaNode> unknownSchemaNodes = dataChildByName.getUnknownSchemaNodes();
if(Collections2.transform(unknownSchemaNodes, UNKNOWN_NODE_TO_STRING).contains(UNKNOWN_NODE_TO_STRING.apply(unknownSchemaNode))) {
identityQName = QName.create(dataChildByName.getQName(), localIdentityName);
}
}
return identityQName;
}
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:16,代码来源:RuntimeBeanEntry.java
示例15: testParsingAttributes
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void testParsingAttributes() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8745/foo.yang");
final QName contWithAttributes = QName.create("foo", "cont-with-attributes");
final ContainerSchemaNode contWithAttr = (ContainerSchemaNode) SchemaContextUtil.findDataSchemaNode(
schemaContext, SchemaPath.create(true, contWithAttributes));
final Document doc = loadDocument("/bug8745/foo.xml");
final DOMSource domSource = new DOMSource(doc.getDocumentElement());
final DOMResult domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
final XMLOutputFactory outputfactory = XMLOutputFactory.newInstance();
outputfactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
final XMLStreamWriter xmlStreamWriter = outputfactory.createXMLStreamWriter(domResult);
final NormalizedNodeStreamWriter streamWriter = XMLStreamNormalizedNodeStreamWriter.create(
xmlStreamWriter, schemaContext);
final InputStream resourceAsStream = Bug8745Test.class.getResourceAsStream("/bug8745/foo.xml");
// final XMLStreamReader reader = inputFactory.createXMLStreamReader(resourceAsStream);
final XMLStreamReader reader = new DOMSourceXMLStreamReader(domSource);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, contWithAttr);
xmlParser.parse(reader);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setNormalize(true);
final String expectedXml = toString(doc.getDocumentElement());
final String serializedXml = toString(domResult.getNode());
final Diff diff = new Diff(expectedXml, serializedXml);
XMLAssert.assertXMLEqual(diff, true);
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:37,代码来源:Bug8745Test.java
示例16: setup
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@BeforeClass
public static void setup() {
fooModule = QNameModule.create(URI.create("foo-namespace"));
parentContainer = QName.create(fooModule, "parent-container");
bazModule = QNameModule.create(URI.create("baz-namespace"));
outerContainer = QName.create(bazModule, "outer-container");
myContainer1 = QName.create(bazModule, "my-container-1");
myKeyedList = QName.create(bazModule, "my-keyed-list");
myKeyLeaf = QName.create(bazModule, "my-key-leaf");
myLeafInList1 = QName.create(bazModule, "my-leaf-in-list-1");
myLeafInList2 = QName.create(bazModule, "my-leaf-in-list-2");
myLeaf1 = QName.create(bazModule, "my-leaf-1");
myLeafList = QName.create(bazModule, "my-leaf-list");
myContainer2 = QName.create(bazModule, "my-container-2");
innerContainer = QName.create(bazModule, "inner-container");
myLeaf2 = QName.create(bazModule, "my-leaf-2");
myLeaf3 = QName.create(bazModule, "my-leaf-3");
myChoice = QName.create(bazModule, "my-choice");
myLeafInCase2 = QName.create(bazModule, "my-leaf-in-case-2");
myContainer3 = QName.create(bazModule, "my-container-3");
myDoublyKeyedList = QName.create(bazModule, "my-doubly-keyed-list");
myFirstKeyLeaf = QName.create(bazModule, "my-first-key-leaf");
mySecondKeyLeaf = QName.create(bazModule, "my-second-key-leaf");
myLeafInList3 = QName.create(bazModule, "my-leaf-in-list-3");
schemaContext = YangParserTestUtils.parseYangResourceDirectory("/");
parentContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext,
ImmutableList.of(parentContainer));
outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext,
ImmutableList.of(outerContainer));
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:36,代码来源:XmlToNormalizedNodesTest.java
示例17: test
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void test() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug8803");
final SchemaPath topContPath = SchemaPath.create(true, QName.create("foo-ns", "top-cont"));
final SchemaNode dataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, topContPath);
assertTrue(dataSchemaNode instanceof ContainerSchemaNode);
final ContainerSchemaNode topContSchema = (ContainerSchemaNode) dataSchemaNode;
final InputStream resourceAsStream = Bug8803Test.class.getResourceAsStream("/bug8803/foo.xml");
// deserialization
final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topContSchema);
xmlParser.parse(reader);
final NormalizedNode<?, ?> transformedInput = result.getResult();
assertNotNull(transformedInput);
// serialization
final StringWriter writer = new StringWriter();
final XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
// switching NS repairing to false does not help
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
final XMLStreamWriter xmlStreamWriter = outputFactory.createXMLStreamWriter(writer);
final NormalizedNodeStreamWriter xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(
xmlStreamWriter, schemaContext);
final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(
xmlNormalizedNodeStreamWriter);
normalizedNodeWriter.write(transformedInput);
final String serializedXml = writer.toString();
assertFalse(serializedXml.isEmpty());
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:38,代码来源:Bug8803Test.java
示例18: test
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void test() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/dom-reader-test");
final ContainerSchemaNode outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil
.findNodeInSchemaContext(schemaContext, ImmutableList.of(QName.create("foo-ns", "top-cont")));
assertNotNull(outerContainerSchema);
// deserialization
final Document doc = loadDocument("/dom-reader-test/foo.xml");
final DOMSource inputXml = new DOMSource(doc.getDocumentElement());
XMLStreamReader domXMLReader = new DOMSourceXMLStreamReader(inputXml);
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, outerContainerSchema);
xmlParser.parse(domXMLReader);
final NormalizedNode<?, ?> transformedInput = result.getResult();
assertNotNull(transformedInput);
// serialization
//final StringWriter writer = new StringWriter();
final DOMResult domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
final XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
final XMLStreamWriter xmlStreamWriter = outputFactory.createXMLStreamWriter(domResult);
final NormalizedNodeStreamWriter xmlNormalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(
xmlStreamWriter, schemaContext);
final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(
xmlNormalizedNodeStreamWriter);
normalizedNodeWriter.write(transformedInput);
//final String serializedXml = writer.toString();
final String serializedXml = toString(domResult.getNode());
assertFalse(serializedXml.isEmpty());
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:38,代码来源:DOMSourceXMLStreamReaderTest.java
示例19: getTargetNodeForLeafRef
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
private TypeDefinition<?> getTargetNodeForLeafRef(final String nodeName, final Class<?> clas) {
final LeafSchemaNode schemaNode = findSchemaNodeWithLeafrefType(leafRefModule, nodeName);
assertNotNull(schemaNode);
final LeafrefTypeDefinition leafrefTypedef = findLeafrefType(schemaNode);
assertNotNull(leafrefTypedef);
final TypeDefinition<?> targetBaseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypedef, schemaContext,
schemaNode);
assertTrue("Wrong class found.", clas.isInstance(targetBaseType));
return targetBaseType;
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:11,代码来源:XmlStreamUtilsTest.java
示例20: valid10Test
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; //导入依赖的package包/类
@Test
public void valid10Test() throws Exception {
final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6880/foo.yang");
assertNotNull(schemaContext);
final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext,
SchemaPath.create(true, QName.create(FOO_NS, "my-leaf-list")));
assertTrue(findDataSchemaNode instanceof LeafListSchemaNode);
final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
final Collection<? extends Object> defaults = myLeafList.getDefaults();
assertEquals(2, defaults.size());
assertTrue(defaults.contains("my-default-value-1") && defaults.contains("my-default-value-2"));
}
开发者ID:opendaylight,项目名称:yangtools,代码行数:15,代码来源:Bug6880Test.java
注:本文中的org.opendaylight.yangtools.yang.model.util.SchemaContextUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论