import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.AbstractSchemaContextProvider;
// FIXME: 4.0.0 hide this class
-public final class LeafRefContext implements SchemaContextProvider {
+public final class LeafRefContext extends AbstractSchemaContextProvider {
private final QName currentNodeQName;
private final SchemaPath currentNodePath;
- private final SchemaContext schemaContext;
private final Module module;
private final LeafRefPath leafRefTargetPath;
private volatile LeafRefPath leafRefNodePath = null;
LeafRefContext(final LeafRefContextBuilder leafRefContextBuilder) {
+ super(leafRefContextBuilder.getSchemaContext());
this.currentNodeQName = leafRefContextBuilder.getCurrentNodeQName();
this.currentNodePath = leafRefContextBuilder.getCurrentNodePath();
- this.schemaContext = leafRefContextBuilder.getSchemaContext();
this.leafRefTargetPath = leafRefContextBuilder.getLeafRefTargetPath();
this.absoluteLeafRefTargetPath = leafRefContextBuilder.getAbsoluteLeafRefTargetPath();
this.leafRefTargetPathString = leafRefContextBuilder.getLeafRefTargetPathString();
return currentNodeQName;
}
- @Override
- public SchemaContext getSchemaContext() {
- return schemaContext;
- }
-
public LeafRefPath getAbsoluteLeafRefTargetPath() {
return absoluteLeafRefTargetPath;
}
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.util.AbstractSchemaContextProvider;
@Beta
@NonNullByDefault
-public class ImmutableNormalizedAnydata implements NormalizedAnydata {
- private final SchemaContext schemaContext;
+public class ImmutableNormalizedAnydata extends AbstractSchemaContextProvider implements NormalizedAnydata {
private final DataSchemaNode contextNode;
private final NormalizedNode<?, ?> data;
public ImmutableNormalizedAnydata(final SchemaContext schemaContext, final DataSchemaNode contextNode,
final NormalizedNode<?, ?> data) {
- this.schemaContext = requireNonNull(schemaContext);
+ super(schemaContext);
this.contextNode = requireNonNull(contextNode);
this.data = requireNonNull(data);
}
- @Override
- public final SchemaContext getSchemaContext() {
- return schemaContext;
- }
-
@Override
public final DataSchemaNode getContextNode() {
return contextNode;
}
@Override
- public final String toString() {
- return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
- }
-
protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
- return helper.add("schemaConteext", schemaContext).add("node", contextNode).add("data", data);
+ return super.addToStringAttributes(helper).add("node", contextNode).add("data", data);
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeAware;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.AbstractSchemaContextProvider;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param <T> Codec type
* @author Robert Varga
*/
-public abstract class AbstractCodecFactory<T extends TypeAwareCodec<?, ?, ?>> implements SchemaContextProvider {
+public abstract class AbstractCodecFactory<T extends TypeAwareCodec<?, ?, ?>> extends AbstractSchemaContextProvider {
private static final Logger LOG = LoggerFactory.getLogger(AbstractCodecFactory.class);
private final @NonNull CodecCache<T> cache;
- private final @NonNull SchemaContext schemaContext;
-
- protected AbstractCodecFactory(final SchemaContext schemaContext, final CodecCache<T> cache) {
- this.schemaContext = requireNonNull(schemaContext);
+ protected AbstractCodecFactory(final @NonNull SchemaContext schemaContext, final @NonNull CodecCache<T> cache) {
+ super(schemaContext);
this.cache = requireNonNull(cache);
}
- @Override
- public final SchemaContext getSchemaContext() {
- return schemaContext;
- }
-
public final <S extends TypeAware & SchemaNode> @NonNull T codecFor(final S schema) {
/*
* There are many trade-offs to be made here. We need the common case being as fast as possible while reusing
return createComplexUnion(schema, (UnionTypeDefinition) type);
} else if (type instanceof LeafrefTypeDefinition) {
final TypeDefinition<?> target = SchemaContextUtil.getBaseTypeForLeafRef((LeafrefTypeDefinition) type,
- schemaContext, schema);
+ getSchemaContext(), schema);
verifyNotNull(target, "Unable to find base type for leafref node %s type %s.", schema.getPath(),
target);
--- /dev/null
+/*
+ * Copyright (c) 2019 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.yang.model.util;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.Identifiable;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+@Beta
+@NonNullByDefault
+public abstract class AbstractIdentifiableSchemaContextProvider<T> extends AbstractSchemaContextProvider
+ implements Identifiable<T> {
+ private final @NonNull T identifier;
+
+ protected AbstractIdentifiableSchemaContextProvider(final SchemaContext schemaContext, final T identifier) {
+ super(schemaContext);
+ this.identifier = requireNonNull(identifier);
+ }
+
+ @Override
+ public final T getIdentifier() {
+ return identifier;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 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.yang.model.util;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+
+/**
+ * Utility superclass for classes returning a constant {@link SchemaContext}.
+ */
+@Beta
+@NonNullByDefault
+public abstract class AbstractSchemaContextProvider implements SchemaContextProvider {
+ private final SchemaContext schemaContext;
+
+ protected AbstractSchemaContextProvider(final SchemaContext schemaContext) {
+ this.schemaContext = requireNonNull(schemaContext);
+ }
+
+ @Override
+ // FIXME: remove @NonNull SchemaContextProvider's method has sane semantics
+ public final @NonNull SchemaContext getSchemaContext() {
+ return schemaContext;
+ }
+
+ @Override
+ public final String toString() {
+ return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
+ }
+
+ protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
+ return helper.add("schemaContext", schemaContext);
+ }
+}