import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import org.opendaylight.yangtools.yang.binding.DataObject;
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.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
final class LeafNodeCodecContext<D extends DataObject> extends NodeCodecContext<D> implements NodeContextSupplier {
Object defaultValue = ((LeafSchemaNode) schema).getDefault();
TypeDefinition<?> type = ((LeafSchemaNode) schema).getType();
if (defaultValue != null) {
+ if (type instanceof IdentityrefTypeDefinition) {
+ return qnameDomValueFromString(codec, schema, defaultValue);
+ }
return domValueFromString(codec, type, defaultValue);
- }
- else {
+ } else {
while (type.getBaseType() != null && type.getDefaultValue() == null) {
type = type.getBaseType();
}
defaultValue = type.getDefaultValue();
if (defaultValue != null) {
- if (defaultValue instanceof Boolean) {
- return codec.deserialize(defaultValue);
+ if (type instanceof IdentityrefTypeDefinition) {
+ return qnameDomValueFromString(codec, schema, defaultValue);
}
- if (defaultValue instanceof IdentitySchemaNode) {
- defaultValue = ((IdentitySchemaNode) defaultValue).getQName();
- return codec.deserialize(defaultValue);
- }
-
- if (defaultValue instanceof ImmutableList) {
- return codec.deserialize(ImmutableSet.copyOf((ImmutableList) defaultValue));
- }
-
- if (defaultValue instanceof List) {
- return codec.deserialize(defaultValue);
- }
return domValueFromString(codec, type, defaultValue);
}
}
return null;
}
+ private static Object qnameDomValueFromString(final Codec<Object, Object> codec, final DataSchemaNode schema,
+ final Object defaultValue) {
+ Object qname = QName.create(schema.getQName(), (String) defaultValue);
+ return codec.deserialize(qname);
+ }
+
private static Object domValueFromString(final Codec<Object, Object> codec, final TypeDefinition<?> type,
Object defaultValue) {
TypeDefinitionAwareCodec typeDefAwareCodec = TypeDefinitionAwareCodec.from(type);
}
identity my-identity {
- description "identity for testing purposes";
+ description "parent identity for testing purposes";
+ }
+
+ identity my-derived-identity {
+ base my-identity;
+ description "child identity for testing purposes";
+ }
+
+ identity my-derived-identity2 {
+ base my-derived-identity;
+ description "another child identity for testing purposes";
}
typedef my-identityref {
}
}
+ typedef my-identityref2 {
+ type identityref {
+ base my-identity;
+ }
+ default "my-derived-identity";
+ }
+
container tiny-int-container {
presence "presence container";
leaf identityref-leaf {
type my-identityref;
}
+
+ leaf identityref-leaf2 {
+ type my-identityref;
+ default "my-derived-identity";
+ }
+
+ leaf identityref-leaf3 {
+ type my-identityref2;
+ }
+
+ leaf identityref-leaf4 {
+ type my-identityref;
+ default "my-derived-identity2";
+ }
}
}
\ No newline at end of file