--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, 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.rfc6643.model.api;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.util.Arrays;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * Maximum allowed access, as defined by
+ * <a href="https://tools.ietf.org/html/rfc2578#section-7.3">RFC2578 Section 7.3</a>.
+ */
+@Beta
+public enum MaxAccess {
+ /**
+ * Indicates the annotated object is an auxiliary object, as per
+ * <a href="https://tools.ietf.org/html/rfc2578#section-7.7">RFC2578 Section 7.7</a>.
+ */
+ NOT_ACCESSIBLE("not-accessible"),
+ /**
+ * Indicates the annotated object is accessible only for notifications.
+ */
+ ACCESSIBLE_FOR_NOTIFY("accessible-for-notify"),
+ /**
+ * Indicates that {@code read} access makes 'protocol sense', but {@code write} and {@code create} do not.
+ */
+ READ_ONLY("read-only"),
+ /**
+ * Indicates that {@code read} and {@code write} access make 'protocol sense', but {@code create} does not.
+ */
+ READ_WRITE("read-write"),
+ /**
+ * Indicates that {@code read}, {@code write} and {@code create} access make 'protocol sense'.
+ */
+ READ_CREATE("read-create");
+
+ private static final ImmutableMap<String, MaxAccess> VALUES =
+ Maps.uniqueIndex(Arrays.asList(MaxAccess.values()), MaxAccess::stringLiteral);
+
+ private @NonNull String str;
+
+ MaxAccess(final @NonNull String str) {
+ this.str = str;
+ }
+
+ public @NonNull String stringLiteral() {
+ return str;
+ }
+
+ public static @Nullable MaxAccess forStringLiteral(final @NonNull String str) {
+ return VALUES.get(requireNonNull(str));
+ }
+}
import com.google.common.annotations.Beta;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
@Beta
-public interface MaxAccessEffectiveStatement extends EffectiveStatement<String, MaxAccessStatement> {
-
+public interface MaxAccessEffectiveStatement extends EffectiveStatement<MaxAccess, MaxAccessStatement> {
+ @Override
+ default StatementDefinition statementDefinition() {
+ return IetfYangSmiv2ExtensionsMapping.MAX_ACCESS;
+ }
}
package org.opendaylight.yangtools.rfc6643.model.api;
import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
@Beta
public interface MaxAccessSchemaNode extends UnknownSchemaNode {
- String getArgument();
+ @NonNull MaxAccess getArgument();
}
package org.opendaylight.yangtools.rfc6643.model.api;
import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
@Beta
-public interface MaxAccessStatement extends UnknownStatement<String> {
-
+public interface MaxAccessStatement extends UnknownStatement<MaxAccess> {
+ @Override
+ default StatementDefinition statementDefinition() {
+ return IetfYangSmiv2ExtensionsMapping.MAX_ACCESS;
+ }
}
package org.opendaylight.yangtools.rfc6643.parser;
import java.util.Objects;
+import org.opendaylight.yangtools.rfc6643.model.api.MaxAccess;
import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessEffectiveStatement;
import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessSchemaNode;
import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessStatement;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class MaxAccessEffectiveStatementImpl extends UnknownEffectiveStatementBase<String, MaxAccessStatement>
+final class MaxAccessEffectiveStatementImpl extends UnknownEffectiveStatementBase<MaxAccess, MaxAccessStatement>
implements MaxAccessEffectiveStatement, MaxAccessSchemaNode {
private final SchemaPath path;
- MaxAccessEffectiveStatementImpl(final StmtContext<String, MaxAccessStatement, ?> ctx) {
+ MaxAccessEffectiveStatementImpl(final StmtContext<MaxAccess, MaxAccessStatement, ?> ctx) {
super(ctx);
path = ctx.getParentContext().getSchemaPath().get().createChild(getNodeType());
}
@Override
- public String getArgument() {
+ public MaxAccess getArgument() {
return argument();
}
*/
package org.opendaylight.yangtools.rfc6643.parser;
+import org.opendaylight.yangtools.rfc6643.model.api.MaxAccess;
import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class MaxAccessStatementImpl extends AbstractDeclaredStatement<String> implements MaxAccessStatement {
- MaxAccessStatementImpl(final StmtContext<String, MaxAccessStatement, ?> context) {
+final class MaxAccessStatementImpl extends AbstractDeclaredStatement<MaxAccess> implements MaxAccessStatement {
+ MaxAccessStatementImpl(final StmtContext<MaxAccess, MaxAccessStatement, ?> context) {
super(context);
}
}
import com.google.common.annotations.Beta;
import org.opendaylight.yangtools.rfc6643.model.api.IetfYangSmiv2ExtensionsMapping;
+import org.opendaylight.yangtools.rfc6643.model.api.MaxAccess;
import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessEffectiveStatement;
import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@Beta
public final class MaxAccessStatementSupport
- extends AbstractStatementSupport<String, MaxAccessStatement, MaxAccessEffectiveStatement> {
+ extends AbstractStatementSupport<MaxAccess, MaxAccessStatement, MaxAccessEffectiveStatement> {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
SubstatementValidator.builder(IetfYangSmiv2ExtensionsMapping.MAX_ACCESS).build();
private static final MaxAccessStatementSupport INSTANCE = new MaxAccessStatementSupport();
}
@Override
- public String parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return value;
+ public MaxAccess parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+ final MaxAccess val = MaxAccess.forStringLiteral(value);
+ if (val == null) {
+ throw new SourceException(ctx.getStatementSourceReference(), "Invalid max-access value '%s'", value);
+ }
+ return val;
+ }
+
+ @Override
+ public String internArgument(final String rawArgument) {
+ final MaxAccess val = MaxAccess.forStringLiteral(rawArgument);
+ return val == null ? rawArgument : val.stringLiteral();
}
@Override
}
@Override
- public MaxAccessStatement createDeclared(final StmtContext<String, MaxAccessStatement, ?> ctx) {
+ public MaxAccessStatement createDeclared(final StmtContext<MaxAccess, MaxAccessStatement, ?> ctx) {
return new MaxAccessStatementImpl(ctx);
}
@Override
public MaxAccessEffectiveStatement createEffective(
- final StmtContext<String, MaxAccessStatement, MaxAccessEffectiveStatement> ctx) {
+ final StmtContext<MaxAccess, MaxAccessStatement, MaxAccessEffectiveStatement> ctx) {
return new MaxAccessEffectiveStatementImpl(ctx);
}
}
\ No newline at end of file
import org.opendaylight.yangtools.rfc6643.model.api.AliasSchemaNode;
import org.opendaylight.yangtools.rfc6643.model.api.DefValSchemaNode;
import org.opendaylight.yangtools.rfc6643.model.api.ImpliedSchemaNode;
+import org.opendaylight.yangtools.rfc6643.model.api.MaxAccess;
import org.opendaylight.yangtools.rfc6643.model.api.MaxAccessSchemaNode;
import org.opendaylight.yangtools.rfc6643.model.api.ObjectIdentifier;
import org.opendaylight.yangtools.rfc6643.model.api.OidSchemaNode;
ifStackHigherLayer.getUnknownSchemaNodes().forEach(unknownSchemaNode -> {
if (unknownSchemaNode instanceof MaxAccessSchemaNode) {
final MaxAccessSchemaNode maxAccess = (MaxAccessSchemaNode) unknownSchemaNode;
- assertEquals(maxAccess.getArgument(), "not-accessible");
+ assertEquals(MaxAccess.NOT_ACCESSIBLE, maxAccess.getArgument());
}
});