/** * Creates a new CustomCrossSourceStatementReactorBuilder object initialized by specific version bundle. Statement * parser will support all versions defined in given version bundle. * * @param supportedVersions * bundle of supported verions */ CustomCrossSourceStatementReactorBuilder(final Set<YangVersion> supportedVersions) { reactorSupportBundles = ImmutableMap.<ModelProcessingPhase, StatementSupportBundle.Builder>builder() .put(ModelProcessingPhase.INIT, StatementSupportBundle.builder(supportedVersions)) .put(ModelProcessingPhase.SOURCE_PRE_LINKAGE, StatementSupportBundle.builder(supportedVersions)) .put(ModelProcessingPhase.SOURCE_LINKAGE, StatementSupportBundle.builder(supportedVersions)) .put(ModelProcessingPhase.STATEMENT_DEFINITION, StatementSupportBundle.builder(supportedVersions)) .put(ModelProcessingPhase.FULL_DECLARATION, StatementSupportBundle.builder(supportedVersions)) .put(ModelProcessingPhase.EFFECTIVE_MODEL, StatementSupportBundle.builder(supportedVersions)).build(); }
public StatementSupport<?, ?, ?> getStatementDefinition(final YangVersion version, final QName stmtName) { StatementSupport<?, ?, ?> result = getVersionSpecificStatementDefinition(version, stmtName); if (result == null) { result = getCommonStatementDefinition(stmtName); } return result; }
public CustomCrossSourceStatementReactorBuilder addAllSupports(final ModelProcessingPhase phase, final StatementSupportBundle stmtSupportBundle) { addAllCommonStatementSupports(phase, stmtSupportBundle.getCommonDefinitions().values()); addAllVersionSpecificSupports(phase, stmtSupportBundle.getAllVersionSpecificDefinitions()); addAllNamespaceSupports(phase, stmtSupportBundle.getNamespaceDefinitions().values()); return this; }
private QNameToStatementDefinition stmtDef() { // regular YANG statements and extension supports added final StatementSupportBundle supportsForPhase = currentContext.getSupportsForPhase(inProgressPhase); qnameToStmtDefMap.putAll(supportsForPhase.getCommonDefinitions()); qnameToStmtDefMap.putAll(supportsForPhase.getDefinitionsSpecificForVersion(getRootVersion())); // No further actions needed if (inProgressPhase != ModelProcessingPhase.FULL_DECLARATION) { return qnameToStmtDefMap; } // We need to any and all extension statements which have been declared in the context final Map<QName, StatementSupport<?, ?, ?>> extensions = currentContext.getAllFromNamespace( StatementDefinitionNamespace.class); if (extensions != null) { extensions.forEach((qname, support) -> { final StatementSupport<?, ?, ?> existing = qnameToStmtDefMap.putIfAbsent(qname, support); if (existing != null) { LOG.debug("Source {} already defines statement {} as {}", source, qname, existing); } else { LOG.debug("Source {} defined statement {} as {}", source, qname, support); } }); } return qnameToStmtDefMap; }
public static Builder derivedFrom(final StatementSupportBundle parent) { return new Builder(parent.getSupportedVersions(), parent); }
@Override @SuppressWarnings("unchecked") public <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour( final Class<N> namespace) { final NamespaceBehaviour<?, ?, ?> potential = namespaceDefinitions.get(namespace); if (potential != null) { checkState(namespace.equals(potential.getIdentifier())); // Safe cast, previous checkState checks equivalence of key from which type argument are derived return (NamespaceBehaviour<K, V, N>) potential; } if (parent != null) { return parent.getNamespaceBehaviour(namespace); } return null; }
private StatementSupport<?, ?, ?> getCommonStatementDefinition(final QName stmtName) { final StatementSupport<?, ?, ?> potential = commonDefinitions.get(stmtName); if (potential != null) { return potential; } if (parent != null) { return parent.getCommonStatementDefinition(stmtName); } return null; }
@Override public StatementSupportBundle build() { Preconditions.checkState(parent != null, "Parent must not be null"); return new StatementSupportBundle(parent, supportedVersions, ImmutableMap.copyOf(commonStatements), ImmutableMap.copyOf(namespaces), ImmutableTable.copyOf(versionSpecificStatements)); }
StatementDefinitionContext<?, ?, ?> getStatementDefinition(final YangVersion version, final QName name) { StatementDefinitionContext<?, ?, ?> potential = definitions.get(version, name); if (potential == null) { final StatementSupport<?, ?, ?> potentialRaw = supports.get(currentPhase).getStatementDefinition(version, name); if (potentialRaw != null) { potential = new StatementDefinitionContext<>(potentialRaw); definitions.put(version, name, potential); } } return potential; }
BuildGlobalContext(final ImmutableMap<ModelProcessingPhase, StatementSupportBundle> supports, final ImmutableMap<ValidationBundleType, Collection<?>> supportedValidation, final StatementParserMode statementParserMode) { this.supports = requireNonNull(supports, "BuildGlobalContext#supports cannot be null"); switch (statementParserMode) { case DEFAULT_MODE: enabledSemanticVersions = false; break; case SEMVER_MODE: enabledSemanticVersions = true; break; default: throw new IllegalArgumentException("Unhandled parser mode " + statementParserMode); } for (final Entry<ValidationBundleType, Collection<?>> validationBundle : supportedValidation.entrySet()) { addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue()); } this.supportedVersions = ImmutableSet.copyOf(supports.get(ModelProcessingPhase.INIT).getSupportedVersions()); }
@Override public <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> getNamespaceBehaviour( final Class<N> type) { NamespaceBehaviourWithListeners<?, ?, ?> potential = supportedNamespaces.get(type); if (potential == null) { final NamespaceBehaviour<K, V, N> potentialRaw = supports.get(currentPhase).getNamespaceBehaviour(type); if (potentialRaw != null) { potential = createNamespaceContext(potentialRaw); supportedNamespaces.put(type, potential); } else { throw new NamespaceNotAvailableException("Namespace " + type + " is not available in phase " + currentPhase); } } Verify.verify(type.equals(potential.getIdentifier())); /* * Safe cast, previous checkState checks equivalence of key from which * type argument are derived */ return (NamespaceBehaviourWithListeners<K, V, N>) potential; }