org.opendaylight.yangtools.yang.common.QNameModule Java Examples
The following examples show how to use
org.opendaylight.yangtools.yang.common.QNameModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatementSupport.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Determine reactor copy behavior of a statement instance. Statement support classes are required to determine * their operations with regard to their statements being replicated into different contexts, so that * {@link Mutable} instances are not created when it is evident they are superfluous. * * @param stmt Context of statement to be copied statement. * @param parent Parent statement context * @param copyType Type of copy being performed * @param targetModule Target module, if present * @return Policy that needs to be applied to the copy operation of this statement. */ // FIXME: YANGTOOLS-694: clarify targetModule semantics (does null mean 'same as declared'?) default @NonNull CopyPolicy applyCopyPolicy(final Mutable<?, ?, ?> stmt, final Mutable<?, ?, ?> parent, final CopyType copyType, @Nullable final QNameModule targetModule) { // Most of statement supports will just want to copy the statement // FIXME: YANGTOOLS-694: that is not strictly true. Subclasses of this should indicate if they are themselves // copy-sensitive: // 1) if they are not and cannot be targeted by inference, and all their current // substatements are also non-sensitive, we want to return the same context. // 2) if they are not and their current substatements are sensitive, we want to copy // as a lazily-instantiated interceptor to let it deal with substatements when needed // (YANGTOOLS-1067 prerequisite) // 3) otherwise perform this eager copy // return Optional.of(parent.childCopyOf(stmt, copyType, targetModule)); return CopyPolicy.DECLARED_COPY; }
Example #2
Source File: XMLStreamWriterUtils.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Write a value into a XML stream writer. This method assumes the start and end of element is * emitted by the caller. * * @param writer XML Stream writer * @param type data type. In case of leaf ref this should be the type of leaf being referenced * @param value data value * @param parent optional parameter of a module QName owning the leaf definition * @return String characters to be written * @throws XMLStreamException if an encoding problem occurs */ private String encodeValue(final @NonNull ValueWriter writer, final @NonNull TypeDefinition<?> type, final @NonNull Object value, final QNameModule parent) throws XMLStreamException { if (type instanceof IdentityrefTypeDefinition) { return encode(writer, (IdentityrefTypeDefinition) type, value, parent); } else if (type instanceof InstanceIdentifierTypeDefinition) { return encode(writer, (InstanceIdentifierTypeDefinition) type, value); } else if (value instanceof QName && isIdentityrefUnion(type)) { // Ugly special-case form unions with identityrefs return encode(writer, (QName) value, parent); } else if (value instanceof YangInstanceIdentifier && isInstanceIdentifierUnion(type)) { return encodeInstanceIdentifier(writer, (YangInstanceIdentifier) value); } else { return serialize(type, value); } }
Example #3
Source File: DerivedFromXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testInvalidNormalizedNodeValueType() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode("should be QName")); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("bar-prefix", BAR_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToIdrefLeafNode()); final Function derivedFromFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "derived-from"); assertFalse(getDerivedFromResult(derivedFromFunction, normalizedNodeContext, "foo-prefix:id-a3")); }
Example #4
Source File: AbstractMagnesiumDataInput.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private @NonNull QNameModule decodeQNameModuleDef(final byte type) throws IOException { final String namespace = readRefString(type); final byte refType = input.readByte(); final String revision = refType == MagnesiumValue.STRING_EMPTY ? null : readRefString(refType); final QNameModule module; try { module = QNameFactory.createModule(namespace, revision); } catch (UncheckedExecutionException e) { throw new InvalidNormalizedNodeStreamException("Illegal QNameModule ns=" + namespace + " rev=" + revision, e); } codedModules.add(module); return module; }
Example #5
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkContentSimpleTest(final SchemaContext context) { URI yangTypesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"); final Revision rev20100924 = Revision.of("2010-09-24"); final Revision rev20130516 = Revision.of("2013-05-16"); final Revision rev20130715 = Revision.of("2013-07-15"); final QNameModule yangTypes20100924 = QNameModule.create(yangTypesNS, rev20100924); final QNameModule yangTypes20130516 = QNameModule.create(yangTypesNS, rev20130516); final QNameModule yangTypes20130715 = QNameModule.create(yangTypesNS, rev20130715); final QName dateTimeTypeDef20100924 = QName.create(yangTypes20100924, "date-and-time"); final QName dateTimeTypeDef20130516 = QName.create(yangTypes20130516, "date-and-time"); final QName dateTimeTypeDef20130715 = QName.create(yangTypes20130715, "date-and-time"); Module yangTypesModule20100924 = context.findModule("ietf-yang-types", rev20100924).get(); Module yangTypesModule20130516 = context.findModule("ietf-yang-types", rev20130516).get(); Module yangTypesModule20130715 = context.findModule("ietf-yang-types", rev20130715).get(); assertTrue(findTypeDef(yangTypesModule20100924, dateTimeTypeDef20100924)); assertTrue(findTypeDef(yangTypesModule20130516, dateTimeTypeDef20130516)); assertTrue(findTypeDef(yangTypesModule20130715, dateTimeTypeDef20130715)); checkNetconfMonitoringModuleSimpleTest(context, rev20130715, dateTimeTypeDef20130715); checkInterfacesModuleSimpleTest(context, rev20100924, dateTimeTypeDef20100924); }
Example #6
Source File: StmtContextUtils.java From yangtools with Eclipse Public License 1.0 | 6 votes |
public static QName parseNodeIdentifier(StmtContext<?, ?, ?> ctx, final String prefix, final String localName) { final QNameModule module = getModuleQNameByPrefix(ctx, prefix); if (module != null) { return internedQName(ctx, module, localName); } if (ctx.getCopyHistory().getLastOperation() == CopyType.ADDED_BY_AUGMENTATION) { final Optional<? extends StmtContext<?, ?, ?>> optOrigCtx = ctx.getOriginalCtx(); if (optOrigCtx.isPresent()) { ctx = optOrigCtx.get(); final QNameModule origModule = getModuleQNameByPrefix(ctx, prefix); if (origModule != null) { return internedQName(ctx, origModule, localName); } } } throw new InferenceException(ctx.getStatementSourceReference(), "Cannot resolve QNameModule for '%s'", prefix); }
Example #7
Source File: EnumValueXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testEnumValueFunction() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class, "/yang-xpath-functions-test/enum-value-function/foo.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode("major")); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("foo-prefix", FOO_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToSeverityLeafNode("major")); final Function enumValueFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "enum-value"); final int enumValueResult = (int) enumValueFunction.call(normalizedNodeContext, ImmutableList.of()); assertEquals(5, enumValueResult); }
Example #8
Source File: EnumValueXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testInvalidNormalizedNodeValueType() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class, "/yang-xpath-functions-test/enum-value-function/foo.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode(100)); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("foo-prefix", FOO_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToSeverityLeafNode(100)); final Function enumValueFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "enum-value"); final Double enumValueResult = (Double) enumValueFunction.call(normalizedNodeContext, ImmutableList.of()); assertEquals(Double.NaN, enumValueResult, 0.001); }
Example #9
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkContentFullTest(final SchemaContext context) { URI yangTypesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"); final Revision rev20100924 = Revision.of("2010-09-24"); final Revision rev20130516 = Revision.of("2013-05-16"); final Revision rev20130715 = Revision.of("2013-07-15"); final QNameModule yangTypes20100924 = QNameModule.create(yangTypesNS, rev20100924); final QNameModule yangTypes20130516 = QNameModule.create(yangTypesNS, rev20130516); final QNameModule yangTypes20130715 = QNameModule.create(yangTypesNS, rev20130715); final QName dateTimeTypeDef20100924 = QName.create(yangTypes20100924, "date-and-time"); final QName dateTimeTypeDef20130516 = QName.create(yangTypes20130516, "date-and-time"); final QName dateTimeTypeDef20130715 = QName.create(yangTypes20130715, "date-and-time"); Module yangTypesModule20100924 = context.findModule("ietf-yang-types", rev20100924).get(); Module yangTypesModule20130516 = context.findModule("ietf-yang-types", rev20130516).get(); Module yangTypesModule20130715 = context.findModule("ietf-yang-types", rev20130715).get(); assertTrue(findTypeDef(yangTypesModule20100924, dateTimeTypeDef20100924)); assertTrue(findTypeDef(yangTypesModule20130516, dateTimeTypeDef20130516)); assertTrue(findTypeDef(yangTypesModule20130715, dateTimeTypeDef20130715)); checkNetconfMonitoringModuleFullTest(context, rev20130715, dateTimeTypeDef20130715); checkInterfacesModuleFullTest(context, rev20100924, dateTimeTypeDef20100924); }
Example #10
Source File: DerivedFromXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/bar-invalid.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode(ID_C2_IDENTITY)); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("bar-prefix", BAR_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToIdrefLeafNode()); final Function derivedFromFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "derived-from"); assertFalse(getDerivedFromResult(derivedFromFunction, normalizedNodeContext, "some-identity")); }
Example #11
Source File: YangModeledAnyXMLDeserializationTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Before public void setUp() { barModuleQName = QNameModule.create(URI.create("bar")); myContainer1 = QName.create(barModuleQName, "my-container-1"); myLeaf1 = QName.create(barModuleQName, "my-leaf-1"); myAnyXMLDataBar = QName.create(barModuleQName, "my-anyxml-data"); fooModuleQName = QNameModule.create(URI.create("foo")); myContainer2 = QName.create(fooModuleQName, "my-container-2"); innerContainer = QName.create(fooModuleQName, "inner-container"); myLeaf3 = QName.create(fooModuleQName, "my-leaf-3"); myLeaf2 = QName.create(fooModuleQName, "my-leaf-2"); myAnyXMLDataFoo = QName.create(fooModuleQName, "my-anyxml-data"); schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/yang"); }
Example #12
Source File: LeafRefPathParserImpl.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static Deque<QNameWithPredicate> createPathSteps(final QNameModule localModule, final ImmutableList<Step> steps) { final Deque<QNameWithPredicate> path = new ArrayDeque<>(steps.size()); for (Step step : steps) { switch (step.getAxis()) { case CHILD: checkState(step instanceof QNameStep, "Unsupported step %s", step); path.add(adaptChildStep((QNameStep) step, localModule)); break; case PARENT: path.add(QNameWithPredicate.UP_PARENT); break; default: throw new IllegalStateException("Unsupported axis in step " + step); } } return path; }
Example #13
Source File: AbstractModuleStatementSupport.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Override public final void onPreLinkageDeclared(final Mutable<String, ModuleStatement, ModuleEffectiveStatement> stmt) { final String moduleName = stmt.getStatementArgument(); final URI moduleNs = firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class); SourceException.throwIfNull(moduleNs, stmt.getStatementSourceReference(), "Namespace of the module [%s] is missing", stmt.getStatementArgument()); stmt.addToNs(ModuleNameToNamespace.class, moduleName, moduleNs); final String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class); SourceException.throwIfNull(modulePrefix, stmt.getStatementSourceReference(), "Prefix of the module [%s] is missing", stmt.getStatementArgument()); stmt.addToNs(ImpPrefixToNamespace.class, modulePrefix, moduleNs); stmt.addContext(PreLinkageModuleNamespace.class, moduleName, stmt); final Optional<Revision> revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()); final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern(); stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule); stmt.setRootIdentifier(RevisionSourceIdentifier.create(stmt.getStatementArgument(), revisionDate)); }
Example #14
Source File: SchemaContextFactoryDeviationsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static ListenableFuture<EffectiveModelContext> createSchemaContext( final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations, final String... resources) throws Exception { final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository( "shared-schema-repo-with-deviations-test"); final Collection<SourceIdentifier> requiredSources = new ArrayList<>(); for (final String resource : resources) { final SettableSchemaProvider<ASTSchemaSource> yangSource = getImmediateYangSourceProviderFromResource( resource); yangSource.register(sharedSchemaRepository); yangSource.setResult(); requiredSources.add(yangSource.getId()); } final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.builder() .setModulesDeviatedByModules(modulesWithSupportedDeviations).build(); return sharedSchemaRepository.createEffectiveModelContextFactory(config).createEffectiveModelContext( requiredSources); }
Example #15
Source File: JSONStreamWriterContext.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Write a child JSON node identifier, optionally prefixing it with the module name corresponding to its namespace. * * @param schema Schema context * @param writer Output writer * @param qname Namespace/name tuple * @throws IOException when the writer reports it */ final void writeChildJsonIdentifier(final SchemaContext schema, final JsonWriter writer, final QName qname) throws IOException { final StringBuilder sb = new StringBuilder(); // Prepend module name if namespaces do not match final QNameModule module = qname.getModule(); if (!module.getNamespace().equals(getNamespace())) { final Optional<String> modules = schema.findModule(module).map(Module::getName); checkArgument(modules.isPresent(), "Could not find module for namespace {}", module); sb.append(modules.get()).append(':'); } sb.append(qname.getLocalName()); writer.name(sb.toString()); }
Example #16
Source File: AbstractL3vpnMcastIpRIBSupport.java From bgpcep with Eclipse Public License 1.0 | 6 votes |
/** * Default constructor. Requires the QName of the container augmented under the routes choice * node in instantiations of the rib grouping. It is assumed that this container is defined by * the same model which populates it with route grouping instantiation, and by extension with * the route attributes container. * * @param mappingService Serialization service * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null * @param afiClass address Family Class * @param destContainerQname destination container Qname * @param destListQname destinations list Qname */ AbstractL3vpnMcastIpRIBSupport( final BindingNormalizedNodeSerializer mappingService, final Class<C> cazeClass, final Class<S> containerClass, final Class<? extends AddressFamily> afiClass, final QName destContainerQname, final QName destListQname) { super(mappingService, cazeClass, containerClass, L3vpnMcastRoute.class, afiClass, McastMplsLabeledVpnSubsequentAddressFamily.class, destContainerQname); final QNameModule module = BindingReflections.getQNameModule(cazeClass); this.nlriRoutesList = NodeIdentifier.create(destListQname); this.rdNid = new NodeIdentifier(QName.create(module, "route-distinguisher")); this.cacheableNlriObjects = ImmutableSet.of(cazeClass); }
Example #17
Source File: Utils.java From yangtools with Eclipse Public License 1.0 | 5 votes |
static Resolved interpretAsQName(final YangNamespaceContext namespaceContext, final QNameModule defaultNamespace, final YangLiteralExpr expr) throws XPathExpressionException { final String text = expr.getLiteral(); final int colon = text.indexOf(':'); final QName qname; try { qname = colon == -1 ? QName.create(defaultNamespace, text).intern() : namespaceContext.createQName(text.substring(0, colon), text.substring(colon + 1)); } catch (IllegalArgumentException e) { throw wrapException(e, "Cannot interpret %s as a QName", expr); } return YangQNameExpr.of(qname); }
Example #18
Source File: ModuleNamespaceContext.java From yangtools with Eclipse Public License 1.0 | 5 votes |
Entry<String, String> prefixAndNamespaceFor(final QNameModule module) { if (YangConstants.RFC6020_YIN_MODULE.equals(module)) { return YIN_PREFIX_AND_NAMESPACE; } final String prefix = moduleToPrefix.get(module); checkArgument(prefix != null, "Module %s does not map to a prefix", module); return new SimpleImmutableEntry<>(prefix, module.getNamespace().toString()); }
Example #19
Source File: DeviationStatementSupport.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Override public void onFullDefinitionDeclared( final Mutable<Absolute, DeviationStatement, DeviationEffectiveStatement> ctx) { final QNameModule currentModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx.getRoot()); final QNameModule targetModule = Iterables.getLast(ctx.coerceStatementArgument().getNodeIdentifiers()) .getModule(); if (currentModule.equals(targetModule)) { throw new InferenceException(ctx.getStatementSourceReference(), "Deviation must not target the same module as the one it is defined in: %s", currentModule); } }
Example #20
Source File: DerivedFromXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void shouldFailOnMalformedIdentityArgument() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode(ID_C2_IDENTITY)); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("bar-prefix", BAR_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToIdrefLeafNode()); final Function derivedFromFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "derived-from"); try { getDerivedFromResult(derivedFromFunction, normalizedNodeContext, "foo:bar:id-a3"); fail("Function call should have failed on malformed identity argument."); } catch (IllegalArgumentException ex) { assertEquals("Malformed identity argument: foo:bar:id-a3.", ex.getMessage()); } }
Example #21
Source File: RandomPrefixTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test2QNames1Namespace() throws Exception { final RandomPrefix a = new RandomPrefix(null); final URI uri = URI.create("localhost"); final QName qname = QName.create(QNameModule.create(uri, Revision.of("2000-01-01")), "local-name"); final QName qname2 = QName.create(QNameModule.create(uri, Revision.of("2000-01-01")), "local-name"); assertEquals(a.encodePrefix(qname.getNamespace()), a.encodePrefix(qname2.getNamespace())); }
Example #22
Source File: SchemaContextUtil.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Beta public static SchemaNode findDataTreeSchemaNode(final SchemaContext ctx, final QNameModule localModule, final PathExpression absPath) { final Steps pathSteps = absPath.getSteps(); if (pathSteps instanceof LocationPathSteps) { return findDataTreeSchemaNode(ctx, localModule, ((LocationPathSteps) pathSteps).getLocationPath()); } // We would need a reference schema node and no, we do not want to use SchemaContext in its SchemaNode capacity checkArgument(!(pathSteps instanceof DerefSteps), "No reference node for steps %s", pathSteps); // We are missing proper API alignment, if this ever triggers throw new IllegalStateException("Unsupported path " + pathSteps); }
Example #23
Source File: Bug4610Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug4610"); Revision revision = Revision.of("2015-12-12"); QNameModule foo = QNameModule.create(URI.create("foo"), revision); QNameModule bar = QNameModule.create(URI.create("bar"), revision); QName g1 = QName.create(bar, "g1"); QName g2 = QName.create(bar, "g2"); QName c1Bar = QName.create(bar, "c1"); QName c1Foo = QName.create(foo, "c1"); QName g3 = QName.create(foo, "g3"); QName root = QName.create(foo, "root"); ContainerEffectiveStatement effectiveContainerStatementG1 = findContainer(context, g1, c1Bar); ContainerEffectiveStatement effectiveContainerStatementG2 = findContainer(context, g2, c1Bar); ContainerEffectiveStatement effectiveContainerStatementG3 = findContainer(context, g3, c1Foo); ContainerEffectiveStatement effectiveContainerStatementRoot = findContainer(context, root, c1Foo); // check arguments QName originalStatementArgument = effectiveContainerStatementG1.argument(); assertTrue(originalStatementArgument.equals(effectiveContainerStatementG2.argument())); assertFalse(originalStatementArgument.equals(effectiveContainerStatementG3.argument())); assertFalse(originalStatementArgument.equals(effectiveContainerStatementRoot.argument())); ContainerStatement originalContainerStatement = effectiveContainerStatementG1.getDeclared(); ContainerStatement inGrouping2ContainerStatement = effectiveContainerStatementG2.getDeclared(); ContainerStatement inGrouping3ContainerStatement = effectiveContainerStatementG3.getDeclared(); ContainerStatement inRootContainerStatement = effectiveContainerStatementRoot.getDeclared(); // check declared instances assertTrue(originalContainerStatement == inGrouping2ContainerStatement); assertTrue(originalContainerStatement == inGrouping3ContainerStatement); assertTrue(originalContainerStatement == inRootContainerStatement); }
Example #24
Source File: AbstractStringInstanceIdentifierCodec.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Override protected final String serializeImpl(final YangInstanceIdentifier data) { final StringBuilder sb = new StringBuilder(); DataSchemaContextNode<?> current = getDataContextTree().getRoot(); QNameModule lastModule = null; for (PathArgument arg : data.getPathArguments()) { current = current.getChild(arg); checkArgument(current != null, "Invalid input %s: schema for argument %s (after %s) not found", data, arg, sb); if (current.isMixin()) { /* * XML/YANG instance identifier does not have concept * of augmentation identifier, or list as whole which * identifies a mixin (same as the parent element), * so we can safely ignore it if it is part of path * (since child node) is identified in same fashion. */ continue; } final QName qname = arg.getNodeType(); sb.append('/'); appendQName(sb, qname, lastModule); lastModule = qname.getModule(); if (arg instanceof NodeIdentifierWithPredicates) { for (Entry<QName, Object> entry : ((NodeIdentifierWithPredicates) arg).entrySet()) { appendQName(sb.append('['), entry.getKey(), lastModule); sb.append("='").append(String.valueOf(entry.getValue())).append("']"); } } else if (arg instanceof NodeWithValue) { sb.append("[.='").append(((NodeWithValue<?>) arg).getValue()).append("']"); } } return sb.toString(); }
Example #25
Source File: SchemaContextFactoryConfiguration.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private SchemaContextFactoryConfiguration(final @NonNull SchemaSourceFilter filter, final @NonNull StatementParserMode statementParserMode, final @Nullable ImmutableSet<QName> supportedFeatures, final @Nullable ImmutableSetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) { this.filter = requireNonNull(filter); this.statementParserMode = requireNonNull(statementParserMode); this.supportedFeatures = supportedFeatures; this.modulesDeviatedByModules = modulesDeviatedByModules; }
Example #26
Source File: StatementContextBase.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Override public final Mutable<?, ?, ?> childCopyOf(final StmtContext<?, ?, ?> stmt, final CopyType type, final QNameModule targetModule) { checkEffectiveModelCompleted(stmt); checkArgument(stmt instanceof StatementContextBase, "Unsupported statement %s", stmt); return childCopyOf((StatementContextBase<?, ?, ?>) stmt, type, targetModule); }
Example #27
Source File: StringPatternCheckingCodecTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testStringPatternCheckingCodec() { final SchemaContext schemaContext = YangParserTestUtils.parseYangResource( "/string-pattern-checking-codec-test.yang"); assertNotNull(schemaContext); final QNameModule testModuleQName = QNameModule.create(URI.create("string-pattern-checking-codec-test")); final Module testModule = schemaContext.findModules("string-pattern-checking-codec-test").iterator().next(); final ContainerSchemaNode testContainer = (ContainerSchemaNode) testModule.findDataChildByName( QName.create(testModuleQName, "test-container")).get(); final LeafSchemaNode testLeaf = (LeafSchemaNode) testContainer.findDataChildByName( QName.create(testModuleQName, "string-leaf-with-valid-pattern")).get(); final StringCodec<String> codec = getCodec(testLeaf.getType(), StringCodec.class); assertNotNull(codec); assertEquals("ABCD", codec.serialize("ABCD")); assertEquals("ABCD", codec.deserialize("ABCD")); try { codec.deserialize("abcd"); fail("Exception should have been thrown."); } catch (final IllegalArgumentException ex) { LOG.debug("IllegalArgumentException was thrown as expected", ex); assertEquals("Value 'abcd' does not match regular expression '[A-Z]+'", ex.getMessage()); } }
Example #28
Source File: Bug4295Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Before public void init() { foo = QNameModule.create(URI.create("foo")); root = QName.create(foo, "root"); subRoot = QName.create(foo, "sub-root"); outerList = QName.create(foo, "outer-list"); innerList = QName.create(foo, "inner-list"); oid = QName.create(foo, "o-id"); iid = QName.create(foo, "i-id"); oleaf = QName.create(foo, "o"); ileaf = QName.create(foo, "i"); inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, YangParserTestUtils.parseYangResource("/bug-4295/foo.yang")); }
Example #29
Source File: ImmutableNormalizedNodeStreamWriterTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Before public void setup() throws URISyntaxException, ParseException { bazModule = QNameModule.create(new URI("baz-namespace"), Revision.of("1970-01-01")); 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"); myOrderedList = QName.create(bazModule, "my-ordered-list"); myKeyLeafInOrderedList = QName.create(bazModule, "my-key-leaf-in-ordered-list"); myLeafInOrderedList1 = QName.create(bazModule, "my-leaf-in-ordered-list-1"); myLeafInOrderedList2 = QName.create(bazModule, "my-leaf-in-ordered-list-2"); myUnkeyedList = QName.create(bazModule, "my-unkeyed-list"); myLeafInUnkeyedList = QName.create(bazModule, "my-leaf-in-unkeyed-list"); myLeaf1 = QName.create(bazModule, "my-leaf-1"); myLeafList = QName.create(bazModule, "my-leaf-list"); myOrderedLeafList = QName.create(bazModule, "my-ordered-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"); myAnyxml = QName.create(bazModule, "my-anyxml"); 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"); anyxmlDomSource = new DOMSource(); }
Example #30
Source File: Bug3874ExtensionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { SchemaContext context = reactor.newBuild() .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/bugs/bug3874/foo.yang"))) .addSource(YangStatementStreamSource.create( YangTextSchemaSource.forResource("/bugs/bug3874/yang-ext.yang"))) .buildEffective(); QNameModule foo = QNameModule.create(URI.create("foo")); QName myContainer2QName = QName.create(foo, "my-container-2"); QName myAnyXmlDataQName = QName.create(foo, "my-anyxml-data"); DataSchemaNode dataChildByName = context.findDataChildByName(myAnyXmlDataQName).get(); assertTrue(dataChildByName instanceof YangModeledAnyxmlSchemaNode); YangModeledAnyxmlSchemaNode yangModeledAnyXml = (YangModeledAnyxmlSchemaNode) dataChildByName; SchemaNode myContainer2 = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, myContainer2QName)); assertTrue(myContainer2 instanceof ContainerSchemaNode); assertEquals(myContainer2, yangModeledAnyXml.getSchemaOfAnyXmlData()); Collection<? extends UnknownSchemaNode> unknownSchemaNodes = yangModeledAnyXml.getUnknownSchemaNodes(); assertEquals(1, unknownSchemaNodes.size()); UnknownSchemaNode next = unknownSchemaNodes.iterator().next(); assertTrue(next instanceof AnyxmlSchemaLocationEffectiveStatementImpl); AnyxmlSchemaLocationEffectiveStatementImpl anyxmlSchemaLocationUnknownNode = (AnyxmlSchemaLocationEffectiveStatementImpl) next; assertEquals(OpenDaylightExtensionsStatements.ANYXML_SCHEMA_LOCATION.getStatementName(), anyxmlSchemaLocationUnknownNode.getNodeType()); assertEquals(OpenDaylightExtensionsStatements.ANYXML_SCHEMA_LOCATION.getStatementName(), anyxmlSchemaLocationUnknownNode.getQName()); }