package org.opendaylight.mdsal.binding.javav2.dom.codec.generator.impl;
import com.google.common.annotations.Beta;
+import java.util.Collection;
import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.api.TreeNodeSerializerGenerator;
import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.generator.AbstractStreamWriterGenerator;
+import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.source.AbstractAugmentSerializerSource;
import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.source.AbstractAugmentableDataNodeContainerEmitterSource;
-import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.source.AbstractDataNodeContainerSerializerSource;
import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.source.AbstractTreeNodeSerializerSource;
import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.serializer.AugmentableDispatchSerializer;
import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.serializer.ChoiceDispatchSerializer;
}
@Override
- protected AbstractTreeNodeSerializerSource generateSerializer(final GeneratedType type,
- final AugmentationSchemaNode schema) {
- return new AbstractDataNodeContainerSerializerSource(this, type, schema) {
+ protected AbstractTreeNodeSerializerSource generateAugmentSerializer(final GeneratedType type,
+ final Collection<AugmentationSchemaNode> augmentationSchemas) {
+ return new AbstractAugmentSerializerSource(this, type, augmentationSchemas) {
@Override
public CharSequence emitStartEvent() {
import com.google.common.cache.LoadingCache;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
import java.util.Map.Entry;
import javassist.CannotCompileException;
import javassist.CtClass;
import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.serializer.AugmentableDispatchSerializer;
import org.opendaylight.mdsal.binding.javav2.generator.util.Types;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.javav2.model.api.Type;
+import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.mdsal.binding.javav2.runtime.context.BindingRuntimeContext;
import org.opendaylight.mdsal.binding.javav2.runtime.javassist.JavassistUtils;
import org.opendaylight.mdsal.binding.javav2.runtime.reflection.BindingReflections;
import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingStreamEventWriter;
import org.opendaylight.mdsal.binding.javav2.spec.runtime.TreeNodeSerializerImplementation;
import org.opendaylight.mdsal.binding.javav2.spec.runtime.TreeNodeSerializerRegistry;
+import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
import org.opendaylight.yangtools.util.ClassLoaderUtils;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
private AbstractTreeNodeSerializerSource generateEmitterSource(final Class<?> type, final String serializerName) {
Types.typeForClass(type);
javassist.appendClassLoaderIfMissing(type.getClassLoader());
+
+ if (Augmentation.class.isAssignableFrom(type)) {
+ final Entry<Type, Collection<AugmentationSchemaNode>> entry = context.getAugmentationDefinition(type);
+ return generateAugmentSerializer(((GeneratedTypeBuilder) entry.getKey()).toInstance(), entry.getValue());
+ }
+
final Entry<GeneratedType, Object> typeWithSchema = context.getTypeWithSchema(type);
final GeneratedType generatedType = typeWithSchema.getKey();
final Object schema = typeWithSchema.getValue();
} else {
source = generateMapEntrySerializer(generatedType, casted);
}
- } else if (schema instanceof AugmentationSchemaNode) {
- source = generateSerializer(generatedType, (AugmentationSchemaNode) schema);
} else if (schema instanceof CaseSchemaNode) {
source = generateCaseSerializer(generatedType, (CaseSchemaNode) schema);
} else if (schema instanceof NotificationDefinition) {
* binding objects.
*
* @param type - binding type of augmentation
- * @param schema - schema of augmentation
+ * @param schemas - schemas of augmentation
* @return source for augmentation node writer
*/
- protected abstract AbstractTreeNodeSerializerSource generateSerializer(GeneratedType type,
- AugmentationSchemaNode schema);
+ protected abstract AbstractTreeNodeSerializerSource generateAugmentSerializer(GeneratedType type,
+ Collection<AugmentationSchemaNode> schemas);
/**
* Generates serializer source for notification node, which will read
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.source;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.spi.generator.AbstractGenerator;
+import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Beta
+public abstract class AbstractAugmentSerializerSource extends AbstractDataNodeContainerSerializerSource {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractAugmentSerializerSource.class);
+ private final Collection<AugmentationSchemaNode> augmentationSchemas;
+
+ public AbstractAugmentSerializerSource(final AbstractGenerator generator, final GeneratedType type,
+ final Collection<AugmentationSchemaNode> augmentationSchemas) {
+ // Note: passing first augmentation schema node just to avoid exceptions from super class.
+ super(generator, type, augmentationSchemas.stream().findFirst().get());
+ this.augmentationSchemas = Preconditions.checkNotNull(augmentationSchemas);
+ }
+
+ /**
+ * Override {@link AbstractDataNodeContainerSerializerSource#getChildNodes()} to get all children nodes
+ * of same target augmentation schema nodes.
+ */
+ @Override
+ protected Collection<DataSchemaNode> getChildNodes() {
+ Collection<DataSchemaNode> childNodes = new ArrayList<>();
+ for (AugmentationSchemaNode schema : this.augmentationSchemas) {
+ childNodes.addAll(schema.getChildNodes());
+ }
+ return childNodes;
+ }
+
+}
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.opendaylight.mdsal.binding.javav2.dom.codec.generator.impl.StreamWriterGenerator;
protected static final String INPUT = "_input";
private static final String CHOICE_PREFIX = "CHOICE_";
+ //Note: the field takes no effects by augmentation.
private final DataNodeContainer schemaNode;
private final GeneratedType dtoType;
return true;
}
+ /**
+ * Note: the method would be overrided by {@link AbstractAugmentSerializerSource#getChildNodes()},
+ * since all augmentation schema nodes of same target would be grouped into sort of one node,
+ * so call {@link AbstractAugmentSerializerSource#getChildNodes()} to get all these children
+ * nodes of same target augmentation schemas.
+ */
+ protected Collection<DataSchemaNode> getChildNodes() {
+ return schemaNode.getChildNodes();
+ }
+
private void emitBody(final StringBuilder builder) {
final Map<String, Type> getterToType = collectAllProperties(dtoType, new HashMap<String, Type>());
- for (final DataSchemaNode schemaChild : schemaNode.getChildNodes()) {
+ for (final DataSchemaNode schemaChild : getChildNodes()) {
/**
* As before, it only emitted data nodes which were not added by uses or augment, now
* according to binding v2 specification, augment of the same module is same as inlining,