Fix checkstyle issues and activate enforcement.
Change-Id: I5ef078ba907284d5885521971cb0391a28fa2e57
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
- <!--
- Maven Site Configuration
+ <!--
+ Maven Site Configuration
- The following configuration is necessary for maven-site-plugin to
- correctly identify the correct deployment path for OpenDaylight Maven
- sites.
- -->
- <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+ The following configuration is necessary for maven-site-plugin to
+ correctly identify the correct deployment path for OpenDaylight Maven
+ sites.
+ -->
+ <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
- <distributionManagement>
- <site>
- <id>opendaylight-site</id>
- <url>${nexus.site.url}/${project.artifactId}/</url>
- </site>
- </distributionManagement>
+ <distributionManagement>
+ <site>
+ <id>opendaylight-site</id>
+ <url>${nexus.site.url}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
</project>
import org.slf4j.LoggerFactory;
/**
- * Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry
+ * Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry.
*/
final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public Collection<ObjectRegistration<YangModuleInfo>> addingBundle(final Bundle bundle, final BundleEvent event) {
final URL resource = bundle.getEntry(YANG_MODLE_BINDING_PROVIDER_SERVICE);
if (resource == null) {
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public void removedBundle(final Bundle bundle, final BundleEvent event,
final Collection<ObjectRegistration<YangModuleInfo>> regs) {
if (regs == null) {
this.runtimeContext = checkNotNull(runtimeContext);
}
+ @SuppressWarnings("checkstyle:illegalCatch")
synchronized void updateService() {
final SchemaContext context;
try {
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public void close() throws Exception {
try {
inner.close();
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
- <!--
- Maven Site Configuration
+ <!--
+ Maven Site Configuration
- The following configuration is necessary for maven-site-plugin to
- correctly identify the correct deployment path for OpenDaylight Maven
- sites.
- -->
- <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+ The following configuration is necessary for maven-site-plugin to
+ correctly identify the correct deployment path for OpenDaylight Maven
+ sites.
+ -->
+ <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
- <distributionManagement>
- <site>
- <id>opendaylight-site</id>
- <url>${nexus.site.url}/${project.artifactId}/</url>
- </site>
- </distributionManagement>
+ <distributionManagement>
+ <site>
+ <id>opendaylight-site</id>
+ <url>${nexus.site.url}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
</project>
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
/**
- * Navigable tree representing hierarchy of Binding to Normalized Node codecs
- *
- * This navigable tree is associated to conrete set of YANG models, represented by SchemaContext and
- * provides access to subtree specific serialization context.
- *
- * TODO: Add more detailed documentation
- **/
+ * Navigable tree representing hierarchy of Binding to Normalized Node codecs. This navigable tree is associated to
+ * a concrete set of YANG models, represented by SchemaContext and provides access to subtree specific serialization
+ * context.
+ */
+// TODO: Add more detailed documentation
public interface BindingCodecTree {
@Nullable
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
/**
- * Subtree codec specific to model subtree between Java Binding and
- * NormalizedNode.
+ * Subtree codec specific to model subtree between Java Binding and NormalizedNode.
*/
@Beta
public interface BindingCodecTreeNode<T extends DataObject> extends BindingNormalizedNodeCodec<T> {
/**
- * Returns binding class of interface which represents API of current
- * schema node.
- *
- * The result is same as invoking {@link DataObject#getImplementedInterface()}
- * on instance of data.
+ * Returns binding class of interface which represents API of current schema node. The result is same as invoking
+ * {@link DataObject#getImplementedInterface()} on instance of data.
*
* @return interface which defines API of binding representation of data.
*/
Class<T> getBindingClass();
/**
- * Returns child context as if it was walked by
- * {@link BindingStreamEventWriter}. This means that to enter case, one must
- * issue getChild(ChoiceClass).getChild(CaseClass).
+ * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case,
+ * one must issue getChild(ChoiceClass).getChild(CaseClass).
*
* @param childClass Child class by Biding Stream navigation
* @return Context of child
<E extends DataObject> BindingCodecTreeNode<E> streamChild(@Nonnull Class<E> childClass);
/**
- * Returns child context as if it was walked by
- * {@link BindingStreamEventWriter}. This means that to enter case, one must
- * issue getChild(ChoiceClass).getChild(CaseClass).
+ * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case,
+ * one must issue getChild(ChoiceClass).getChild(CaseClass).
*
- * This method differs from {@link #streamChild(Class)}, that is less
- * stricter for interfaces representing augmentation and cases, that
- * may return {@link BindingCodecTreeNode} even if augmentation interface
- * containing same data was supplied and does not represent augmentation
- * of this node.
+ * <p>
+ * This method differs from {@link #streamChild(Class)}, that is less strict for interfaces representing
+ * augmentation and cases, that may return {@link BindingCodecTreeNode} even if augmentation interface containing
+ * same data was supplied and does not represent augmentation of this node.
*
* @param childClass
* @return Context of child or Optional absent is supplied class is not
* applicable in context.
*/
- <E extends DataObject> Optional<? extends BindingCodecTreeNode<E>> possibleStreamChild(@Nonnull Class<E> childClass);
+ <E extends DataObject> Optional<? extends BindingCodecTreeNode<E>> possibleStreamChild(
+ @Nonnull Class<E> childClass);
/**
- * Returns nested node context using supplied YANG Instance Identifier
+ * Returns nested node context using supplied YANG Instance Identifier.
*
* @param child
* Yang Instance Identifier Argument
BindingCodecTreeNode<?> yangPathArgumentChild(@Nonnull YangInstanceIdentifier.PathArgument child);
/**
- * Returns nested node context using supplied Binding Instance Identifier
- * and adds YANG instance identifiers to supplied list.
+ * Returns nested node context using supplied Binding Instance Identifier and adds YANG instance identifiers to
+ * the supplied list.
*
* @param arg
* Binding Instance Identifier Argument
@Nullable List<YangInstanceIdentifier.PathArgument> builder);
/**
- * Returns codec which uses caches serialization / deserialization results
+ * Returns codec which uses caches serialization / deserialization results.
*
+ * <p>
* Caching may introduce performance penalty to serialization / deserialization
* but may decrease use of heap for repetitive objects.
*
- *
* @param cacheSpecifier Set of objects, for which cache may be in place
* @return Codec whihc uses cache for serialization / deserialization.
*/
* @throws IllegalArgumentException If supplied {@code arg} is not valid.
*/
@Beta
- @Nullable InstanceIdentifier.PathArgument deserializePathArgument(@Nullable YangInstanceIdentifier.PathArgument arg);
+ @Nullable InstanceIdentifier.PathArgument deserializePathArgument(
+ @Nullable YangInstanceIdentifier.PathArgument arg);
Object getSchema();
}
import org.opendaylight.yangtools.yang.binding.DataObject;
/**
- * Caching variant of Binding to Normalized Node codec.
- *
- * Caching may introduce performance penalty to serialization / deserialization
- * but may decrease use of heap for repetitive objects.
+ * Caching variant of Binding to Normalized Node codec. Caching may introduce performance penalty to serialization and
+ * deserialization but may decrease use of heap for repetitive objects.
*
* @param <T> Binding representtion of data
*/
public interface BindingNormalizedNodeCachingCodec<T extends DataObject> extends BindingNormalizedNodeCodec<T>,
AutoCloseable {
/**
- * Invoking close will invalidate this codec and any of its child
- * codecs and will invalidate cache.
- *
- * Any subsequent calls to this codec will fail with {@link IllegalStateException}
- * thrown.
+ * Invoking close will invalidate this codec and any of its child codecs and will invalidate cache. Any subsequent
+ * calls to this codec will fail with {@link IllegalStateException} thrown.
*/
@Override
void close();
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
/**
- * Factory for {@link BindingStreamEventWriter}, which provides stream writers
- * which translates data and delegates calls to {@link NormalizedNodeStreamWriter}.
+ * Factory for {@link BindingStreamEventWriter}, which provides stream writers which translates data and delegates
+ * calls to {@link NormalizedNodeStreamWriter}.
*/
public interface BindingNormalizedNodeWriterFactory {
/**
- * Creates a {@link BindingStreamEventWriter} for data tree path which will
- * translate to NormalizedNode model and invoke proper events on supplied
- * {@link NormalizedNodeStreamWriter}.
+ * Creates a {@link BindingStreamEventWriter} for data tree path which will translate to NormalizedNode model
+ * and invoke proper events on supplied {@link NormalizedNodeStreamWriter}.
+ *
* <p>
- * Also provides translation of supplied Instance Identifier to
- * {@link YangInstanceIdentifier} so client code, does not need to translate
- * that separately.
+ * Also provides translation of supplied Instance Identifier to {@link YangInstanceIdentifier} so client code, does
+ * not need to translate that separately.
+ *
* <p>
* If {@link YangInstanceIdentifier} is not needed, please use
- * {@link #newWriter(InstanceIdentifier, NormalizedNodeStreamWriter)}
- * method to conserve resources.
+ * {@link #newWriter(InstanceIdentifier, NormalizedNodeStreamWriter)} method to conserve resources.
*
* @param path
* Binding Path in conceptual data tree, for which writer should
@Nonnull InstanceIdentifier<?> path, @Nonnull NormalizedNodeStreamWriter domWriter);
/**
- * Creates a {@link BindingStreamEventWriter} for data tree path which will
- * translate to NormalizedNode model and invoke proper events on supplied
- * {@link NormalizedNodeStreamWriter}.
- * <p>
+ * Creates a {@link BindingStreamEventWriter} for data tree path which will translate to NormalizedNode model
+ * and invoke proper events on supplied {@link NormalizedNodeStreamWriter}.
*
- * This variation does not provide YANG instance identifier and is useful
- * for use-cases, where {@link InstanceIdentifier} translation is done
- * in other way, or YANG instance identifier is unnecessary (e.g. notifications, RPCs).
+ * <p>
+ * This variant does not provide YANG instance identifier and is useful for use-cases, where
+ * {@link InstanceIdentifier} translation is done in other way, or YANG instance identifier is unnecessary
+ * (e.g. notifications, RPCs).
*
* @param path Binding Path in conceptual data tree, for which writer should
* be instantiated
@Nonnull NormalizedNodeStreamWriter domWriter);
/**
- * Creates a {@link BindingStreamEventWriter} for RPC data which will
- * translate to NormalizedNode model and invoke proper events on supplied
- * {@link NormalizedNodeStreamWriter}.
+ * Creates a {@link BindingStreamEventWriter} for RPC data which will translate to NormalizedNode model and invoke
+ * proper events on supplied {@link NormalizedNodeStreamWriter}.
*
* @param rpcInputOrOutput Binding class representing RPC input or output,
* for which writer should be instantiated
@Nonnull NormalizedNodeStreamWriter domWriter);
/**
- * Creates a {@link BindingStreamEventWriter} for notification which will
- * translate to NormalizedNode model and invoke proper events on supplied
- * {@link NormalizedNodeStreamWriter}.
+ * Creates a {@link BindingStreamEventWriter} for notification which will translate to NormalizedNode model
+ * and invoke proper events on supplied {@link NormalizedNodeStreamWriter}.
*
* @param notification Binding class representing notification,
* for which writer should be instantiated
*/
abstract class AbstractGenerator {
/**
- * Ensure that the serializer class for specified class is loaded
- * and return its name.
+ * Ensure that the serializer class for specified class is loaded and return its name.
*
* @param cls Data object class
* @return Serializer class name
*/
- protected abstract String loadSerializerFor(final Class<?> cls);
+ protected abstract String loadSerializerFor(Class<?> cls);
}
\ No newline at end of file
* fix the static declared fields to final once we initialize them. If we
* cannot get access, that's fine, too.
*/
- Field f = null;
+ Field field = null;
try {
- f = Field.class.getDeclaredField("modifiers");
- f.setAccessible(true);
+ field = Field.class.getDeclaredField("modifiers");
+ field.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
LOG.warn("Could not get Field modifiers field, serializers run at decreased efficiency", e);
}
- FIELD_MODIFIERS = f;
+ FIELD_MODIFIERS = field;
}
protected AbstractStreamWriterGenerator(final JavassistUtils utils) {
return implementations.getUnchecked(cls).getClass().getName();
}
- private final class SerializerImplementationLoader extends CacheLoader<Class<?>, DataObjectSerializerImplementation> {
+ private final class SerializerImplementationLoader
+ extends CacheLoader<Class<?>, DataObjectSerializerImplementation> {
private static final String GETINSTANCE_METHOD_NAME = "getInstance";
private static final String SERIALIZER_SUFFIX = "$StreamWriter";
@SuppressWarnings("unchecked")
public DataObjectSerializerImplementation load(final Class<?> type) throws Exception {
Preconditions.checkArgument(BindingReflections.isBindingClass(type));
- Preconditions.checkArgument(DataContainer.class.isAssignableFrom(type),"DataContainer is not assingnable from %s from classloader %s.",type,type.getClassLoader());
+ Preconditions.checkArgument(DataContainer.class.isAssignableFrom(type),
+ "DataContainer is not assingnable from %s from classloader %s.", type, type.getClassLoader());
final String serializerName = getSerializerName(type);
}
private Class<? extends DataObjectSerializerImplementation> generateSerializer(final Class<?> type,
- final String serializerName) throws CannotCompileException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException {
+ final String serializerName) throws CannotCompileException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException,
+ NoSuchFieldException {
final DataObjectSerializerSource source = generateEmitterSource(type, serializerName);
final CtClass poolClass = generateEmitter0(type, source, serializerName);
@SuppressWarnings("unchecked")
- final Class<? extends DataObjectSerializerImplementation> cls = poolClass.toClass(type.getClassLoader(), type.getProtectionDomain());
+ final Class<? extends DataObjectSerializerImplementation> cls = poolClass.toClass(type.getClassLoader(),
+ type.getProtectionDomain());
/*
* Due to OSGi class loader rules we cannot initialize the fields during
final DataObjectSerializerSource source;
if (schema instanceof ContainerSchemaNode) {
source = generateContainerSerializer(generatedType, (ContainerSchemaNode) schema);
- } else if (schema instanceof ListSchemaNode){
+ } else if (schema instanceof ListSchemaNode) {
final ListSchemaNode casted = (ListSchemaNode) schema;
if (casted.getKeyDefinition().isEmpty()) {
source = generateUnkeyedListEntrySerializer(generatedType, casted);
} else {
source = generateMapEntrySerializer(generatedType, casted);
}
- } else if(schema instanceof AugmentationSchema) {
+ } else if (schema instanceof AugmentationSchema) {
source = generateSerializer(generatedType,(AugmentationSchema) schema);
- } else if(schema instanceof ChoiceCaseNode) {
+ } else if (schema instanceof ChoiceCaseNode) {
source = generateCaseSerializer(generatedType,(ChoiceCaseNode) schema);
- } else if(schema instanceof NotificationDefinition) {
+ } else if (schema instanceof NotificationDefinition) {
source = generateNotificationSerializer(generatedType,(NotificationDefinition) schema);
} else {
throw new UnsupportedOperationException("Schema type " + schema.getClass() + " is not supported");
return source;
}
- private CtClass generateEmitter0(final Class<?> type, final DataObjectSerializerSource source, final String serializerName) {
+ private CtClass generateEmitter0(final Class<?> type, final DataObjectSerializerSource source,
+ final String serializerName) {
final CtClass product;
/*
(Supplier<String>) () -> source.getSerializerBody().toString());
try {
- product = javassist.instantiatePrototype(DataObjectSerializerPrototype.class.getName(), serializerName, cls -> {
- // Generate any static fields
- for (final StaticConstantDefinition def : source.getStaticConstants()) {
- final CtField field = new CtField(javassist.asCtClass(def.getType()), def.getName(), cls);
- field.setModifiers(Modifier.PRIVATE + Modifier.STATIC);
- cls.addField(field);
- }
-
- // Replace serialize() -- may reference static fields
- final CtMethod serializeTo = cls.getDeclaredMethod(SERIALIZE_METHOD_NAME, serializeArguments);
- serializeTo.setBody(body);
-
- // The prototype is not visible, so we need to take care of that
- cls.setModifiers(Modifier.setPublic(cls.getModifiers()));
- });
+ product = javassist.instantiatePrototype(DataObjectSerializerPrototype.class.getName(), serializerName,
+ cls -> {
+ // Generate any static fields
+ for (final StaticConstantDefinition def : source.getStaticConstants()) {
+ final CtField field = new CtField(javassist.asCtClass(def.getType()), def.getName(), cls);
+ field.setModifiers(Modifier.PRIVATE + Modifier.STATIC);
+ cls.addField(field);
+ }
+
+ // Replace serialize() -- may reference static fields
+ final CtMethod serializeTo = cls.getDeclaredMethod(SERIALIZE_METHOD_NAME, serializeArguments);
+ serializeTo.setBody(body);
+
+ // The prototype is not visible, so we need to take care of that
+ cls.setModifiers(Modifier.setPublic(cls.getModifiers()));
+ });
} catch (final NotFoundException e) {
LOG.error("Failed to instatiate serializer {}", source, e);
throw new LinkageError("Unexpected instantation problem: serializer prototype not found", e);
}
/**
- * Generates serializer source code for supplied container node,
- * which will read supplied binding type and invoke proper methods
- * on supplied {@link BindingStreamEventWriter}.
+ * Generates serializer source code for supplied container node, which will read supplied binding type and invoke
+ * proper methods on supplied {@link BindingStreamEventWriter}.
+ *
* <p>
- * Implementation is required to recursively invoke events
- * for all reachable binding objects.
+ * Implementation is required to recursively invoke events for all reachable binding objects.
*
* @param type Binding type of container
* @param node Schema of container
* @return Source for container node writer
*/
- protected abstract DataObjectSerializerSource generateContainerSerializer(GeneratedType type, ContainerSchemaNode node);
+ protected abstract DataObjectSerializerSource generateContainerSerializer(GeneratedType type,
+ ContainerSchemaNode node);
/**
- * Generates serializer source for supplied case node,
- * which will read supplied binding type and invoke proper methods
- * on supplied {@link BindingStreamEventWriter}.
+ * Generates serializer source for supplied case node, which will read supplied binding type and invoke proper
+ * methods on supplied {@link BindingStreamEventWriter}.
+ *
* <p>
- * Implementation is required to recursively invoke events
- * for all reachable binding objects.
+ * Implementation is required to recursively invoke events for all reachable binding objects.
*
* @param type Binding type of case
* @param node Schema of case
protected abstract DataObjectSerializerSource generateCaseSerializer(GeneratedType type, ChoiceCaseNode node);
/**
- * Generates serializer source for supplied list node,
- * which will read supplied binding type and invoke proper methods
- * on supplied {@link BindingStreamEventWriter}.
+ * Generates serializer source for supplied list node, which will read supplied binding type and invoke proper
+ * methods on supplied {@link BindingStreamEventWriter}.
+ *
* <p>
- * Implementation is required to recursively invoke events
- * for all reachable binding objects.
+ * Implementation is required to recursively invoke events for all reachable binding objects.
*
* @param type Binding type of list
* @param node Schema of list
protected abstract DataObjectSerializerSource generateMapEntrySerializer(GeneratedType type, ListSchemaNode node);
/**
- * Generates serializer source for supplied list node,
- * which will read supplied binding type and invoke proper methods
- * on supplied {@link BindingStreamEventWriter}.
+ * Generates serializer source for supplied list node, which will read supplied binding type and invoke proper
+ * methods on supplied {@link BindingStreamEventWriter}.
+ *
* <p>
- * Implementation is required to recursively invoke events
- * for all reachable binding objects.
+ * Implementation is required to recursively invoke events for all reachable binding objects.
*
* @param type Binding type of list
* @param node Schema of list
* @return Source for list node writer
*/
- protected abstract DataObjectSerializerSource generateUnkeyedListEntrySerializer(GeneratedType type, ListSchemaNode node);
+ protected abstract DataObjectSerializerSource generateUnkeyedListEntrySerializer(GeneratedType type,
+ ListSchemaNode node);
/**
- * Generates serializer source for supplied augmentation node,
- * which will read supplied binding type and invoke proper methods
- * on supplied {@link BindingStreamEventWriter}.
+ * Generates serializer source for supplied augmentation node, which will read supplied binding type and invoke
+ * proper methods on supplied {@link BindingStreamEventWriter}.
+ *
* <p>
- * Implementation is required to recursively invoke events
- * for all reachable binding objects.
+ * Implementation is required to recursively invoke events for all reachable binding objects.
*
* @param type Binding type of augmentation
* @param schema Schema of augmentation
protected abstract DataObjectSerializerSource generateSerializer(GeneratedType type, AugmentationSchema schema);
/**
- * Generates serializer source for notification node,
- * which will read supplied binding type and invoke proper methods
- * on supplied {@link BindingStreamEventWriter}.
+ * Generates serializer source for notification node, which will read supplied binding type and invoke proper
+ * methods on supplied {@link BindingStreamEventWriter}.
+ *
* <p>
- * Implementation is required to recursively invoke events
- * for all reachable binding objects.
+ * Implementation is required to recursively invoke events for all reachable binding objects.
*
* @param type Binding type of notification
* @param node Schema of notification
* @return Source for notification node writer
*/
- protected abstract DataObjectSerializerSource generateNotificationSerializer(GeneratedType type, NotificationDefinition node);
-
+ protected abstract DataObjectSerializerSource generateNotificationSerializer(GeneratedType type,
+ NotificationDefinition node);
}
abstract class AugmentableDataNodeContainerEmitterSource extends DataNodeContainerSerializerSource {
private static final String AUGMENTABLE_SERIALIZER = "AUGMENTABLE_SERIALIZER";
- public AugmentableDataNodeContainerEmitterSource(final AbstractStreamWriterGenerator generator, final GeneratedType type, final DataNodeContainer node) {
+ AugmentableDataNodeContainerEmitterSource(final AbstractStreamWriterGenerator generator, final GeneratedType type,
+ final DataNodeContainer node) {
super(generator, type, node);
/*
- * Eventhough intuition says the serializer could reference the generator directly,
- * that is not true in OSGi environment -- so we need to resolve the reference first
- * and inject it as a static constant.
+ * Eventhough intuition says the serializer could reference the generator directly, that is not true in OSGi
+ * environment -- so we need to resolve the reference first and inject it as a static constant.
*/
- staticConstant(AUGMENTABLE_SERIALIZER, DataObjectSerializerImplementation.class, StreamWriterGenerator.AUGMENTABLE);
+ staticConstant(AUGMENTABLE_SERIALIZER, DataObjectSerializerImplementation.class,
+ StreamWriterGenerator.AUGMENTABLE);
}
@Override
- protected void emitAfterBody(final StringBuilder b) {
- b.append(statement(invoke(AUGMENTABLE_SERIALIZER, "serialize", REGISTRY, INPUT, STREAM)));
+ protected void emitAfterBody(final StringBuilder sb) {
+ sb.append(statement(invoke(AUGMENTABLE_SERIALIZER, "serialize", REGISTRY, INPUT, STREAM)));
}
}
\ No newline at end of file
protected final DataNodeContainer schemaNode;
private final GeneratedType dtoType;
- DataNodeContainerSerializerSource(final AbstractGenerator generator, final GeneratedType type, final DataNodeContainer node) {
+ DataNodeContainerSerializerSource(final AbstractGenerator generator, final GeneratedType type,
+ final DataNodeContainer node) {
super(generator);
this.dtoType = Preconditions.checkNotNull(type);
this.schemaNode = Preconditions.checkNotNull(node);
@Override
protected CharSequence getSerializerBody() {
- final StringBuilder b = new StringBuilder();
- b.append("{\n");
- b.append(statement(assign(DataObjectSerializerRegistry.class.getName(), REGISTRY, "$1")));
- b.append(statement(assign(dtoType.getFullyQualifiedName(), INPUT,
+ final StringBuilder sb = new StringBuilder();
+ sb.append("{\n");
+ sb.append(statement(assign(DataObjectSerializerRegistry.class.getName(), REGISTRY, "$1")));
+ sb.append(statement(assign(dtoType.getFullyQualifiedName(), INPUT,
cast(dtoType.getFullyQualifiedName(), "$2"))));
- b.append(statement(assign(BindingStreamEventWriter.class.getName(), STREAM, cast(BindingStreamEventWriter.class.getName(), "$3"))));
- b.append(statement(assign(BindingSerializer.class.getName(), SERIALIZER, null)));
- b.append("if (");
- b.append(STREAM);
- b.append(" instanceof ");
- b.append(BindingSerializer.class.getName());
- b.append(") {");
- b.append(statement(assign(SERIALIZER, cast(BindingSerializer.class.getName(), STREAM))));
- b.append('}');
- b.append(statement(emitStartEvent()));
-
- emitBody(b);
- emitAfterBody(b);
- b.append(statement(endNode()));
- b.append(statement("return null"));
- b.append('}');
- return b;
+ sb.append(statement(assign(BindingStreamEventWriter.class.getName(), STREAM,
+ cast(BindingStreamEventWriter.class.getName(), "$3"))));
+ sb.append(statement(assign(BindingSerializer.class.getName(), SERIALIZER, null)));
+ sb.append("if (");
+ sb.append(STREAM);
+ sb.append(" instanceof ");
+ sb.append(BindingSerializer.class.getName());
+ sb.append(") {");
+ sb.append(statement(assign(SERIALIZER, cast(BindingSerializer.class.getName(), STREAM))));
+ sb.append('}');
+ sb.append(statement(emitStartEvent()));
+
+ emitBody(sb);
+ emitAfterBody(sb);
+ sb.append(statement(endNode()));
+ sb.append(statement("return null"));
+ sb.append('}');
+ return sb;
}
/**
* Allows for customization of emitting code, which is processed after
* normal DataNodeContainer body. Ideal for augmentations or others.
*/
- protected void emitAfterBody(final StringBuilder b) {
+ protected void emitAfterBody(final StringBuilder sb) {
// No-op
}
return prefix + BindingMapping.getGetterSuffix(node.getQName());
}
- private void emitBody(final StringBuilder b) {
+ private void emitBody(final StringBuilder sb) {
final Map<String, Type> getterToType = collectAllProperties(dtoType, new HashMap<String, Type>());
for (final DataSchemaNode schemaChild : schemaNode.getChildNodes()) {
if (!schemaChild.isAugmenting()) {
// FIXME AnyXml nodes are ignored, since their type cannot be found in generated bindnig
// Bug-706 https://bugs.opendaylight.org/show_bug.cgi?id=706
if (schemaChild instanceof AnyXmlSchemaNode) {
- LOG.warn("Node {} will be ignored. AnyXml is not yet supported from binding aware code." +
- "Binding Independent code can be used to serialize anyXml nodes.", schemaChild.getPath());
+ LOG.warn("Node {} will be ignored. AnyXml is not yet supported from binding aware code."
+ + "Binding Independent code can be used to serialize anyXml nodes.",
+ schemaChild.getPath());
continue;
}
String.format("Unable to find type for child node %s. Expected child nodes: %s",
schemaChild.getPath(), getterToType));
}
- emitChild(b, getter, childType, schemaChild);
+ emitChild(sb, getter, childType, schemaChild);
}
}
}
- private void emitChild(final StringBuilder b, final String getterName, final Type childType,
+ private void emitChild(final StringBuilder sb, final String getterName, final Type childType,
final DataSchemaNode schemaChild) {
- b.append(statement(assign(childType, getterName, cast(childType, invoke(INPUT, getterName)))));
+ sb.append(statement(assign(childType, getterName, cast(childType, invoke(INPUT, getterName)))));
- b.append("if (").append(getterName).append(" != null) {\n");
- emitChildInner(b, getterName, childType, schemaChild);
- b.append("}\n");
+ sb.append("if (").append(getterName).append(" != null) {\n");
+ emitChildInner(sb, getterName, childType, schemaChild);
+ sb.append("}\n");
}
- private void emitChildInner(final StringBuilder b, final String getterName, final Type childType,
+ private void emitChildInner(final StringBuilder sb, final String getterName, final Type childType,
final DataSchemaNode child) {
if (child instanceof LeafSchemaNode) {
- b.append(statement(leafNode(child.getQName().getLocalName(), getterName)));
+ sb.append(statement(leafNode(child.getQName().getLocalName(), getterName)));
} else if (child instanceof AnyXmlSchemaNode) {
- b.append(statement(anyxmlNode(child.getQName().getLocalName(), getterName)));
+ sb.append(statement(anyxmlNode(child.getQName().getLocalName(), getterName)));
} else if (child instanceof LeafListSchemaNode) {
final CharSequence startEvent;
if (((LeafListSchemaNode) child).isUserOrdered()) {
} else {
startEvent = startLeafSet(child.getQName().getLocalName(),invoke(getterName, "size"));
}
- b.append(statement(startEvent));
+ sb.append(statement(startEvent));
final Type valueType = ((ParameterizedType) childType).getActualTypeArguments()[0];
- b.append(forEach(getterName, valueType, statement(leafSetEntryNode(CURRENT))));
- b.append(statement(endNode()));
+ sb.append(forEach(getterName, valueType, statement(leafSetEntryNode(CURRENT))));
+ sb.append(statement(endNode()));
} else if (child instanceof ListSchemaNode) {
final Type valueType = ((ParameterizedType) childType).getActualTypeArguments()[0];
final ListSchemaNode casted = (ListSchemaNode) child;
- emitList(b, getterName, valueType, casted);
+ emitList(sb, getterName, valueType, casted);
} else if (child instanceof ContainerSchemaNode) {
- b.append(tryToUseCacheElse(getterName,statement(staticInvokeEmitter(childType, getterName))));
+ sb.append(tryToUseCacheElse(getterName,statement(staticInvokeEmitter(childType, getterName))));
} else if (child instanceof ChoiceSchemaNode) {
final String propertyName = CHOICE_PREFIX + childType.getName();
- staticConstant(propertyName, DataObjectSerializerImplementation.class, ChoiceDispatchSerializer.from(loadClass(childType)));
- b.append(tryToUseCacheElse(getterName,statement(invoke(propertyName, StreamWriterGenerator.SERIALIZE_METHOD_NAME, REGISTRY, cast(DataObject.class.getName(),getterName), STREAM))));
+ staticConstant(propertyName, DataObjectSerializerImplementation.class,
+ ChoiceDispatchSerializer.from(loadClass(childType)));
+ sb.append(tryToUseCacheElse(getterName,statement(invoke(propertyName,
+ StreamWriterGenerator.SERIALIZE_METHOD_NAME, REGISTRY, cast(DataObject.class.getName(), getterName),
+ STREAM))));
}
}
private static StringBuilder tryToUseCacheElse(final String getterName, final CharSequence statement) {
final StringBuilder b = new StringBuilder();
-
b.append("if ( ");
b.append(SERIALIZER).append("== null || ");
b.append(invoke(SERIALIZER, "serialize", getterName)).append("== null");
return b;
}
- private void emitList(final StringBuilder b, final String getterName, final Type valueType,
+ private void emitList(final StringBuilder sb, final String getterName, final Type valueType,
final ListSchemaNode child) {
final CharSequence startEvent;
- b.append(statement(assign("int", "_count", invoke(getterName, "size"))));
+ sb.append(statement(assign("int", "_count", invoke(getterName, "size"))));
if (child.getKeyDefinition().isEmpty()) {
startEvent = startUnkeyedList(classReference(valueType), "_count");
} else if (child.isUserOrdered()) {
} else {
startEvent = startMapNode(classReference(valueType), "_count");
}
- b.append(statement(startEvent));
- b.append(forEach(getterName, valueType, tryToUseCacheElse(CURRENT,statement(staticInvokeEmitter(valueType, CURRENT)))));
- b.append(statement(endNode()));
+ sb.append(statement(startEvent));
+ sb.append(forEach(getterName, valueType, tryToUseCacheElse(CURRENT, statement(staticInvokeEmitter(valueType,
+ CURRENT)))));
+ sb.append(statement(endNode()));
}
}
/**
* Prototype of a DataObjectSerializerImplementation. This is a template class, which the
- * {@link AbstractStreamWriterGenerator} uses to instantiate {@link DataObjectSerializerImplementation}
- * on a per-type basis. During that time, the {@link #serialize(DataObjectSerializerRegistry, DataObject, BindingStreamEventWriter)}
+ * {@link AbstractStreamWriterGenerator} uses to instantiate {@link DataObjectSerializerImplementation} on a per-type
+ * basis. During that time, the {@link #serialize(DataObjectSerializerRegistry, DataObject, BindingStreamEventWriter)}
* method will be replaced by the real implementation.
*/
final class DataObjectSerializerPrototype implements DataObjectSerializerImplementation {
}
@Override
- public void serialize(final DataObjectSerializerRegistry reg, final DataObject obj, final BindingStreamEventWriter stream) {
+ public void serialize(final DataObjectSerializerRegistry reg, final DataObject obj,
+ final BindingStreamEventWriter stream) {
throw new UnsupportedOperationException("Prototype body, this code should never be invoked.");
}
}
private final AbstractGenerator generator;
/**
+ * Create a new source.
+ *
* @param generator Parent generator
*/
DataObjectSerializerSource(final AbstractGenerator generator) {
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
/**
- * Concrete implementation of {@link AbstractStreamWriterGenerator}
- * which in runtime generates classes implementing {@link DataObjectSerializerImplementation}
- * interface and are used to serialize Binding {@link DataObject}.
+ * Concrete implementation of {@link AbstractStreamWriterGenerator} which in runtime generates classes implementing
+ * {@link DataObjectSerializerImplementation} interface and are used to serialize Binding {@link DataObject}.
*
- * Actual implementation of codecs is done via static methods, which allows
- * for static wiring of codecs. Choice codec and Augmentable codecs
- * are static properties of parent codec and stateless implementations
- * are used ( {@link ChoiceDispatchSerializer}, {@link AugmentableDispatchSerializer},
- * which uses registry to dispatch to concrete item codec.
+ * <p>
+ * Actual implementation of codecs is done via static methods, which allows for static wiring of codecs. Choice codec
+ * and Augmentable codecs are static properties of parent codec and stateless implementations are used
+ * ({@link ChoiceDispatchSerializer}, {@link AugmentableDispatchSerializer}), which uses registry to dispatch to
+ * concrete item codec.
*/
public final class StreamWriterGenerator extends AbstractStreamWriterGenerator {
private static final String UNKNOWN_SIZE = BindingStreamEventWriter.class.getName() + ".UNKNOWN_SIZE";
}
@Override
- protected DataObjectSerializerSource generateContainerSerializer(final GeneratedType type, final ContainerSchemaNode node) {
-
+ protected DataObjectSerializerSource generateContainerSerializer(final GeneratedType type,
+ final ContainerSchemaNode node) {
return new AugmentableDataNodeContainerEmitterSource(this, type, node) {
@Override
public CharSequence emitStartEvent() {
}
@Override
- protected DataObjectSerializerSource generateNotificationSerializer(final GeneratedType type, final NotificationDefinition node) {
-
+ protected DataObjectSerializerSource generateNotificationSerializer(final GeneratedType type,
+ final NotificationDefinition node) {
return new AugmentableDataNodeContainerEmitterSource(this, type, node) {
@Override
public CharSequence emitStartEvent() {
}
@Override
- protected DataObjectSerializerSource generateUnkeyedListEntrySerializer(final GeneratedType type, final ListSchemaNode node) {
+ protected DataObjectSerializerSource generateUnkeyedListEntrySerializer(final GeneratedType type,
+ final ListSchemaNode node) {
return new AugmentableDataNodeContainerEmitterSource(this, type, node) {
-
@Override
public CharSequence emitStartEvent() {
return startUnkeyedListItem(UNKNOWN_SIZE);
}
@Override
- protected DataObjectSerializerSource generateSerializer(final GeneratedType type, final AugmentationSchema schema) {
+ protected DataObjectSerializerSource generateSerializer(final GeneratedType type,
+ final AugmentationSchema schema) {
return new DataNodeContainerSerializerSource(this, type, schema) {
-
@Override
public CharSequence emitStartEvent() {
return startAugmentationNode(classReference(type));
}
@Override
- protected DataObjectSerializerSource generateMapEntrySerializer(final GeneratedType type, final ListSchemaNode node) {
+ protected DataObjectSerializerSource generateMapEntrySerializer(final GeneratedType type,
+ final ListSchemaNode node) {
return new AugmentableDataNodeContainerEmitterSource(this, type, node) {
@Override
public CharSequence emitStartEvent() {
return commonInvoke(object, methodName).append(arg).append(')');
}
- protected static final CharSequence invoke(final CharSequence object, final String methodName, final Object... args) {
+ protected static final CharSequence invoke(final CharSequence object, final String methodName,
+ final Object... args) {
final StringBuilder sb = commonInvoke(object, methodName);
final UnmodifiableIterator<Object> iterator = Iterators.forArray(args);
return cast(type.getFullyQualifiedName(), value);
}
+ protected static final CharSequence cast(final String type, final CharSequence value) {
+ return "((" + type + ") " + value + ')';
+ }
+
protected static final CharSequence forEach(final String iterable, final String iteratorName,
final String valueType, final String valueName, final CharSequence body) {
final StringBuilder sb = new StringBuilder();
protected static final CharSequence statement(final CharSequence statement) {
return new StringBuilder(statement).append(";\n");
}
-
- protected static final CharSequence cast(final String type, final CharSequence value) {
- return "((" + type + ") " + value + ')';
- }
}
import com.google.common.base.Preconditions;
/**
- * Definition of static property for generated class
+ * Definition of static property for generated class.
+ *
* <p>
* This definition consists of
* <ul>
}
return true;
}
-
}
import org.opendaylight.yangtools.yang.binding.DataObject;
/**
- *
- * Abstract Holder of Binding to Normalized Node caches indexed by {@link DataContainerCodecContext}
- * to which cache is associated.
- *
+ * Abstract Holder of Binding to Normalized Node caches indexed by {@link DataContainerCodecContext} to which cache is
+ * associated.
*/
abstract class AbstractBindingNormalizedNodeCacheHolder {
private final Set<Class<? extends DataObject>> cachedValues;
private final LoadingCache<DataContainerCodecContext<?, ?>, BindingNormalizedNodeCache> caches = CacheBuilder
.newBuilder().build(new CacheLoader<DataContainerCodecContext<?, ?>, BindingNormalizedNodeCache>() {
-
@Override
- public BindingNormalizedNodeCache load(final DataContainerCodecContext<?, ?> key) throws Exception {
+ public BindingNormalizedNodeCache load(final DataContainerCodecContext<?, ?> key) {
return new BindingNormalizedNodeCache(AbstractBindingNormalizedNodeCacheHolder.this, key);
}
-
});
protected AbstractBindingNormalizedNodeCacheHolder(final Set<Class<? extends DataObject>> cacheSpec) {
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-final class AugmentationNodeContext<D extends DataObject & Augmentation<?>> extends DataObjectCodecContext<D,AugmentationSchema> {
+final class AugmentationNodeContext<D extends DataObject & Augmentation<?>>
+ extends DataObjectCodecContext<D, AugmentationSchema> {
- public AugmentationNodeContext(final DataContainerCodecPrototype<AugmentationSchema> prototype) {
+ AugmentationNodeContext(final DataContainerCodecPrototype<AugmentationSchema> prototype) {
super(prototype);
}
DataContainerCodecContext<?,?> currentNode = root;
for (final InstanceIdentifier.PathArgument bindingArg : binding.getPathArguments()) {
currentNode = currentNode.bindingPathArgumentChild(bindingArg, builder);
- Preconditions.checkArgument(currentNode != null, "Supplied Instance Identifier %s is not valid.",binding);
+ Preconditions.checkArgument(currentNode != null, "Supplied Instance Identifier %s is not valid.", binding);
}
return currentNode;
}
ListNodeCodecContext<?> currentList = null;
for (final YangInstanceIdentifier.PathArgument domArg : dom.getPathArguments()) {
- Preconditions.checkArgument(currentNode instanceof DataContainerCodecContext<?,?>, "Unexpected child of non-container node %s", currentNode);
+ Preconditions.checkArgument(currentNode instanceof DataContainerCodecContext<?,?>,
+ "Unexpected child of non-container node %s", currentNode);
final DataContainerCodecContext<?,?> previous = (DataContainerCodecContext<?,?>) currentNode;
final NodeCodecContext<?> nextNode = previous.yangPathArgumentChild(domArg);
* Identifier as Item or IdentifiableItem
*/
if (currentList != null) {
- Preconditions.checkArgument(currentList == nextNode, "List should be referenced two times in YANG Instance Identifier %s", dom);
+ Preconditions.checkArgument(currentList == nextNode,
+ "List should be referenced two times in YANG Instance Identifier %s", dom);
// We entered list, so now we have all information to emit
// list path using second list argument.
return getLeafNodesUsingReflection(parentClass, getterToLeafSchema);
}
- private static String getGetterName(final QName qName, final TypeDefinition<?> typeDef) {
- final String suffix = BindingMapping.getGetterSuffix(qName);
+ private static String getGetterName(final QName qname, final TypeDefinition<?> typeDef) {
+ final String suffix = BindingMapping.getGetterSuffix(qname);
if (typeDef instanceof BooleanTypeDefinition || typeDef instanceof EmptyTypeDefinition) {
return "is" + suffix;
}
throw new IllegalStateException("Unexpected return type " + genericType);
}
} else {
- continue; // We do not have schema for leaf, so we will ignore it (eg. getClass, getImplementedInterface).
+ // We do not have schema for leaf, so we will ignore it (eg. getClass, getImplementedInterface).
+ continue;
}
final Codec<Object, Object> codec = getCodec(valueType, schema);
final LeafNodeCodecContext<?> leafNode = new LeafNodeCodecContext<>(schema, codec, method,
return ValueTypeCodec.NOOP_CODEC;
}
+ @SuppressWarnings("checkstyle:illegalCatch")
private Codec<Object, Object> getCodecForBindingClass(final Class<?> valueType, final TypeDefinition<?> typeDef) {
if (typeDef instanceof IdentityrefTypeDefinition) {
return ValueTypeCodec.encapsulatedValueCodecFor(valueType, identityCodec);
} else if (typeDef instanceof InstanceIdentifierTypeDefinition) {
return ValueTypeCodec.encapsulatedValueCodecFor(valueType, instanceIdentifierCodec);
} else if (typeDef instanceof UnionTypeDefinition) {
- final Callable<UnionTypeCodec> loader = UnionTypeCodec.loader(valueType, (UnionTypeDefinition) typeDef, this);
+ final Callable<UnionTypeCodec> loader = UnionTypeCodec.loader(valueType, (UnionTypeDefinition) typeDef,
+ this);
try {
return loader.call();
} catch (final Exception e) {
final DataContainerCodecContext<?, ?> subtreeRoot;
final AbstractBindingNormalizedNodeCacheHolder cacheHolder;
- public BindingNormalizedNodeCache(final AbstractBindingNormalizedNodeCacheHolder cacheHolder,
+ BindingNormalizedNodeCache(final AbstractBindingNormalizedNodeCacheHolder cacheHolder,
final DataContainerCodecContext<?, ?> subtreeRoot) {
this.cacheHolder = Preconditions.checkNotNull(cacheHolder, "cacheHolder");
this.subtreeRoot = Preconditions.checkNotNull(subtreeRoot, "subtreeRoot");
}
/**
- * Returns cached NormalizedNode representation of DataObject.
- *
- * If representation is not cached, serializes DataObject and updates cache with representation.
+ * Returns cached NormalizedNode representation of DataObject. If the representation is not cached, serializes
+ * DataObject and updates cache with representation.
*
* @param obj Binding object to be deserialized
* @return NormalizedNode representation of binding object.
}
@Override
- public <T extends DataObject> Entry<YangInstanceIdentifier,NormalizedNode<?,?>> toNormalizedNode(final InstanceIdentifier<T> path, final T data) {
+ public <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?,?>> toNormalizedNode(
+ final InstanceIdentifier<T> path, final T data) {
final NormalizedNodeResult result = new NormalizedNodeResult();
// We create DOM stream writer which produces normalized nodes
final NormalizedNodeStreamWriter domWriter = ImmutableNormalizedNodeStreamWriter.from(result);
// We create Binding Stream Writer which translates from Binding to Normalized Nodes
- final Entry<YangInstanceIdentifier, BindingStreamEventWriter> writeCtx = codecContext.newWriter(path, domWriter);
+ final Entry<YangInstanceIdentifier, BindingStreamEventWriter> writeCtx = codecContext.newWriter(path,
+ domWriter);
// We get serializer which reads binding data and uses Binding To Normalized Node writer to write result
try {
}
@Override
- public Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(final YangInstanceIdentifier path,
+ final NormalizedNode<?, ?> data) {
if (!isBindingRepresentable(data)) {
return null;
}
final NodeCodecContext<?> codec = codecContext.getCodecContextNode(path, builder);
if (codec == null) {
if (data != null) {
- LOG.warn("Path {} does not have a binding equivalent, should have been caught earlier ({})", path, data.getClass());
+ LOG.warn("Path {} does not have a binding equivalent, should have been caught earlier ({})", path,
+ data.getClass());
}
return null;
}
return codec.deserialize(data);
}
- @Override
- public Entry<YangInstanceIdentifier, BindingStreamEventWriter> newWriterAndIdentifier(final InstanceIdentifier<?> path, final NormalizedNodeStreamWriter domWriter) {
+ @Override
+ public Entry<YangInstanceIdentifier, BindingStreamEventWriter> newWriterAndIdentifier(
+ final InstanceIdentifier<?> path, final NormalizedNodeStreamWriter domWriter) {
return codecContext.newWriter(path, domWriter);
}
@Override
- public BindingStreamEventWriter newWriter(final InstanceIdentifier<?> path, final NormalizedNodeStreamWriter domWriter) {
+ public BindingStreamEventWriter newWriter(final InstanceIdentifier<?> path,
+ final NormalizedNodeStreamWriter domWriter) {
return codecContext.newWriterWithoutIdentifier(path, domWriter);
}
return codecContext.newRpcWriter(rpcInputOrOutput,streamWriter);
}
- public <T extends DataObject> Function<Optional<NormalizedNode<?, ?>>, Optional<T>> deserializeFunction(final InstanceIdentifier<T> path) {
- final DataObjectCodecContext<?,?> ctx = (DataObjectCodecContext<?,?>) codecContext.getCodecContextNode(path, null);
+ public <T extends DataObject> Function<Optional<NormalizedNode<?, ?>>, Optional<T>> deserializeFunction(
+ final InstanceIdentifier<T> path) {
+ final DataObjectCodecContext<?,?> ctx = (DataObjectCodecContext<?,?>) codecContext.getCodecContextNode(path,
+ null);
return new DeserializeFunction<>(ctx);
}
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public BindingCodecTree create(final SchemaContext context, final Class<?>... bindingClasses) {
final ModuleInfoBackedContext strategy = ModuleInfoBackedContext.create();
for (final Class<?> bindingCls : bindingClasses) {
strategy.registerModuleInfo(BindingReflections.getModuleInfo(bindingCls));
} catch (final Exception e) {
throw new IllegalStateException(
- "Could not create BindingRuntimeContext from class " + bindingCls.getName(),
- e);
+ "Could not create BindingRuntimeContext from class " + bindingCls.getName(), e);
}
}
final BindingRuntimeContext runtimeCtx = BindingRuntimeContext.create(strategy, context);
}
}
- private final class DataObjectSerializerProxy implements DataObjectSerializer, Delegator<DataObjectSerializerImplementation> {
+ private final class DataObjectSerializerProxy
+ implements DataObjectSerializer, Delegator<DataObjectSerializerImplementation> {
private final DataObjectSerializerImplementation delegate;
DataObjectSerializerProxy(final DataObjectSerializerImplementation delegate) {
delegate.serialize(BindingNormalizedNodeCodecRegistry.this, obj, stream);
}
}
-
}
private final NormalizedNodeStreamWriter delegate;
private final NodeCodecContext<?> rootNodeSchema;
- BindingToNormalizedStreamWriter(final NodeCodecContext<?> rootNodeSchema, final NormalizedNodeStreamWriter delegate) {
+ BindingToNormalizedStreamWriter(final NodeCodecContext<?> rootNodeSchema,
+ final NormalizedNodeStreamWriter delegate) {
this.rootNodeSchema = Preconditions.checkNotNull(rootNodeSchema);
this.delegate = Preconditions.checkNotNull(delegate);
}
- static BindingToNormalizedStreamWriter create(final NodeCodecContext<?> schema, final NormalizedNodeStreamWriter delegate) {
- return new BindingToNormalizedStreamWriter(schema, delegate);
+ static BindingToNormalizedStreamWriter create(final NodeCodecContext<?> schema,
+ final NormalizedNodeStreamWriter delegate) {
+ return new BindingToNormalizedStreamWriter(schema, delegate);
}
private void emitSchema(final Object schema) {
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public Object deserialize(final Object input) {
Preconditions.checkArgument(input instanceof Set);
@SuppressWarnings("unchecked")
final Set<String> casted = (Set<String>) input;
/*
- * We can do this walk based on field set sorted by name,
- * since constructor arguments in Java Binding are sorted by name.
+ * We can do this walk based on field set sorted by name, since constructor arguments in Java Binding are
+ * sorted by name.
*
- * This means we will construct correct array for construction
- * of bits object.
+ * This means we will construct correct array for construction of bits object.
*/
- final Boolean args[] = new Boolean[ctorArgs.size()];
+ final Boolean[] args = new Boolean[ctorArgs.size()];
int currentArg = 0;
for (String value : ctorArgs) {
args[currentArg++] = casted.contains(value);
for (Entry<String, Method> valueGet : getters.entrySet()) {
final Boolean value;
try {
- value = (Boolean) valueGet.getValue().invoke(input);
+ value = (Boolean) valueGet.getValue().invoke(input);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException("Failed to get bit " + valueGet.getKey(), e);
}
* Serializer of Binding objects to Normalized Node which uses {@link BindingNormalizedNodeCache} to
* cache already serialized values.
*
+ * <p>
* This serializer implements {@link BindingStreamEventWriter} along with {@link BindingSerializer}.
*
+ * <p>
* {@link BindingSerializer} interface is used by generated implementations of
* {@link org.opendaylight.yangtools.yang.binding.DataObjectSerializer} to provide Binding object
* for inspection and to prevent streaming of already serialized object.
- *
*/
final class CachingNormalizedNodeSerializer extends ForwardingBindingStreamEventWriter implements
BindingSerializer<Object, DataObject> {
/**
* Serializes input if it is cached, returns null otherwise.
*
+ * <p>
* If input is cached it uses {@link NormalizedNodeWriterWithAddChild#addChild(NormalizedNode)}
* to provide already serialized value to underlying NormalizedNodeWriter in order to reuse
* value instead of creating new one using Normalized Node stream APIs.
*
+ * <p>
* Note that this optional is serialization of child node invoked from
* {@link org.opendaylight.yangtools.yang.binding.DataObjectSerializer}, which may opt-out from
* streaming of data when non-null result is returned.
return null;
}
- @SuppressWarnings({"rawtypes", "unchecked"})
- private BindingNormalizedNodeCache getCacheSerializer(final Class type) {
- if (cacheHolder.isCached(type)) {
- final DataContainerCodecContext<?, ?> currentCtx = (DataContainerCodecContext<?, ?>) delegate.current();
- if (type.equals(currentCtx.getBindingClass())) {
- return cacheHolder.getCachingSerializer(currentCtx);
- }
- return cacheHolder.getCachingSerializer(currentCtx.streamChild(type));
- }
- return null;
- }
-
/**
* Serializes supplied data using stream writer with child cache enabled or using cache directly
* if cache is avalaible also for supplied Codec node.
return serializeUsingStreamWriter(cacheHolder, subtreeRoot, data);
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private BindingNormalizedNodeCache getCacheSerializer(final Class type) {
+ if (cacheHolder.isCached(type)) {
+ final DataContainerCodecContext<?, ?> currentCtx = (DataContainerCodecContext<?, ?>) delegate.current();
+ if (type.equals(currentCtx.getBindingClass())) {
+ return cacheHolder.getCachingSerializer(currentCtx);
+ }
+ return cacheHolder.getCachingSerializer(currentCtx.streamChild(type));
+ }
+ return null;
+ }
+
/**
* Serializes supplied data using stream writer with child cache enabled.
*
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
final class CaseNodeCodecContext<D extends DataObject> extends DataObjectCodecContext<D,ChoiceCaseNode> {
- public CaseNodeCodecContext(final DataContainerCodecPrototype<ChoiceCaseNode> prototype) {
+ CaseNodeCodecContext(final DataContainerCodecPrototype<ChoiceCaseNode> prototype) {
super(prototype);
}
}
@Override
- public YangInstanceIdentifier.PathArgument serializePathArgument(
- final PathArgument arg) {
+ public YangInstanceIdentifier.PathArgument serializePathArgument(final PathArgument arg) {
Preconditions.checkArgument(arg == null);
return null;
}
private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byClass;
private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byCaseChildClass;
- public ChoiceNodeCodecContext(final DataContainerCodecPrototype<ChoiceSchemaNode> prototype) {
+ ChoiceNodeCodecContext(final DataContainerCodecPrototype<ChoiceSchemaNode> prototype) {
super(prototype);
- final Map<YangInstanceIdentifier.PathArgument, DataContainerCodecPrototype<?>> byYangCaseChildBuilder = new HashMap<>();
+ final Map<YangInstanceIdentifier.PathArgument, DataContainerCodecPrototype<?>> byYangCaseChildBuilder =
+ new HashMap<>();
final Map<Class<?>, DataContainerCodecPrototype<?>> byClassBuilder = new HashMap<>();
final Map<Class<?>, DataContainerCodecPrototype<?>> byCaseChildClassBuilder = new HashMap<>();
final Set<Class<?>> potentialSubstitutions = new HashSet<>();
// Updates collection of YANG instance identifier to case
for (final DataSchemaNode cazeChild : cazeDef.getSchema().getChildNodes()) {
if (cazeChild.isAugmenting()) {
- final AugmentationSchema augment = SchemaUtils.findCorrespondingAugment(cazeDef.getSchema(), cazeChild);
+ final AugmentationSchema augment = SchemaUtils.findCorrespondingAugment(cazeDef.getSchema(),
+ cazeChild);
if (augment != null) {
byYangCaseChildBuilder.put(SchemaUtils.getNodeIdentifierForAugmentation(augment), cazeDef);
continue;
* binding specification, that if choice is in grouping schema path location is lost,
* and users may use incorrect case class using copy builders.
*/
- for(final Class<?> substitution : potentialSubstitutions) {
- search: for(final Entry<Class<?>, DataContainerCodecPrototype<?>> real : byClassBuilder.entrySet()) {
+ for (final Class<?> substitution : potentialSubstitutions) {
+ search: for (final Entry<Class<?>, DataContainerCodecPrototype<?>> real : byClassBuilder.entrySet()) {
if (BindingReflections.isSubstitutionFor(substitution, real.getKey())) {
bySubstitutionBuilder.put(substitution, real.getValue());
break search;
@SuppressWarnings("unchecked")
@Override
- public <DV extends DataObject> DataContainerCodecContext<DV, ?> streamChild(final Class<DV> childClass) {
+ public <C extends DataObject> DataContainerCodecContext<C, ?> streamChild(final Class<C> childClass) {
final DataContainerCodecPrototype<?> child = byClass.get(childClass);
- return (DataContainerCodecContext<DV, ?>) childNonNull(child, childClass, "Supplied class %s is not valid case", childClass).get();
+ return (DataContainerCodecContext<C, ?>) childNonNull(child, childClass, "Supplied class %s is not valid case",
+ childClass).get();
}
@SuppressWarnings("unchecked")
@Override
- public <DV extends DataObject> Optional<DataContainerCodecContext<DV, ?>> possibleStreamChild(
- final Class<DV> childClass) {
+ public <C extends DataObject> Optional<DataContainerCodecContext<C, ?>> possibleStreamChild(
+ final Class<C> childClass) {
final DataContainerCodecPrototype<?> child = byClass.get(childClass);
if (child != null) {
- return Optional.of((DataContainerCodecContext<DV, ?>) child.get());
+ return Optional.of((DataContainerCodecContext<C, ?>) child.get());
}
return Optional.absent();
}
}
protected DataContainerCodecPrototype<ChoiceCaseNode> loadCase(final Class<?> childClass) {
- final Optional<ChoiceCaseNode> childSchema = factory().getRuntimeContext().getCaseSchemaDefinition(getSchema(), childClass);
+ final Optional<ChoiceCaseNode> childSchema = factory().getRuntimeContext().getCaseSchemaDefinition(getSchema(),
+ childClass);
if (childSchema.isPresent()) {
return DataContainerCodecPrototype.from(childClass, childSchema.get(), factory());
}
@Nullable
public D deserialize(final NormalizedNode<?, ?> data) {
Preconditions.checkArgument(data instanceof ChoiceNode);
- final NormalizedNodeContainer<?, ?, NormalizedNode<?,?>> casted = (NormalizedNodeContainer<?, ?, NormalizedNode<?,?>>) data;
+ final NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>> casted =
+ (NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>>) data;
final NormalizedNode<?, ?> first = Iterables.getFirst(casted.getValue(), null);
if (first == null) {
import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.DataObjectSerializer;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
}
/**
- * Returns nested node context using supplied YANG Instance Identifier
+ * Returns nested node context using supplied YANG Instance Identifier.
*
* @param arg Yang Instance Identifier Argument
* @return Context of child
* @throws IllegalArgumentException If supplied argument does not represent valid child.
*/
@Override
- public abstract NodeCodecContext<?> yangPathArgumentChild(final YangInstanceIdentifier.PathArgument arg);
+ public abstract NodeCodecContext<?> yangPathArgumentChild(YangInstanceIdentifier.PathArgument arg);
/**
* Returns nested node context using supplied Binding Instance Identifier
* @throws IllegalArgumentException If supplied argument does not represent valid child.
*/
@Override
- public @Nullable DataContainerCodecContext<?,?> bindingPathArgumentChild(final InstanceIdentifier.PathArgument arg,
+ @Nullable
+ public DataContainerCodecContext<?,?> bindingPathArgumentChild(final PathArgument arg,
final List<YangInstanceIdentifier.PathArgument> builder) {
final DataContainerCodecContext<?,?> child = streamChild(arg.getType());
- if(child != null) {
+ if (child != null) {
if (builder != null) {
child.addYangPathArgument(arg,builder);
}
return child;
}
- throw new IllegalArgumentException("SUpplied argument is not valid child");
+ throw new IllegalArgumentException("Supplied argument is not valid child");
}
/**
* Returns deserialized Binding Path Argument from YANG instance identifier.
- *
- * @param domArg
- * @return
*/
protected PathArgument getBindingPathArgument(final YangInstanceIdentifier.PathArgument domArg) {
return bindingArg();
}
/**
- *
- * Returns child context as if it was walked by
- * {@link BindingStreamEventWriter}. This means that to enter case, one
+ * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case, one
* must issue getChild(ChoiceClass).getChild(CaseClass).
*
- * @param childClass
+ * @param childClass child class
* @return Context of child node or null, if supplied class is not subtree child
* @throws IllegalArgumentException If supplied child class is not valid in specified context.
*/
@Override
- public abstract @Nullable <DV extends DataObject> DataContainerCodecContext<DV,?> streamChild(final Class<DV> childClass) throws IllegalArgumentException;
+ public abstract @Nullable <C extends DataObject> DataContainerCodecContext<C, ?> streamChild(Class<C> childClass);
/**
- *
- * Returns child context as if it was walked by
- * {@link BindingStreamEventWriter}. This means that to enter case, one
+ * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case, one
* must issue getChild(ChoiceClass).getChild(CaseClass).
*
- * @param childClass
+ * @param childClass child class
* @return Context of child or Optional absent is supplied class is not applicable in context.
*/
@Override
- public abstract <DV extends DataObject> Optional<DataContainerCodecContext<DV,?>> possibleStreamChild(final Class<DV> childClass);
+ public abstract <C extends DataObject> Optional<DataContainerCodecContext<C,?>> possibleStreamChild(
+ Class<C> childClass);
@Override
public String toString() {
@Override
public BindingNormalizedNodeCachingCodec<D> createCachingCodec(
final ImmutableCollection<Class<? extends DataObject>> cacheSpecifier) {
- if(cacheSpecifier.isEmpty()) {
+ if (cacheSpecifier.isEmpty()) {
return new NonCachingCodec<>(this);
}
return new CachingNormalizedNodeCodec<>(this,ImmutableSet.copyOf(cacheSpecifier));
}
DataObjectSerializer eventStreamSerializer() {
- if(eventStreamSerializer == null) {
+ if (eventStreamSerializer == null) {
eventStreamSerializer = factory().getEventStreamSerializer(getBindingClass());
}
return eventStreamSerializer;
private volatile DataContainerCodecContext<?,T> instance = null;
@SuppressWarnings({"rawtypes", "unchecked"})
- private DataContainerCodecPrototype(final Class<?> cls, final YangInstanceIdentifier.PathArgument arg, final T nodeSchema,
- final CodecContextFactory factory) {
+ private DataContainerCodecPrototype(final Class<?> cls, final YangInstanceIdentifier.PathArgument arg,
+ final T nodeSchema, final CodecContextFactory factory) {
this.bindingClass = cls;
this.yangArg = arg;
this.schema = nodeSchema;
this.bindingArg = new InstanceIdentifier.Item(bindingClass);
if (arg instanceof AugmentationIdentifier) {
- this.namespace = Iterables.getFirst(((AugmentationIdentifier) arg).getPossibleChildNames(), null).getModule();
+ this.namespace = Iterables.getFirst(((AugmentationIdentifier) arg).getPossibleChildNames(), null)
+ .getModule();
} else {
this.namespace = arg.getNodeType().getModule();
}
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
- static <T extends DataSchemaNode> DataContainerCodecPrototype<T> from(final Class<?> cls, final T schema,
- final CodecContextFactory factory) {
- return new DataContainerCodecPrototype(cls, NodeIdentifier.create(schema.getQName()), schema, factory);
- }
-
static DataContainerCodecPrototype<SchemaContext> rootPrototype(final CodecContextFactory factory) {
final SchemaContext schema = factory.getRuntimeContext().getSchemaContext();
final NodeIdentifier arg = NodeIdentifier.create(schema.getQName());
- return new DataContainerCodecPrototype<SchemaContext>(DataRoot.class, arg, schema, factory);
+ return new DataContainerCodecPrototype<>(DataRoot.class, arg, schema, factory);
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ static <T extends DataSchemaNode> DataContainerCodecPrototype<T> from(final Class<?> cls, final T schema,
+ final CodecContextFactory factory) {
+ return new DataContainerCodecPrototype(cls, NodeIdentifier.create(schema.getQName()), schema, factory);
+ }
@SuppressWarnings({ "rawtypes", "unchecked" })
static DataContainerCodecPrototype<?> from(final Class<?> augClass, final AugmentationIdentifier arg,
return new DataContainerCodecPrototype(augClass, arg, schema, factory);
}
- static DataContainerCodecPrototype<NotificationDefinition> from(final Class<?> augClass, final NotificationDefinition schema, final CodecContextFactory factory) {
+ static DataContainerCodecPrototype<NotificationDefinition> from(final Class<?> augClass,
+ final NotificationDefinition schema, final CodecContextFactory factory) {
final PathArgument arg = NodeIdentifier.create(schema.getQName());
- return new DataContainerCodecPrototype<NotificationDefinition>(augClass,arg, schema, factory);
+ return new DataContainerCodecPrototype<>(augClass,arg, schema, factory);
}
protected T getSchema() {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-abstract class DataObjectCodecContext<D extends DataObject,T extends DataNodeContainer> extends DataContainerCodecContext<D,T> {
+abstract class DataObjectCodecContext<D extends DataObject, T extends DataNodeContainer>
+ extends DataContainerCodecContext<D, T> {
private static final Logger LOG = LoggerFactory.getLogger(DataObjectCodecContext.class);
private static final MethodType CONSTRUCTOR_TYPE = MethodType.methodType(void.class, InvocationHandler.class);
private static final MethodType DATAOBJECT_TYPE = MethodType.methodType(DataObject.class, InvocationHandler.class);
byYangBuilder.put(childProto.getYangArg(), childProto);
if (childProto.isChoice()) {
final ChoiceNodeCodecContext<?> choice = (ChoiceNodeCodecContext<?>) childProto.get();
- for(final Class<?> cazeChild : choice.getCaseChildrenClasses()) {
+ for (final Class<?> cazeChild : choice.getCaseChildrenClasses()) {
byBindingArgClassBuilder.put(cazeChild, childProto);
}
}
}
reloadAllAugmentations();
- final Class<?> proxyClass = Proxy.getProxyClass(getBindingClass().getClassLoader(), new Class[] { getBindingClass(), AugmentationHolder.class });
+ final Class<?> proxyClass = Proxy.getProxyClass(getBindingClass().getClassLoader(), getBindingClass(),
+ AugmentationHolder.class);
try {
proxyConstructor = MethodHandles.publicLookup().findConstructor(proxyClass, CONSTRUCTOR_TYPE)
.asType(DATAOBJECT_TYPE);
@SuppressWarnings("unchecked")
@Override
- public <DV extends DataObject> DataContainerCodecContext<DV, ?> streamChild(final Class<DV> childClass) {
+ public <C extends DataObject> DataContainerCodecContext<C, ?> streamChild(final Class<C> childClass) {
final DataContainerCodecPrototype<?> childProto = streamChildPrototype(childClass);
- return (DataContainerCodecContext<DV, ?>) childNonNull(childProto, childClass, " Child %s is not valid child.",
+ return (DataContainerCodecContext<C, ?>) childNonNull(childProto, childClass, " Child %s is not valid child.",
childClass).get();
}
- private final DataContainerCodecPrototype<?> streamChildPrototype(final Class<?> childClass) {
+ private DataContainerCodecPrototype<?> streamChildPrototype(final Class<?> childClass) {
final DataContainerCodecPrototype<?> childProto = byStreamClass.get(childClass);
if (childProto != null) {
return childProto;
@SuppressWarnings("unchecked")
@Override
- public <DV extends DataObject> Optional<DataContainerCodecContext<DV, ?>> possibleStreamChild(
- final Class<DV> childClass) {
+ public <C extends DataObject> Optional<DataContainerCodecContext<C, ?>> possibleStreamChild(
+ final Class<C> childClass) {
final DataContainerCodecPrototype<?> childProto = streamChildPrototype(childClass);
if (childProto != null) {
- return Optional.<DataContainerCodecContext<DV,?>>of((DataContainerCodecContext<DV,?>) childProto.get());
+ return Optional.of((DataContainerCodecContext<C, ?>) childProto.get());
}
return Optional.absent();
}
}
@Nullable
- private final DataContainerCodecPrototype<?> augmentationByClassOrEquivalentClass(@Nonnull final Class<?> childClass) {
+ private DataContainerCodecPrototype<?> augmentationByClassOrEquivalentClass(@Nonnull final Class<?> childClass) {
final DataContainerCodecPrototype<?> childProto = byStreamAugmented.get(childClass);
if (childProto != null) {
return childProto;
}
}
+ @SuppressWarnings("checkstyle:illegalCatch")
protected final D createBindingProxy(final NormalizedNodeContainer<?, ?, ?> node) {
try {
return (D) proxyConstructor.invokeExact((InvocationHandler)new LazyDataObject<>(this, node));
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public Object deserialize(final Object input) {
try {
return constructor.invokeExact(input);
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public Object serialize(final Object input) {
try {
return getter.invokeExact(input);
private final MethodHandle ctorInvoker;
private final MethodHandle ctor;
- public IdentifiableItemCodec(final ListSchemaNode schema, final Class<? extends Identifier<?>> keyClass,
+ IdentifiableItemCodec(final ListSchemaNode schema, final Class<? extends Identifier<?>> keyClass,
final Class<?> identifiable, final Map<QName, ValueContext> keyValueContexts) {
this.schema = schema;
this.identifiable = identifiable;
}
@Override
+ @SuppressWarnings("checkstyle:illegalCatch")
public IdentifiableItem<?, ?> deserialize(final NodeIdentifierWithPredicates input) {
final Object[] bindingValues = new Object[keysInBindingOrder.size()];
int offset = 0;
import javax.annotation.Nullable;
/**
- * Thrown where incorrect nesting of data structures was detected
- * and was caused by user.
+ * Thrown where incorrect nesting of data structures was detected and was caused by user.
*/
public class IncorrectNestingException extends IllegalArgumentException {
}
public static void check(final boolean check, final String message, final Object... args) {
- if(!check) {
+ if (!check) {
throw IncorrectNestingException.create(message, args);
}
}
@Nonnull
public static <V> V checkNonNull(@Nullable final V nullable, final String message, final Object... args) {
- if(nullable != null) {
+ if (nullable != null) {
return nullable;
}
throw IncorrectNestingException.create(message, args);
}
@Override
- protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg, final List<YangInstanceIdentifier.PathArgument> builder) {
+ protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg,
+ final List<YangInstanceIdentifier.PathArgument> builder) {
/*
- * DOM Instance Identifier for list is always represent by two
- * entries one for map and one for children. This is also true for
- * wildcarded instance identifiers
+ * DOM Instance Identifier for list is always represent by two entries one for map and one for children. This
+ * is also true for wildcarded instance identifiers
*/
if (builder == null) {
return;
if (dom instanceof MapEntryNode && keyGetter.equals(method)) {
NodeIdentifierWithPredicates identifier = ((MapEntryNode) dom).getIdentifier();
return codec.deserialize(identifier).getKey();
- } else {
- return super.getBindingChildValue(method, dom);
}
+ return super.getBindingChildValue(method, dom);
}
@Override
- protected InstanceIdentifier.PathArgument getBindingPathArgument(final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument domArg) {
+ protected InstanceIdentifier.PathArgument getBindingPathArgument(final YangInstanceIdentifier.PathArgument domArg) {
if (domArg instanceof NodeIdentifierWithPredicates) {
return codec.deserialize((NodeIdentifierWithPredicates) domArg);
}
@Override
public YangInstanceIdentifier.PathArgument serializePathArgument(final InstanceIdentifier.PathArgument arg) {
- if(arg instanceof IdentifiableItem) {
+ if (arg instanceof IdentifiableItem) {
return codec.serialize((IdentifiableItem<?,?>) arg);
}
return super.serializePathArgument(arg);
@Override
public InstanceIdentifier.PathArgument deserializePathArgument(final YangInstanceIdentifier.PathArgument arg) {
- if(arg instanceof NodeIdentifierWithPredicates) {
+ if (arg instanceof NodeIdentifierWithPredicates) {
return codec.deserialize((NodeIdentifierWithPredicates) arg);
}
return super.deserializePathArgument(arg);
}
-
-
}
if (!Arrays.equals((byte[]) thisValue, (byte[]) otherValue)) {
return false;
}
- } else if (!Objects.equals(thisValue, otherValue)){
+ } else if (!Objects.equals(thisValue, otherValue)) {
return false;
}
}
private static Map<Class<? extends Augmentation<?>>, Augmentation<?>> getAllAugmentations(final Object dataObject) {
if (dataObject instanceof AugmentationReader) {
return ((AugmentationReader) dataObject).getAugmentations(dataObject);
- } else if (dataObject instanceof Augmentable<?>){
+ } else if (dataObject instanceof Augmentable<?>) {
return BindingReflections.getAugmentations((Augmentable<?>) dataObject);
}
Preconditions.checkNotNull(cls,"Supplied augmentation must not be null.");
@SuppressWarnings({"unchecked","rawtypes"})
- final Optional<DataContainerCodecContext<?,?>> augCtx= context.possibleStreamChild((Class) cls);
- if(augCtx.isPresent()) {
+ final Optional<DataContainerCodecContext<?, ?>> augCtx = context.possibleStreamChild((Class) cls);
+ if (augCtx.isPresent()) {
final Optional<NormalizedNode<?, ?>> augData = data.getChild(augCtx.get().getDomPathArgument());
if (augData.isPresent()) {
return augCtx.get().deserialize(augData.get());
return qnameDomValueFromString(codec, schema, (String) defaultValue, schemaContext);
}
return domValueFromString(codec, type, defaultValue);
- } else {
- while (type.getBaseType() != null && type.getDefaultValue() == null) {
- type = type.getBaseType();
- }
+ }
- defaultValue = type.getDefaultValue();
- if (defaultValue != null) {
- if (type instanceof IdentityrefTypeDefinition) {
- return qnameDomValueFromString(codec, schema, (String) defaultValue, schemaContext);
- }
- return domValueFromString(codec, type, defaultValue);
+ while (type.getBaseType() != null && type.getDefaultValue() == null) {
+ type = type.getBaseType();
+ }
+
+ defaultValue = type.getDefaultValue();
+ if (defaultValue != null) {
+ if (type instanceof IdentityrefTypeDefinition) {
+ return qnameDomValueFromString(codec, schema, (String) defaultValue, schemaContext);
}
+ return domValueFromString(codec, type, defaultValue);
}
}
return null;
if (module.getPrefix().equals(defaultValuePrefix)) {
qname = QName.create(module.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
return codec.deserialize(qname);
- } else {
- Set<ModuleImport> imports = module.getImports();
- for (ModuleImport moduleImport : imports) {
- if (moduleImport.getPrefix().equals(defaultValuePrefix)) {
- Module importedModule = schemaContext.findModuleByName(moduleImport.getModuleName(),
- moduleImport.getRevision());
- qname = QName.create(importedModule.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
- return codec.deserialize(qname);
- }
+ }
+
+ Set<ModuleImport> imports = module.getImports();
+ for (ModuleImport moduleImport : imports) {
+ if (moduleImport.getPrefix().equals(defaultValuePrefix)) {
+ Module importedModule = schemaContext.findModuleByName(moduleImport.getModuleName(),
+ moduleImport.getRevision());
+ qname = QName.create(importedModule.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
+ return codec.deserialize(qname);
}
- return null;
}
+ return null;
}
qname = QName.create(schema.getQName(), defaultValue);
}
private static Object domValueFromString(final Codec<Object, Object> codec, final TypeDefinition<?> type,
- final Object defaultValue) {
+ final Object defaultValue) {
TypeDefinitionAwareCodec<?, ?> typeDefAwareCodec = TypeDefinitionAwareCodec.from(type);
if (typeDefAwareCodec != null) {
Object castedDefaultValue = typeDefAwareCodec.deserialize((String) defaultValue);
return this;
}
- final Method getGetter() {
+ Method getGetter() {
return getter;
}
import com.google.common.base.Preconditions;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
}
static void checkModulePresent(final SchemaContext schemaContext, final QName name) {
- if(schemaContext.findModuleByNamespaceAndRevision(name.getNamespace(), name.getRevision()) == null) {
- throw MissingSchemaException.create("Module %s is not present in current schema context.",name.getModule());
+ if (schemaContext.findModuleByNamespaceAndRevision(name.getNamespace(), name.getRevision()) == null) {
+ throw MissingSchemaException.create("Module %s is not present in current schema context.",
+ name.getModule());
}
}
- static void checkModulePresent(final SchemaContext schemaContext, final YangInstanceIdentifier.PathArgument child) {
+ static void checkModulePresent(final SchemaContext schemaContext, final PathArgument child) {
checkModulePresent(schemaContext, extractName(child));
}
private static QName extractName(final PathArgument child) {
- if(child instanceof YangInstanceIdentifier.AugmentationIdentifier) {
- final Set<QName> children = ((YangInstanceIdentifier.AugmentationIdentifier) child).getPossibleChildNames();
+ if (child instanceof AugmentationIdentifier) {
+ final Set<QName> children = ((AugmentationIdentifier) child).getPossibleChildNames();
Preconditions.checkArgument(!children.isEmpty(),"Augmentation without childs must not be used in data");
return children.iterator().next();
}
import org.opendaylight.yangtools.yang.binding.Augmentation;
/**
- * Thrown when Java Binding class was used in data for which codec does not
- * have schema.
+ * Thrown when Java Binding class was used in data for which codec does not have schema.
*
- * By serialization / deserialization of this exception {@link #getBindingClass()}
- * will return null.
+ * <p>
+ * By serialization / deserialization of this exception {@link #getBindingClass()} will return null.
*/
public class MissingSchemaForClassException extends MissingSchemaException {
} else {
schema = runtimeContext.getSchemaDefinition(bindingClass);
}
- if(schema == null) {
+ if (schema == null) {
throw MissingSchemaForClassException.forClass(bindingClass);
}
}
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
/**
- * Location specific context for schema nodes, which contains codec specific
- * information to properly serialize / deserialize from Java YANG Binding data
- * to NormalizedNode data.
+ * Location specific context for schema nodes, which contains codec specific information to properly serialize
+ * and deserialize from Java YANG Binding data to NormalizedNode data.
*
+ * <p>
* Two core subtypes of codec context are available:
* <ul>
- * <li>{@link LeafNodeCodecContext} - Context for nodes, which does not contain
- * any nested YANG modeled substructures.</li>
- * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain
- * nested YANG modeled substructures. This context nodes contains context
- * for children nodes.</li>
+ * <li>{@link LeafNodeCodecContext} - Context for nodes, which does not contain any nested YANG modeled substructures.
+ * </li>
+ * <li>{@link DataObjectCodecContext} - Context for nodes, which does contain nested YANG modeled substructures. This
+ * context nodes contains context for children nodes.</li>
* </ul>
*/
abstract class NodeCodecContext<D extends DataObject> implements BindingCodecTreeNode<D> {
/**
- * Returns Yang Instance Identifier Path Argument of current node
+ * Returns Yang Instance Identifier Path Argument of current node.
*
* @return DOM Path Argument of node
*/
protected abstract YangInstanceIdentifier.PathArgument getDomPathArgument();
/**
+ * Immutable factory, which provides access to runtime context, create leaf nodes and provides path argument codecs.
*
- * Immutable factory, which provides access to runtime context,
- * create leaf nodes and provides path argument codecs.
* <p>
- * During lifetime of factory all calls for same arguments to method must return
- * equal result (not necessary same instance of result).
- *
+ * During lifetime of factory all calls for same arguments to method must return equal result (not necessary same
+ * instance of result).
*/
protected interface CodecContextFactory {
/**
* Returns immutable runtime context associated with this factory.
+ *
* @return runtime context
*/
BindingRuntimeContext getRuntimeContext();
ImmutableMap<String, LeafNodeCodecContext<?>> getLeafNodes(Class<?> type, DataNodeContainer schema);
/**
- * Returns Path argument codec for list item
+ * Returns Path argument codec for list item.
*
* @param type Type of list item
* @param schema Schema of list item
}
/**
- *
- * Serializes supplied Binding Path Argument
- * and adds all necessary YANG instance identifiers to supplied list.
+ * Serializes supplied Binding Path Argument and adds all necessary YANG instance identifiers to supplied list.
*
* @param arg Binding Path Argument
* @param builder DOM Path argument.
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-final class NotificationCodecContext<D extends DataObject & Notification> extends DataObjectCodecContext<D,NotificationDefinition> {
+final class NotificationCodecContext<D extends DataObject & Notification>
+ extends DataObjectCodecContext<D, NotificationDefinition> {
- public NotificationCodecContext(final Class<?> key, final NotificationDefinition schema, final CodecContextFactory factory) {
+ NotificationCodecContext(final Class<?> key, final NotificationDefinition schema,
+ final CodecContextFactory factory) {
super(DataContainerCodecPrototype.from(key, schema, factory));
}
* {@link UnmappedRpcInputCodec} and {@link ContainerNodeCodecContext}, which results in bimorphic invocation in
* {@link BindingNormalizedNodeCodecRegistry#fromNormalizedNodeRpcData()}.
*
+ * <p>
* Without this interface we could end up with megamorphic invocation, as the two implementations cannot share class
* hierarchy.
*
@Override
public RpcInputCodec load(final SchemaPath key) {
final ContainerSchemaNode schema = SchemaContextUtil.getRpcDataSchema(getSchema(), key);
- if (schema instanceof EffectiveStatement &&
- ((EffectiveStatement) schema).getDeclared().getStatementSource() != StatementSource.DECLARATION) {
+ if (schema instanceof EffectiveStatement
+ && ((EffectiveStatement) schema).getDeclared().getStatementSource()
+ != StatementSource.DECLARATION) {
// This is an implicitly-defined input or output statement. We do not have a corresponding
// data representation, so we hard-wire it to null.
return UnmappedRpcInputCodec.getInstance();
*
* @param factory
* CodecContextFactory
- * @return
+ * @return A new root node
*/
static SchemaRootCodecContext<?> create(final CodecContextFactory factory) {
final DataContainerCodecPrototype<SchemaContext> prototype = DataContainerCodecPrototype.rootPrototype(factory);
@SuppressWarnings("unchecked")
@Override
- public <DV extends DataObject> DataContainerCodecContext<DV, ?> streamChild(final Class<DV> childClass)
- throws IllegalArgumentException {
+ public <C extends DataObject> DataContainerCodecContext<C, ?> streamChild(final Class<C> childClass) {
/* FIXME: This is still not solved for RPCs
* TODO: Probably performance wise RPC, Data and Notification loading cache
* should be merge for performance resons. Needs microbenchmark to
* determine which is faster (keeping them separate or in same cache).
*/
if (Notification.class.isAssignableFrom(childClass)) {
- return (DataContainerCodecContext<DV, ?>) getNotification((Class<? extends Notification>)childClass);
+ return (DataContainerCodecContext<C, ?>) getNotification((Class<? extends Notification>)childClass);
}
- return (DataContainerCodecContext<DV, ?>) getOrRethrow(childrenByClass,childClass);
+ return (DataContainerCodecContext<C, ?>) getOrRethrow(childrenByClass,childClass);
}
@Override
- public <E extends DataObject> Optional<DataContainerCodecContext<E,?>> possibleStreamChild(final Class<E> childClass) {
+ public <C extends DataObject> Optional<DataContainerCodecContext<C, ?>> possibleStreamChild(
+ final Class<C> childClass) {
throw new UnsupportedOperationException("Not supported");
}
@Override
public DataContainerCodecContext<?,?> yangPathArgumentChild(final PathArgument arg) {
- return getOrRethrow(childrenByQName,arg.getNodeType());
+ return getOrRethrow(childrenByQName, arg.getNodeType());
}
@Override
public D deserialize(final NormalizedNode<?, ?> normalizedNode) {
- throw new UnsupportedOperationException(
- "Could not create Binding data representation for root");
- }
-
-
- ContainerNodeCodecContext<?> getRpc(final Class<? extends DataContainer> rpcInputOrOutput) {
- return getOrRethrow(rpcDataByClass, rpcInputOrOutput);
+ throw new UnsupportedOperationException("Could not create Binding data representation for root");
}
NotificationCodecContext<?> getNotification(final Class<? extends Notification> notification) {
return getOrRethrow(notificationsByPath, notification);
}
+ ContainerNodeCodecContext<?> getRpc(final Class<? extends DataContainer> rpcInputOrOutput) {
+ return getOrRethrow(rpcDataByClass, rpcInputOrOutput);
+ }
+
RpcInputCodec<?> getRpc(final SchemaPath notification) {
return getOrRethrow(rpcDataByPath, notification);
}
private DataContainerCodecContext<?,?> createDataTreeChildContext(final Class<?> key) {
final QName qname = BindingReflections.findQName(key);
- final DataSchemaNode childSchema = childNonNull(getSchema().getDataChildByName(qname),key,"%s is not top-level item.",key);
+ final DataSchemaNode childSchema = childNonNull(getSchema().getDataChildByName(qname), key,
+ "%s is not top-level item.", key);
return DataContainerCodecPrototype.from(key, childSchema, factory()).get();
}
* - union values
* @param subtype
* - subtype of union
- * @throws NoSuchMethodException
+ * @throws NoSuchMethodException when the getter method is not found
*/
private static void addLeafrefValueCodec(final Class<?> unionCls, final UnionTypeDefinition unionType,
final BindingCodecContext bindingCodecContext, final Set<UnionValueOptionContext> values,
private final MethodHandle getter;
private final MethodHandle unionCtor;
- UnionValueOptionContext(final Class<?> unionType, final Class<?> valueType, final Method getter, final Codec<Object, Object> codec) {
+ UnionValueOptionContext(final Class<?> unionType, final Class<?> valueType, final Method getter,
+ final Codec<Object, Object> codec) {
this.bindingType = Preconditions.checkNotNull(valueType);
this.codec = Preconditions.checkNotNull(codec);
return baValue == null ? null : codec.serialize(baValue);
}
+ @SuppressWarnings("checkstyle:illegalCatch")
Object deserializeUnion(final Object input) {
// Side-step potential exceptions by checking the type if it is available
if (codec instanceof EncapsulatedValueCodec && !((EncapsulatedValueCodec) codec).canAcceptObject(input)) {
}
}
+ @SuppressWarnings("checkstyle:illegalCatch")
Object getValueFrom(final Object input) {
try {
return getter.invokeExact(input);
private final Class<?> identifier;
private final String getterName;
- ValueContext(final Class<?> identifier, final LeafNodeCodecContext <?>leaf) {
+ ValueContext(final Class<?> identifier, final LeafNodeCodecContext<?> leaf) {
getterName = leaf.getGetter().getName();
try {
getter = MethodHandles.publicLookup().unreflect(identifier.getMethod(getterName)).asType(OBJECT_METHOD);
} catch (IllegalAccessException | NoSuchMethodException | SecurityException e) {
- throw new IllegalStateException(String.format("Cannot find method %s in class %s", getterName, identifier), e);
+ throw new IllegalStateException(String.format("Cannot find method %s in class %s", getterName, identifier),
+ e);
}
this.identifier = identifier;
codec = leaf.getValueCodec();
}
+ @SuppressWarnings("checkstyle:illegalCatch")
Object getAndSerialize(final Object obj) {
final Object value;
try {
*/
abstract class ValueTypeCodec implements Codec<Object, Object> {
- private static final Cache<Class<?>, SchemaUnawareCodec> staticCodecs = CacheBuilder.newBuilder().weakKeys()
+ private static final Cache<Class<?>, SchemaUnawareCodec> STATIC_CODECS = CacheBuilder.newBuilder().weakKeys()
.build();
-
/**
- * Marker interface for codecs, which functionality will not be
- * affected by schema change (introduction of new YANG modules)
- * they may have one static instance generated when
- * first time needed.
- *
+ * Marker interface for codecs, which functionality will not be affected by schema change (introduction of new YANG
+ * modules) they may have one static instance generated when first time needed.
*/
interface SchemaUnawareCodec extends Codec<Object,Object> {
}
-
/**
- *
- * No-op Codec, Java YANG Binding uses same types as NormalizedNode model
- * for base YANG types, representing numbers, binary and strings.
- *
- *
+ * No-op Codec, Java YANG Binding uses same types as NormalizedNode model for base YANG types, representing numbers,
+ * binary and strings.
*/
public static final SchemaUnawareCodec NOOP_CODEC = new SchemaUnawareCodec() {
public static final SchemaUnawareCodec EMPTY_CODEC = new SchemaUnawareCodec() {
@Override
- public Object serialize(final Object arg0) {
- // Empty type has null value in NormalizedNode and Composite Node
- // representation
+ public Object serialize(final Object input) {
+ // Empty type has null value in NormalizedNode and Composite Node representation
return null;
}
@Override
- public Object deserialize(final Object arg0) {
- /* Empty type has boolean.TRUE representation in Binding-aware world
- * otherwise it is null / false.
- * So when codec is triggered, empty leaf is present, that means we
- * are safe to return true.
- */
+ public Object deserialize(final Object input) {
+ /* Empty type has boolean.TRUE representation in Binding-aware world otherwise it is null / false.
+ * So when codec is triggered, empty leaf is present, that means we are safe to return true.
+ */
return Boolean.TRUE;
}
};
return def instanceof EmptyTypeDefinition ? EMPTY_CODEC : NOOP_CODEC;
}
- private static SchemaUnawareCodec getCachedSchemaUnawareCodec(final Class<?> typeClz, final Callable<? extends SchemaUnawareCodec> loader) {
+ private static SchemaUnawareCodec getCachedSchemaUnawareCodec(final Class<?> typeClz,
+ final Callable<? extends SchemaUnawareCodec> loader) {
try {
- return staticCodecs.get(typeClz, loader);
+ return STATIC_CODECS.get(typeClz, loader);
} catch (ExecutionException e) {
throw new IllegalStateException(e);
}
}
- private static Callable<? extends SchemaUnawareCodec> getCodecLoader(final Class<?> typeClz, final TypeDefinition<?> def) {
+ private static Callable<? extends SchemaUnawareCodec> getCodecLoader(final Class<?> typeClz,
+ final TypeDefinition<?> def) {
TypeDefinition<?> rootType = def;
while (rootType.getBaseType() != null) {
* value, which effectively could be used to remove augmentation
* from builder / DTO.
*/
- if(value == null) {
+ if (value == null) {
return;
}
Preconditions.checkArgument(value instanceof DataObject);
import org.opendaylight.yangtools.yang.binding.Augmentation;
/**
- * Interface which sould be implemented by proxy {@link java.lang.reflect.InvocationHandler}
- * to obtain augmentations from proxy implementations of {@link org.opendaylight.yangtools.yang.binding.Augmentable}
- * object.
+ * Interface which sould be implemented by proxy {@link java.lang.reflect.InvocationHandler} to obtain augmentations
+ * from proxy implementations of {@link org.opendaylight.yangtools.yang.binding.Augmentable} object.
*
- * If implemented proxy does not implement this interface, its augmentations are not
- * properly serialized / deserialized.
+ * <p>
+ * If implemented proxy does not implement this interface, its augmentations are not properly serialized / deserialized.
*/
public interface AugmentationReader {
return new ChoiceDispatchSerializer(choiceClass);
}
- @SuppressWarnings("unchecked")
@Override
- public void serialize(final DataObjectSerializerRegistry reg, final DataObject obj, final BindingStreamEventWriter stream) throws IOException {
+ @SuppressWarnings("unchecked")
+ public void serialize(final DataObjectSerializerRegistry reg, final DataObject obj,
+ final BindingStreamEventWriter stream) throws IOException {
@SuppressWarnings("rawtypes")
Class cazeClass = obj.getImplementedInterface();
stream.startChoiceNode(choiceClass, BindingStreamEventWriter.UNKNOWN_SIZE);
}
protected static final class TestDataObject1 {
- public void foo() {}
+ public void foo() {
+
+ }
}
protected static final class TestDataObject2 {
- public void foo() {}
+ public void foo() {
+
+ }
}
public static final class TestUnion {
- public TestUnion(final TestDataObject1 arg) { }
- public TestUnion(final TestDataObject2 arg) { }
- }
+ public TestUnion(final TestDataObject1 arg) {
+ }
+
+ public TestUnion(final TestDataObject2 arg) {
+
+ }
+ }
}
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
- * This sets of tests are designed in way, that schema context contains models for all
- * augmentations, but backing class loading strategy is not aware of some of the classes, and
- * becames aware of them after codec was used.
+ * This sets of tests are designed in way, that schema context contains models for all augmentations, but backing class
+ * loading strategy is not aware of some of the classes, and becames aware of them after codec was used.
*
- * Idea of this suite is to test that codecs will work even if situation like this happens.
+ * <p>
+ * The idea of this suite is to test that codecs will work even if situation like this happens.
*/
public class AugmentationClassDiscoveredAfterCodecTest {
.build();
final TopLevelList baTree = new TopLevelListBuilder()
.setKey(TOP_FOO_KEY)
- .addAugmentation(TreeComplexUsesAugment.class, new TreeComplexUsesAugmentBuilder(createComplexData()).build())
+ .addAugmentation(TreeComplexUsesAugment.class, new TreeComplexUsesAugmentBuilder(createComplexData())
+ .build())
.build();
final NormalizedNode<?, ?> domTreeEntry = registry.toNormalizedNode(BA_TOP_LEVEL_LIST, baTree).getValue();
final NormalizedNode<?, ?> domRpcEntry = registry.toNormalizedNode(BA_TOP_LEVEL_LIST, baRpc).getValue();
public void copyBuilderWithAugmenationsTest() {
final TopLevelList manuallyConstructed = new TopLevelListBuilder()
.setKey(TOP_FOO_KEY)
- .addAugmentation(TreeComplexUsesAugment.class, new TreeComplexUsesAugmentBuilder(createComplexData()).build())
+ .addAugmentation(TreeComplexUsesAugment.class, new TreeComplexUsesAugmentBuilder(createComplexData())
+ .build())
.build();
- final NormalizedNode<?, ?> domTreeEntry = registry.toNormalizedNode(BA_TOP_LEVEL_LIST, manuallyConstructed).getValue();
- final TopLevelList deserialized = registry.deserializeFunction(BA_TOP_LEVEL_LIST).apply(Optional.<NormalizedNode<?, ?>>of(domTreeEntry)).get();
+ final NormalizedNode<?, ?> domTreeEntry = registry.toNormalizedNode(BA_TOP_LEVEL_LIST, manuallyConstructed)
+ .getValue();
+ final TopLevelList deserialized = registry.deserializeFunction(BA_TOP_LEVEL_LIST)
+ .apply(Optional.of(domTreeEntry)).get();
assertEquals(manuallyConstructed, deserialized);
final TopLevelList copiedFromDeserialized = new TopLevelListBuilder(deserialized).build();
assertEquals(manuallyConstructed, copiedFromDeserialized);
private static RpcComplexUsesAugment createComplexData() {
return new RpcComplexUsesAugmentBuilder()
- .setContainerWithUses(new ContainerWithUsesBuilder()
- .setLeafFromGrouping("foo")
- .build())
- .setListViaUses(Collections.<ListViaUses>emptyList())
- .build();
+ .setContainerWithUses(new ContainerWithUsesBuilder()
+ .setLeafFromGrouping("foo")
+ .build())
+ .setListViaUses(Collections.<ListViaUses>emptyList())
+ .build();
}
-
}
private BinaryList process(final BinaryList binaryList) {
final NormalizedNode<?, ?> domTreeEntry = registry.toNormalizedNode(instanceIdentifier, binaryList).getValue();
- return registry.deserializeFunction(instanceIdentifier).apply(Optional.<NormalizedNode<?, ?>>of(domTreeEntry)).get();
+ return registry.deserializeFunction(instanceIdentifier).apply(Optional.of(domTreeEntry)).get();
}
}
\ No newline at end of file
.setKey(TOP_FOO_KEY)
.setChoiceInList(new EmptyLeafBuilder().setEmptyType(true).build())
.build();
- final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> dom = registry.toNormalizedNode(BA_TOP_LEVEL_LIST, withEmptyCase);
- final Entry<InstanceIdentifier<?>, DataObject> readed = registry.fromNormalizedNode(dom.getKey(),dom.getValue());
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> dom = registry.toNormalizedNode(BA_TOP_LEVEL_LIST,
+ withEmptyCase);
+ final Entry<InstanceIdentifier<?>, DataObject> readed = registry.fromNormalizedNode(dom.getKey(),
+ dom.getValue());
final ChoiceInList list = ((TopLevelList) readed.getValue()).getChoiceInList();
assertTrue(list instanceof EmptyLeaf);
assertTrue(((EmptyLeaf) list).isEmptyType());
private static final QName TOP_QNAME = Top.QNAME;
private static final YangInstanceIdentifier BI_TOP_PATH = YangInstanceIdentifier.builder().node(TOP_QNAME).build();
- private static final YangInstanceIdentifier BI_TREE_LEAF_ONLY = FULL_CODEC.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY);
+ private static final YangInstanceIdentifier BI_TREE_LEAF_ONLY = FULL_CODEC.toYangInstanceIdentifier(
+ BA_TREE_LEAF_ONLY);
-
- @Test(expected=MissingSchemaException.class)
+ @Test(expected = MissingSchemaException.class)
public void testDOMTop() {
CODEC_WITHOUT_TOP.fromYangInstanceIdentifier(BI_TOP_PATH);
}
- @Test(expected=MissingSchemaException.class)
+ @Test(expected = MissingSchemaException.class)
public void testDOMAugment() {
CODEC_WITHOUT_TOP.fromYangInstanceIdentifier(BI_TREE_LEAF_ONLY);
}
- @Test(expected=MissingSchemaForClassException.class)
+ @Test(expected = MissingSchemaForClassException.class)
public void testBindingTop() {
CODEC_WITHOUT_TOP.toYangInstanceIdentifier(BA_TOP_LEVEL_LIST);
}
- @Test(expected=MissingSchemaForClassException.class)
+ @Test(expected = MissingSchemaForClassException.class)
public void testBindingAugment() {
ONLY_TOP_CODEC.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY);
}
- @Test(expected=IncorrectNestingException.class)
+ @Test(expected = IncorrectNestingException.class)
public void testBindingSkippedRoot() {
FULL_CODEC.toYangInstanceIdentifier(InstanceIdentifier.create(TopLevelList.class));
}
@SuppressWarnings({"unchecked", "rawtypes"})
- @Test(expected=IncorrectNestingException.class)
+ @Test(expected = IncorrectNestingException.class)
public void testBindingIncorrectAugment() {
- FULL_CODEC.toYangInstanceIdentifier(InstanceIdentifier.create(Top.class).augmentation((Class) TreeComplexUsesAugment.class));
+ FULL_CODEC.toYangInstanceIdentifier(InstanceIdentifier.create(Top.class).augmentation(
+ (Class) TreeComplexUsesAugment.class));
}
-
+ @SuppressWarnings("checkstyle:illegalCatch")
private static BindingNormalizedNodeCodecRegistry codec(final Class<?>... classes) {
final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create();
- for(final Class<?> clazz : classes) {
+ for (final Class<?> clazz : classes) {
YangModuleInfo modInfo;
try {
modInfo = BindingReflections.getModuleInfo(clazz);
final SchemaContext schema = ctx.tryToCreateSchemaContext().get();
final BindingRuntimeContext runtimeCtx = BindingRuntimeContext.create(ctx, schema);
final JavassistUtils utils = JavassistUtils.forClassPool(ClassPool.getDefault());
- final BindingNormalizedNodeCodecRegistry registry = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(utils));
+ final BindingNormalizedNodeCodecRegistry registry = new BindingNormalizedNodeCodecRegistry(
+ StreamWriterGenerator.create(utils));
registry.onBindingRuntimeContextUpdated(runtimeCtx);
return registry;
}
-
}
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-public class InstanceIdentifierSerializeDeserializeTest extends AbstractBindingRuntimeTest{
+public class InstanceIdentifierSerializeDeserializeTest extends AbstractBindingRuntimeTest {
public static final String TOP_LEVEL_LIST_KEY_VALUE = "foo";
private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
public static final QName TOP_LEVEL_LIST_KEY = QName.create(TOP_QNAME, "name");
private static final QName SIMPLE_VALUE_QNAME = QName.create(TreeComplexUsesAugment.QNAME, "simple-value");
- public static final YangInstanceIdentifier BI_TOP_PATH = YangInstanceIdentifier.builder().node(TOP_QNAME).build();
+ public static final YangInstanceIdentifier BI_TOP_PATH = YangInstanceIdentifier.of(TOP_QNAME);
public static final YangInstanceIdentifier BI_TOP_LEVEL_LIST_PATH = BI_TOP_PATH.node(TOP_LEVEL_LIST_QNAME);
public static final YangInstanceIdentifier BI_TOP_LEVEL_LIST_1_PATH = BI_TOP_LEVEL_LIST_PATH
- .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY, TOP_LEVEL_LIST_KEY_VALUE));
+ .node(new NodeIdentifierWithPredicates(TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY,
+ TOP_LEVEL_LIST_KEY_VALUE));
private BindingNormalizedNodeCodecRegistry registry;
public void testBindingAwareIIToYangIContainer() {
final YangInstanceIdentifier yangInstanceIdentifier = registry.toYangInstanceIdentifier(
InstanceIdentifier.create(Top.class).child(TopLevelList.class));
- final YangInstanceIdentifier.PathArgument lastPathArgument = yangInstanceIdentifier.getLastPathArgument();
- assertTrue(lastPathArgument instanceof YangInstanceIdentifier.NodeIdentifier);
+ final PathArgument lastPathArgument = yangInstanceIdentifier.getLastPathArgument();
+ assertTrue(lastPathArgument instanceof NodeIdentifier);
assertEquals(TopLevelList.QNAME, lastPathArgument.getNodeType());
}
public void testBindingAwareIIToYangIIWildcard() {
final YangInstanceIdentifier yangInstanceIdentifier = registry.toYangInstanceIdentifier(
InstanceIdentifier.create(Top.class).child(TopLevelList.class));
- final YangInstanceIdentifier.PathArgument lastPathArgument = yangInstanceIdentifier.getLastPathArgument();
- assertTrue(lastPathArgument instanceof YangInstanceIdentifier.NodeIdentifier);
+ final PathArgument lastPathArgument = yangInstanceIdentifier.getLastPathArgument();
+ assertTrue(lastPathArgument instanceof NodeIdentifier);
assertEquals(TopLevelList.QNAME, lastPathArgument.getNodeType());
}
public void testBindingAwareIIToYangIIListWithKey() {
final YangInstanceIdentifier yangInstanceIdentifier = registry.toYangInstanceIdentifier(
InstanceIdentifier.create(Top.class).child(TopLevelList.class, TOP_FOO_KEY));
- final YangInstanceIdentifier.PathArgument lastPathArgument = yangInstanceIdentifier.getLastPathArgument();
- assertTrue(lastPathArgument instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates);
- assertTrue(((YangInstanceIdentifier.NodeIdentifierWithPredicates) lastPathArgument).getKeyValues().containsValue(TOP_LEVEL_LIST_KEY_VALUE));
+ final PathArgument lastPathArgument = yangInstanceIdentifier.getLastPathArgument();
+ assertTrue(lastPathArgument instanceof NodeIdentifierWithPredicates);
+ assertTrue(((NodeIdentifierWithPredicates) lastPathArgument).getKeyValues().containsValue(
+ TOP_LEVEL_LIST_KEY_VALUE));
assertEquals(TopLevelList.QNAME, lastPathArgument.getNodeType());
}
@Test
public void testBindingAwareIIToYangIIAugmentation() {
- final YangInstanceIdentifier.PathArgument lastArg = registry.toYangInstanceIdentifier(BA_TREE_COMPLEX_USES).getLastPathArgument();
- assertTrue(lastArg instanceof YangInstanceIdentifier.AugmentationIdentifier);
+ final PathArgument lastArg = registry.toYangInstanceIdentifier(BA_TREE_COMPLEX_USES).getLastPathArgument();
+ assertTrue(lastArg instanceof AugmentationIdentifier);
}
@Test
public void testBindingAwareIIToYangIILeafOnlyAugmentation() {
- final YangInstanceIdentifier.PathArgument leafOnlyLastArg = registry.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY).getLastPathArgument();
- assertTrue(leafOnlyLastArg instanceof YangInstanceIdentifier.AugmentationIdentifier);
- assertTrue(((YangInstanceIdentifier.AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
+ final PathArgument leafOnlyLastArg = registry.toYangInstanceIdentifier(BA_TREE_LEAF_ONLY).getLastPathArgument();
+ assertTrue(leafOnlyLastArg instanceof AugmentationIdentifier);
+ assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
}
}
.setSimpleTypeRef(10)
.setSchemaUnawareUnion(new Int32StringUnion("foo"))
.setSchemaUnawareUnionRef(new Int32StringUnion(10))
- .build();
- final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> dom = registry.toNormalizedNode(BA_TOP_LEVEL_LIST, binding);
- final Entry<InstanceIdentifier<?>, DataObject> readed = registry.fromNormalizedNode(dom.getKey(),dom.getValue());
+ .build();
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> dom = registry.toNormalizedNode(BA_TOP_LEVEL_LIST,
+ binding);
+ final Entry<InstanceIdentifier<?>, DataObject> readed = registry.fromNormalizedNode(dom.getKey(),
+ dom.getValue());
final TreeComplexLeaves readedAugment = (TreeComplexLeaves) readed.getValue();
assertEquals(binding,readedAugment);
-
}
-
-
-
}
assertNotNull(fromYangInstanceIdentifier);
final InstanceIdentifier<ContInt32> BA_II_CONT = InstanceIdentifier.builder(ContInt32.class).build();
- final RefUnionInt32 refVal = new RefUnionInt32(5l);
+ final RefUnionInt32 refVal = new RefUnionInt32(5L);
final ContInt32 data = new ContInt32Builder().setRefUnionInt32(refVal).build();
final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalizedNode =
this.registry.toNormalizedNode(BA_II_CONT, data);
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import javassist.ClassPool;
import org.junit.Before;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
-public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRuntimeTest{
+public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRuntimeTest {
public static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
public static final TopLevelListKey TOP_LEVEL_LIST_FOO_KEY = new TopLevelListKey(TOP_LEVEL_LIST_FOO_KEY_VALUE);
public static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
public static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
public static final QName TOP_LEVEL_LEAF_LIST_QNAME = QName.create(TOP_QNAME, "top-level-leaf-list");
- public static final QName TOP_LEVEL_ORDERED_LEAF_LIST_QNAME = QName.create(TOP_QNAME, "top-level-ordered-leaf-list");
+ public static final QName TOP_LEVEL_ORDERED_LEAF_LIST_QNAME = QName.create(TOP_QNAME,
+ "top-level-ordered-leaf-list");
public static final QName NESTED_LIST_QNAME = QName.create(TOP_QNAME, "nested-list");
public static final QName NESTED_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
public static final QName CHOICE_CONTAINER_QNAME = ChoiceContainer.QNAME;
public static final YangInstanceIdentifier BI_TOP_PATH = YangInstanceIdentifier.of(TOP_QNAME);
public static final YangInstanceIdentifier BI_TOP_LEVEL_LIST_PATH = BI_TOP_PATH.node(TOP_LEVEL_LIST_QNAME);
public static final YangInstanceIdentifier BI_TOP_LEVEL_LIST_FOO_PATH = BI_TOP_LEVEL_LIST_PATH
- .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE));
- public static final YangInstanceIdentifier BI_CHOICE_CONTAINER_PATH = YangInstanceIdentifier.of(CHOICE_CONTAINER_QNAME);
+ .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(TOP_LEVEL_LIST_QNAME,
+ TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE));
+ public static final YangInstanceIdentifier BI_CHOICE_CONTAINER_PATH = YangInstanceIdentifier.of(
+ CHOICE_CONTAINER_QNAME);
private BindingNormalizedNodeCodecRegistry registry;
@Test
public void containerToNormalized() {
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
- registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top());
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(
+ InstanceIdentifier.create(Top.class), top());
final ContainerNode topNormalized = getEmptyTop();
assertEquals(topNormalized, entry.getValue());
}
@Test
public void containerFromNormalized() {
final ContainerNode topNormalized = getEmptyTop();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topNormalized);
+ final Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topNormalized);
assertEquals(top(), entry.getValue());
}
private static ContainerNode getEmptyTop() {
return ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
+ .withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
.withChild(mapNodeBuilder(TOP_LEVEL_LIST_QNAME).build()).build();
}
public void equalsWithAugment() {
final ContainerNode topNormalizedWithAugments = getNormalizedTopWithAugments(
augmentationBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(singleton(AGUMENT_STRING_Q)))
+ .withNodeIdentifier(new AugmentationIdentifier(singleton(AGUMENT_STRING_Q)))
.withChild(ImmutableNodes.leafNode(AGUMENT_STRING_Q, AUGMENT_STRING_VALUE))
.build());
final ContainerNode topNormalized = getEmptyTop();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topNormalized);
- final Map.Entry<InstanceIdentifier<?>, DataObject> entryWithAugments = registry.fromNormalizedNode(BI_TOP_PATH, topNormalizedWithAugments);
+ final Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topNormalized);
+ final Entry<InstanceIdentifier<?>, DataObject> entryWithAugments = registry.fromNormalizedNode(BI_TOP_PATH,
+ topNormalizedWithAugments);
// Equals on other with no augmentation should be false
assertNotEquals(top(), entryWithAugments.getValue());
// Equals on self should be true
assertEquals(entryWithAugments.getValue(), entryWithAugments.getValue());
- final Top topWithAugmentsDiffValue = topWithAugments(Collections.<Class<? extends Augmentation<Top>>, Augmentation<Top>>
- singletonMap(Top1.class, new Top1Builder().setAugmentedString("differentValue").build()));
+ final Top topWithAugmentsDiffValue = topWithAugments(
+ Collections.<Class<? extends Augmentation<Top>>, Augmentation<Top>>singletonMap(Top1.class,
+ new Top1Builder().setAugmentedString("differentValue").build()));
assertNotEquals(topWithAugmentsDiffValue, entryWithAugments.getValue());
assertNotEquals(entryWithAugments.getValue(), topWithAugmentsDiffValue);
}
public void equalsWithMultipleAugments() {
final ContainerNode topNormalizedWithAugments = getNormalizedTopWithAugments(
augmentationBuilder()
- .withNodeIdentifier(
- new YangInstanceIdentifier.AugmentationIdentifier(singleton(AGUMENT_STRING_Q)))
+ .withNodeIdentifier(new AugmentationIdentifier(singleton(AGUMENT_STRING_Q)))
.withChild(ImmutableNodes.leafNode(AGUMENT_STRING_Q, AUGMENT_STRING_VALUE))
.build(),
augmentationBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(singleton(AUGMENT_INT_Q)))
+ .withNodeIdentifier(new AugmentationIdentifier(singleton(AUGMENT_INT_Q)))
.withChild(ImmutableNodes.leafNode(AUGMENT_INT_Q, AUGMENT_INT_VALUE))
.build());
- final Map.Entry<InstanceIdentifier<?>, DataObject> entryWithAugments = registry.fromNormalizedNode(BI_TOP_PATH, topNormalizedWithAugments);
+ final Entry<InstanceIdentifier<?>, DataObject> entryWithAugments = registry.fromNormalizedNode(BI_TOP_PATH,
+ topNormalizedWithAugments);
Map<Class<? extends Augmentation<Top>>, Augmentation<Top>> augments = Maps.newHashMap();
augments.put(Top1.class, new Top1Builder().setAugmentedString(AUGMENT_STRING_VALUE).build());
augments.put(Top2.class, new Top2Builder().setAugmentedInt(AUGMENT_INT_VALUE).build());
}
private static ContainerNode getNormalizedTopWithAugments(final AugmentationNode... augChild) {
- final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode>
- builder = ImmutableContainerNodeBuilder.create();
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder =
+ ImmutableContainerNodeBuilder.create();
for (AugmentationNode augmentationNode : augChild) {
builder.withChild(augmentationNode);
}
- return builder.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
+ return builder.withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
.withChild(mapNodeBuilder(TOP_LEVEL_LIST_QNAME).build()).build();
}
- private static Top topWithAugments(final Map<Class<? extends Augmentation<Top>>, ? extends Augmentation<Top>> augments) {
+ private static Top topWithAugments(
+ final Map<Class<? extends Augmentation<Top>>, ? extends Augmentation<Top>> augments) {
final TopBuilder topBuilder = new TopBuilder();
- for (Map.Entry<Class<? extends Augmentation<Top>>, ? extends Augmentation<Top>> augment : augments.entrySet()) {
+ for (Entry<Class<? extends Augmentation<Top>>, ? extends Augmentation<Top>> augment : augments.entrySet()) {
topBuilder.addAugmentation(augment.getKey(), augment.getValue());
}
return topBuilder.setTopLevelList(Collections.<TopLevelList>emptyList()).build();
@Test
public void listWithKeysToNormalized() {
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
- registry.toNormalizedNode(BA_TOP_LEVEL_LIST, topLevelList(TOP_LEVEL_LIST_FOO_KEY));
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(BA_TOP_LEVEL_LIST,
+ topLevelList(TOP_LEVEL_LIST_FOO_KEY));
final MapEntryNode topLevelListNormalized = ImmutableMapEntryNodeBuilder.create()
- .withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifierWithPredicates(
- TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
+ .withNodeIdentifier(new NodeIdentifierWithPredicates(TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME,
+ TOP_LEVEL_LIST_FOO_KEY_VALUE))
.withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
.build();
assertEquals(topLevelListNormalized, entry.getValue());
@Test
public void listWithKeysFromNormalized() {
final MapEntryNode topLevelListNormalized = ImmutableMapEntryNodeBuilder.create()
- .withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifierWithPredicates(
- TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
+ .withNodeIdentifier(new NodeIdentifierWithPredicates(TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME,
+ TOP_LEVEL_LIST_FOO_KEY_VALUE))
.withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
.build();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entry =
- registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH, topLevelListNormalized);
+ final Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH,
+ topLevelListNormalized);
assertEquals(topLevelList(TOP_LEVEL_LIST_FOO_KEY), entry.getValue());
}
@Test
public void leafOnlyAugmentationToNormalized() {
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
- registry.toNormalizedNode(BA_TREE_LEAF_ONLY, new TreeLeafOnlyAugmentBuilder().setSimpleValue("simpleValue").build());
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(BA_TREE_LEAF_ONLY,
+ new TreeLeafOnlyAugmentBuilder().setSimpleValue("simpleValue").build());
final Set<QName> augmentationChildren = new HashSet<>();
augmentationChildren.add(SIMPLE_VALUE_QNAME);
final AugmentationNode augmentationNode = ImmutableAugmentationNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(augmentationChildren))
+ .withNodeIdentifier(new AugmentationIdentifier(augmentationChildren))
.withChild(leafNode(SIMPLE_VALUE_QNAME, "simpleValue"))
.build();
assertEquals(augmentationNode, entry.getValue());
final Set<QName> augmentationChildren = new HashSet<>();
augmentationChildren.add(SIMPLE_VALUE_QNAME);
final AugmentationNode augmentationNode = ImmutableAugmentationNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(augmentationChildren))
+ .withNodeIdentifier(new AugmentationIdentifier(augmentationChildren))
.withChild(leafNode(SIMPLE_VALUE_QNAME, "simpleValue"))
.build();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH.node(
- new YangInstanceIdentifier.AugmentationIdentifier(augmentationChildren)), augmentationNode);
+ final Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(
+ BI_TOP_LEVEL_LIST_FOO_PATH.node(new AugmentationIdentifier(augmentationChildren)),
+ augmentationNode);
assertEquals(new TreeLeafOnlyAugmentBuilder().setSimpleValue("simpleValue").build(), entry.getValue());
}
topLevelLeafList.add("foo");
Top top = new TopBuilder().setTopLevelOrderedLeafList(topLevelLeafList).build();
- Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
- registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top);
+ Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(
+ InstanceIdentifier.create(Top.class), top);
ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
+ .withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
.withChild(ImmutableOrderedLeafSetNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME))
+ .withNodeIdentifier(new NodeIdentifier(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME))
.withChild(
ImmutableLeafSetEntryNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue<>(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME, "foo"))
+ .withNodeIdentifier(new NodeWithValue<>(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME,
+ "foo"))
.withValue("foo")
.build())
.build())
topLevelLeafList.add("foo");
final Top top = new TopBuilder().setTopLevelLeafList(topLevelLeafList).build();
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
- registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top);
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(
+ InstanceIdentifier.create(Top.class), top);
final ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
+ .withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
.withChild(ImmutableLeafSetNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_LEVEL_LEAF_LIST_QNAME))
+ .withNodeIdentifier(new NodeIdentifier(TOP_LEVEL_LEAF_LIST_QNAME))
.withChild(
ImmutableLeafSetEntryNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue<>(TOP_LEVEL_LEAF_LIST_QNAME, "foo"))
+ .withNodeIdentifier(new NodeWithValue<>(TOP_LEVEL_LEAF_LIST_QNAME, "foo"))
.withValue("foo")
.build())
.build())
@Test
public void leafListFromNormalized() {
final ContainerNode topWithLeafList = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
- .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_LEVEL_LEAF_LIST_QNAME))
- .withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
- new YangInstanceIdentifier.NodeWithValue<>(TOP_LEVEL_LEAF_LIST_QNAME, "foo")).withValue("foo").build()).build())
+ .withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
+ .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(
+ TOP_LEVEL_LEAF_LIST_QNAME))
+ .withChild(ImmutableLeafSetEntryNodeBuilder.create()
+ .withNodeIdentifier(new NodeWithValue<>(TOP_LEVEL_LEAF_LIST_QNAME, "foo"))
+ .withValue("foo").build()).build())
.build();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topWithLeafList);
+ final Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH,
+ topWithLeafList);
final List<String> topLevelLeafList = new ArrayList<>();
topLevelLeafList.add("foo");
final Top top = new TopBuilder().setTopLevelLeafList(topLevelLeafList).build();
@Test
public void orderedLeafListFromNormalized() {
ContainerNode topWithLeafList = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
- .withChild(ImmutableOrderedLeafSetNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier
- (TOP_LEVEL_ORDERED_LEAF_LIST_QNAME))
- .withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
- new YangInstanceIdentifier.NodeWithValue<>(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME, "foo")).withValue("foo").build()).build())
+ .withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
+ .withChild(ImmutableOrderedLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(
+ TOP_LEVEL_ORDERED_LEAF_LIST_QNAME))
+ .withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
+ new NodeWithValue<>(TOP_LEVEL_ORDERED_LEAF_LIST_QNAME, "foo")).withValue("foo").build())
+ .build())
.build();
- Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topWithLeafList);
+ Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topWithLeafList);
List<String> topLevelLeafList = new ArrayList<>();
topLevelLeafList.add("foo");
Top top = new TopBuilder().setTopLevelOrderedLeafList(topLevelLeafList).build();
@Test
public void choiceToNormalized() {
- final ChoiceContainer choiceContainerBA = new ChoiceContainerBuilder().setIdentifier(new ExtendedBuilder().setExtendedId(
- new ExtendedIdBuilder().setId("identifier_value").build()).build()).build();
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
- registry.toNormalizedNode(InstanceIdentifier.create(ChoiceContainer.class), choiceContainerBA);
+ final ChoiceContainer choiceContainerBA = new ChoiceContainerBuilder().setIdentifier(new ExtendedBuilder()
+ .setExtendedId(new ExtendedIdBuilder().setId("identifier_value").build()).build()).build();
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(
+ InstanceIdentifier.create(ChoiceContainer.class), choiceContainerBA);
final ContainerNode choiceContainer = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_CONTAINER_QNAME))
- .withChild(ImmutableChoiceNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_IDENTIFIER_QNAME))
- .withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(EXTENDED_ID_QNAME))
- .withChild(leafNode(CHOICE_IDENTIFIER_ID_QNAME, "identifier_value")).build()).build())
+ .withNodeIdentifier(new NodeIdentifier(CHOICE_CONTAINER_QNAME))
+ .withChild(ImmutableChoiceNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(CHOICE_IDENTIFIER_QNAME))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(EXTENDED_ID_QNAME))
+ .withChild(leafNode(CHOICE_IDENTIFIER_ID_QNAME, "identifier_value")).build()).build())
.build();
assertEquals(choiceContainer, entry.getValue());
}
final QName nestedContainerLeafOuterQname = QName.create(containerIdentifierQname4798,
"leaf-in-outer-container");
- final YangInstanceIdentifier yangInstanceIdentifierOuter = YangInstanceIdentifier.of(containerIdentifierQname4798);
+ final YangInstanceIdentifier yangInstanceIdentifierOuter = YangInstanceIdentifier.of(
+ containerIdentifierQname4798);
final ContainerNode containerNodeOuter = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerIdentifierQname4798))
+ .withNodeIdentifier(new NodeIdentifier(containerIdentifierQname4798))
.withChild(ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(nestedContainerOuterQname))
+ .withNodeIdentifier(new NodeIdentifier(nestedContainerOuterQname))
.withChild(leafNode(nestedContainerLeafOuterQname, "bar"))
.build())
.build();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entryContainer = registry.fromNormalizedNode
- (yangInstanceIdentifierOuter, containerNodeOuter);
+ final Entry<InstanceIdentifier<?>, DataObject> entryContainer = registry.fromNormalizedNode(
+ yangInstanceIdentifierOuter, containerNodeOuter);
assertNotNull(entryContainer.getValue());
assertNotNull(entryContainer.getKey());
- final YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates4798 = new YangInstanceIdentifier
- .NodeIdentifierWithPredicates(nestedListQname4798, nestedListKeyQname4798, "foo");
- final YangInstanceIdentifier yangInstanceIdentifier4798 = YangInstanceIdentifier.of(containerIdentifierQname4798)
+ final NodeIdentifierWithPredicates nodeIdentifierWithPredicates4798 =
+ new NodeIdentifierWithPredicates(nestedListQname4798, nestedListKeyQname4798, "foo");
+ final YangInstanceIdentifier yangInstanceIdentifier4798 = YangInstanceIdentifier.of(
+ containerIdentifierQname4798)
.node(choiceIdentifierQname4798)
.node(nestedListQname4798)
.node(nodeIdentifierWithPredicates4798);
- final YangInstanceIdentifier yangInstanceIdentifierValid = YangInstanceIdentifier.of(containerIdentifierQname4798)
+ final YangInstanceIdentifier yangInstanceIdentifierValid = YangInstanceIdentifier.of(
+ containerIdentifierQname4798)
.node(choiceIdentifierQname4798)
.node(nestedContainerValidQname)
.node(nestedListQname4798)
.node(nodeIdentifierWithPredicates4798);
final ContainerNode containerNodeValid = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerIdentifierQname4798))
+ .withNodeIdentifier(new NodeIdentifier(containerIdentifierQname4798))
.withChild(ImmutableChoiceNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(choiceIdentifierQname4798))
+ .withNodeIdentifier(new NodeIdentifier(choiceIdentifierQname4798))
.withChild(ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(nestedContainerValidQname))
- .withChild(ImmutableMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier
- .NodeIdentifier(nestedListQname4798))
+ .withNodeIdentifier(new NodeIdentifier(nestedContainerValidQname))
+ .withChild(ImmutableMapNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(nestedListQname4798))
.withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "foo"))
.withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "bar"))
.build())
.build())
.build();
try {
- registry.fromNormalizedNode
- (yangInstanceIdentifierValid, containerNodeValid);
+ registry.fromNormalizedNode(yangInstanceIdentifierValid, containerNodeValid);
fail("Incorect YangInstanceIdentifier should fail");
} catch (IllegalStateException e) {
+ // Expected
}
final ContainerNode containerNode4798 = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerIdentifierQname4798))
+ .withNodeIdentifier(new NodeIdentifier(containerIdentifierQname4798))
.withChild(ImmutableChoiceNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(choiceIdentifierQname4798))
- .withChild(ImmutableMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier
- .NodeIdentifier(nestedListQname4798))
- .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "foo"))
- .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "bar"))
- .build())
+ .withNodeIdentifier(new NodeIdentifier(choiceIdentifierQname4798))
+ .withChild(ImmutableMapNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(nestedListQname4798))
+ .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "foo"))
+ .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "bar"))
+ .build())
.build())
.build();
try {
- registry.fromNormalizedNode
- (yangInstanceIdentifier4798, containerNode4798);
+ registry.fromNormalizedNode(yangInstanceIdentifier4798, containerNode4798);
fail("Incorect YangInstanceIdentifier should fail");
} catch (IllegalStateException e) {
+ // Expected
}
}
@Test
public void choiceFromNormalized() {
final ContainerNode choiceContainerBI = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_CONTAINER_QNAME))
- .withChild(ImmutableChoiceNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_IDENTIFIER_QNAME))
- .withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(EXTENDED_ID_QNAME))
- .withChild(leafNode(CHOICE_IDENTIFIER_ID_QNAME, "identifier_value")).build()).build())
+ .withNodeIdentifier(new NodeIdentifier(CHOICE_CONTAINER_QNAME))
+ .withChild(ImmutableChoiceNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(CHOICE_IDENTIFIER_QNAME))
+ .withChild(ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(EXTENDED_ID_QNAME))
+ .withChild(leafNode(CHOICE_IDENTIFIER_ID_QNAME, "identifier_value")).build()).build())
.build();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_CHOICE_CONTAINER_PATH, choiceContainerBI);
- final ChoiceContainer choiceContainerBA = new ChoiceContainerBuilder().setIdentifier(new ExtendedBuilder().setExtendedId(
- new ExtendedIdBuilder().setId("identifier_value").build()).build()).build();
+ final Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_CHOICE_CONTAINER_PATH,
+ choiceContainerBI);
+ final ChoiceContainer choiceContainerBA = new ChoiceContainerBuilder().setIdentifier(new ExtendedBuilder()
+ .setExtendedId(new ExtendedIdBuilder().setId("identifier_value").build()).build()).build();
assertEquals(choiceContainerBA, entry.getValue());
}
final List<NestedList> nestedLists = new ArrayList<>();
nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("foo")).build());
nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("bar")).build());
- final TopLevelList topLevelList = new TopLevelListBuilder().setKey(TOP_LEVEL_LIST_FOO_KEY).setNestedList(nestedLists).build();
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(ii, topLevelList);
- final MapEntryNode foo = mapEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+ final TopLevelList topLevelList = new TopLevelListBuilder().setKey(TOP_LEVEL_LIST_FOO_KEY).setNestedList(
+ nestedLists).build();
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(ii, topLevelList);
+ final MapEntryNode foo = mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(
TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
.withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
- .withChild(
- ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME))
- .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "foo"))
- .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "bar")).build()).build();
+ .withChild(ImmutableOrderedMapNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(NESTED_LIST_QNAME))
+ .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "foo"))
+ .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "bar")).build()).build();
assertEquals(foo, entry.getValue());
}
@Test
public void orderedLisFromNormalized() {
- final MapEntryNode foo = mapEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+ final MapEntryNode foo = mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(
TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
.withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
- .withChild(
- ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME))
- .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "foo"))
- .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "bar")).build()).build();
- final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH, foo);
+ .withChild(ImmutableOrderedMapNodeBuilder.create()
+ .withNodeIdentifier(new NodeIdentifier(NESTED_LIST_QNAME))
+ .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "foo"))
+ .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "bar")).build()).build();
+ final Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH,
+ foo);
final List<NestedList> nestedLists = new ArrayList<>();
nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("foo")).build());
nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("bar")).build());
- final TopLevelList topLevelList = new TopLevelListBuilder().setKey(TOP_LEVEL_LIST_FOO_KEY).setNestedList(nestedLists).build();
+ final TopLevelList topLevelList = new TopLevelListBuilder().setKey(TOP_LEVEL_LIST_FOO_KEY).setNestedList(
+ nestedLists).build();
assertEquals(topLevelList, entry.getValue());
}
final QName containerQName = QName.create(augmentChoice1QName, "case11-choice-case-container");
final QName leafQName = QName.create(augmentChoice1QName, "case11-choice-case-leaf");
- final YangInstanceIdentifier.AugmentationIdentifier aug1Id =
- new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(augmentChoice1QName));
- final YangInstanceIdentifier.AugmentationIdentifier aug2Id =
- new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(augmentChoice2QName));
- final YangInstanceIdentifier.NodeIdentifier augmentChoice1Id =
- new YangInstanceIdentifier.NodeIdentifier(augmentChoice1QName);
- final YangInstanceIdentifier.NodeIdentifier augmentChoice2Id =
- new YangInstanceIdentifier.NodeIdentifier(augmentChoice2QName);
- final YangInstanceIdentifier.NodeIdentifier containerId =
- new YangInstanceIdentifier.NodeIdentifier(containerQName);
+ final AugmentationIdentifier aug1Id = new AugmentationIdentifier(Collections.singleton(augmentChoice1QName));
+ final AugmentationIdentifier aug2Id = new AugmentationIdentifier(Collections.singleton(augmentChoice2QName));
+ final NodeIdentifier augmentChoice1Id = new NodeIdentifier(augmentChoice1QName);
+ final NodeIdentifier augmentChoice2Id = new NodeIdentifier(augmentChoice2QName);
+ final NodeIdentifier containerId = new NodeIdentifier(containerQName);
final TopBuilder tBuilder = new TopBuilder();
final TopChoiceAugment1Builder tca1Builder = new TopChoiceAugment1Builder();
tBuilder.addAugmentation(TopChoiceAugment1.class, tca1Builder.build());
final Top top = tBuilder.build();
- final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> biResult =
- registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top);
+ final Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> biResult = registry.toNormalizedNode(
+ InstanceIdentifier.create(Top.class), top);
final NormalizedNode<?, ?> topNormalized =
- containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
+ containerBuilder().withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
.withChild(augmentationBuilder().withNodeIdentifier(aug1Id)
.withChild(choiceBuilder().withNodeIdentifier(augmentChoice1Id)
.withChild(augmentationBuilder().withNodeIdentifier(aug2Id)
assertEquals(BI_TOP_PATH, biResult.getKey());
assertEquals(topNormalized, biResult.getValue());
- final Map.Entry<InstanceIdentifier<?>, DataObject> baResult = registry.fromNormalizedNode(BI_TOP_PATH, topNormalized);
+ final Entry<InstanceIdentifier<?>, DataObject> baResult = registry.fromNormalizedNode(BI_TOP_PATH,
+ topNormalized);
assertEquals(InstanceIdentifier.create(Top.class), baResult.getKey());
assertEquals(top, baResult.getValue());
assertNotNull("Serialization must not return null obejct.",dom);
assertEquals(TwoLevelListChanged.QNAME,dom.getIdentifier().getNodeType());
- final Notification bindingDeserialized = registry.fromNormalizedNodeNotification(SchemaPath.create(true, TwoLevelListChanged.QNAME),dom);
+ final Notification bindingDeserialized = registry.fromNormalizedNodeNotification(SchemaPath.create(true,
+ TwoLevelListChanged.QNAME),dom);
assertNotNull(bindingDeserialized);
assertTrue(bindingDeserialized instanceof TwoLevelListChanged);
assertEquals(bindingOriginal,bindingDeserialized);
public class UnionTypeTest extends AbstractBindingRuntimeTest {
- private static final String testString = "testtesttest";
+ private static final String TEST_STRING = "testtesttest";
- public static final QName WRAPPER_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:yangtools:test:union", "2015-01-21", "wrapper");
+ public static final QName WRAPPER_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:yangtools:test:union",
+ "2015-01-21", "wrapper");
public static final QName WRAP_LEAF_QNAME = QName.create(WRAPPER_QNAME, "wrap");
private BindingNormalizedNodeCodecRegistry registry;
@Test
public void unionTest() {
- TopLevel topLevel = TopLevelBuilder.getDefaultInstance(testString);
+ TopLevel topLevel = TopLevelBuilder.getDefaultInstance(TEST_STRING);
Wrapper wrapper = new WrapperBuilder().setWrap(topLevel).build();
- NormalizedNode<?, ?> topLevelEntry = registry.toNormalizedNode(InstanceIdentifier.builder(Wrapper.class).build(), wrapper).getValue();
+ NormalizedNode<?, ?> topLevelEntry = registry.toNormalizedNode(InstanceIdentifier.create(Wrapper.class),
+ wrapper).getValue();
ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(WRAPPER_QNAME))
- .withChild(ImmutableNodes.leafNode(WRAP_LEAF_QNAME, testString))
+ .withChild(ImmutableNodes.leafNode(WRAP_LEAF_QNAME, TEST_STRING))
.build();
Assert.assertEquals(topLevelEntry, containerNode);
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public class UnionTypeWithIdentityrefTest extends AbstractBindingRuntimeTest {
- private static final String identOneString = "IdentOne";
- public static final QName NODE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:mdsal:test:bug:6066", "2016-06-07", "union-node");
+ private static final String IDENT_ONE_STRING = "IdentOne";
+ public static final QName NODE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:mdsal:test:bug:6066",
+ "2016-06-07", "union-node");
public static final QName NODE_LEAF_QNAME = QName.create(NODE_QNAME, "value");
private BindingNormalizedNodeCodecRegistry registry;
@Test
public void bug6006Test() {
- DataObject unionNodeObj = createValueNode(identOneString);
+ DataObject unionNodeObj = createValueNode(IDENT_ONE_STRING);
UnionType unionTypeObj = ((UnionNode) unionNodeObj).getValue();
assertEquals(null, unionTypeObj.getUint8());
assertEquals(IdentOne.class, unionTypeObj.getIdentityref());