--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.api.meta;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ForwardingObject;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Utility forwarding implementation of {@link EffectiveStatement} contract. This class is useful for implementing
+ * wrapped statements.
+ *
+ * @author Robert Varga
+ *
+ * @param <A> Argument type
+ * @param <D> Declared Statement representation
+ * @param <E> Effective Statement representation
+ */
+@Beta
+public abstract class ForwardingEffectiveStatement<A, D extends DeclaredStatement<A>,
+ E extends EffectiveStatement<A, D>> extends ForwardingObject implements EffectiveStatement<A, D> {
+
+ @Override
+ protected abstract E delegate();
+
+
+ @Override
+ public D getDeclared() {
+ return delegate().getDeclared();
+ }
+
+ @Override
+ public <K, V, N extends IdentifierNamespace<K, V>> V get(final Class<N> namespace, final K identifier) {
+ return delegate().get(namespace, identifier);
+ }
+
+ @Override
+ public <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAll(final Class<N> namespace) {
+ return delegate().getAll(namespace);
+ }
+
+ @Override
+ public Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return delegate().effectiveSubstatements();
+ }
+
+ @Override
+ public StatementDefinition statementDefinition() {
+ return delegate().statementDefinition();
+ }
+
+ @Override
+ public A argument() {
+ return delegate().argument();
+ }
+
+ @Override
+ public StatementSource getStatementSource() {
+ return delegate().getStatementSource();
+ }
+}
return this;
}
+ public CustomCrossSourceStatementReactorBuilder overrideStatementSupport(final ModelProcessingPhase phase,
+ final StatementSupport<?, ?, ?> stmtSupport) {
+ reactorSupportBundles.get(phase).overrideSupport(stmtSupport);
+ return this;
+ }
+
public CustomCrossSourceStatementReactorBuilder addNamespaceSupport(final ModelProcessingPhase phase,
final NamespaceBehaviour<?, ?, ?> namespaceSupport) {
reactorSupportBundles.get(phase).addSupport(namespaceSupport);
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.spi.meta;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ForwardingObject;
+import java.util.Optional;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+
+/**
+ * Utility forwarding implementation of {@link StatementSupport} contract. This class is useful for implementing
+ * wrapped statements.
+ *
+ * @author Robert Varga
+ *
+ * @param <A> Argument type
+ * @param <D> Declared Statement representation
+ * @param <E> Effective Statement representation
+ */
+@Beta
+public abstract class ForwardingStatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+ extends ForwardingObject implements StatementSupport<A, D, E> {
+
+ @Override
+ protected abstract StatementSupport<A, D, E> delegate();
+
+ @Override
+ public QName getStatementName() {
+ return delegate().getStatementName();
+ }
+
+ @Override
+ public QName getArgumentName() {
+ return delegate().getArgumentName();
+ }
+
+ @Override
+ public Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
+ return delegate().getDeclaredRepresentationClass();
+ }
+
+ @Override
+ public Class<? extends EffectiveStatement<?, ?>> getEffectiveRepresentationClass() {
+ return delegate().getEffectiveRepresentationClass();
+ }
+
+ @Override
+ public boolean isArgumentYinElement() {
+ return delegate().isArgumentYinElement();
+ }
+
+ @Override
+ public D createDeclared(final StmtContext<A, D, ?> ctx) {
+ return delegate().createDeclared(ctx);
+ }
+
+ @Override
+ public E createEffective(final StmtContext<A, D, E> ctx) {
+ return delegate().createEffective(ctx);
+ }
+
+ @Override
+ public StatementDefinition getPublicView() {
+ return delegate().getPublicView();
+ }
+
+ @Override
+ public A parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+ return delegate().parseArgumentValue(ctx, value);
+ }
+
+ @Override
+ public void onStatementAdded(final Mutable<A, D, E> stmt) {
+ delegate().onStatementAdded(stmt);
+ }
+
+ @Override
+ public Optional<StatementSupport<?, ?, ?>> getImplicitParentFor(final StatementDefinition stmtDef) {
+ return delegate().getImplicitParentFor(stmtDef);
+ }
+
+ @Override
+ public void onPreLinkageDeclared(final Mutable<A, D, E> stmt) {
+ delegate().onPreLinkageDeclared(stmt);
+ }
+
+ @Override
+ public void onLinkageDeclared(final Mutable<A, D, E> stmt) {
+ delegate().onLinkageDeclared(stmt);
+ }
+
+ @Override
+ public void onStatementDefinitionDeclared(final Mutable<A, D, E> stmt) {
+ delegate().onStatementDefinitionDeclared(stmt);
+ }
+
+ @Override
+ public void onFullDefinitionDeclared(final Mutable<A, D, E> stmt) {
+ delegate().onFullDefinitionDeclared(stmt);
+ }
+
+ @Override
+ public boolean hasArgumentSpecificSupports() {
+ return delegate().hasArgumentSpecificSupports();
+ }
+
+ @Override
+ public StatementSupport<?, ?, ?> getSupportSpecificForArgument(final String argument) {
+ return delegate().getSupportSpecificForArgument(argument);
+ }
+}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class StatementSupportBundle implements Immutable, NamespaceBehaviour.Registry {
}
public static class Builder implements org.opendaylight.yangtools.concepts.Builder<StatementSupportBundle> {
+ private static final Logger LOG = LoggerFactory.getLogger(Builder.class);
+
private final Map<QName, StatementSupport<?, ?, ?>> commonStatements = new HashMap<>();
private final Table<YangVersion, QName, StatementSupport<?, ?, ?>> versionSpecificStatements = HashBasedTable
.create();
this.supportedVersions = ImmutableSet.copyOf(supportedVersions);
}
- public Builder addSupport(final StatementSupport<?, ?, ?> definition) {
- final QName identifier = definition.getStatementName();
+ public Builder addSupport(final StatementSupport<?, ?, ?> support) {
+ final QName identifier = support.getStatementName();
+ checkNoParentDefinition(identifier);
+
checkState(!commonStatements.containsKey(identifier),
"Statement %s already defined in common statement bundle.", identifier);
- checkState(parent.getCommonStatementDefinition(identifier) == null,
- "Statement %s already defined.", identifier);
- commonStatements.put(identifier, definition);
+ commonStatements.put(identifier, support);
return this;
}
"Statement %s already defined in common statement bundle.", identifier);
checkState(!versionSpecificStatements.contains(version, identifier),
"Statement %s already defined for version %s.", identifier, version);
- checkState(parent.getCommonStatementDefinition(identifier) == null,
- "Statement %s already defined in parent's common statement bundle.", identifier);
+ checkNoParentDefinition(identifier);
checkState(parent.getVersionSpecificStatementDefinition(version, identifier) == null,
"Statement %s already defined for version %s in parent's statement bundle.", identifier, version);
versionSpecificStatements.put(version, identifier, definition);
return this;
}
+ public Builder overrideSupport(final StatementSupport<?, ?, ?> support) {
+ final QName identifier = support.getStatementName();
+ checkNoParentDefinition(identifier);
+
+ final StatementSupport<?, ?, ?> previousSupport = commonStatements.replace(identifier, support);
+ checkState(previousSupport != null, "Statement %s was not previously defined", identifier);
+ LOG.debug("Changed statement {} support from {} to {}", identifier, previousSupport, support);
+ return this;
+ }
+
@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));
}
+
+ private void checkNoParentDefinition(final QName identifier) {
+ checkState(parent.getCommonStatementDefinition(identifier) == null,
+ "Statement %s is defined in parent's common statement bundle", identifier);
+ }
}
}