*/
package org.opendaylight.mdsal.binding.dom.codec.impl;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ImmutableCollection;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
-import javax.annotation.Nullable;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeCachingCodec;
import org.opendaylight.yangtools.concepts.Codec;
LeafNodeCodecContext(final DataSchemaNode schema, final Codec<Object, Object> codec, final Method getter,
final SchemaContext schemaContext) {
this.yangIdentifier = new YangInstanceIdentifier.NodeIdentifier(schema.getQName());
- this.valueCodec = Preconditions.checkNotNull(codec);
+ this.valueCodec = requireNonNull(codec);
this.getter = getter;
- this.schema = Preconditions.checkNotNull(schema);
+ this.schema = requireNonNull(schema);
this.defaultObject = createDefaultObject(schema, valueCodec, schemaContext);
}
private static Object createDefaultObject(final DataSchemaNode schema, final Codec<Object, Object> codec,
final SchemaContext schemaContext) {
if (schema instanceof LeafSchemaNode) {
- Object defaultValue = ((LeafSchemaNode) schema).getDefault();
+ Optional<? extends Object> defaultValue = ((LeafSchemaNode) schema).getType().getDefaultValue();
TypeDefinition<?> type = ((LeafSchemaNode) schema).getType();
- if (defaultValue != null) {
+ if (defaultValue.isPresent()) {
if (type instanceof IdentityrefTypeDefinition) {
- return qnameDomValueFromString(codec, schema, (String) defaultValue, schemaContext);
+ return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext);
}
- return domValueFromString(codec, type, defaultValue);
+ return domValueFromString(codec, type, defaultValue.get());
}
- while (type.getBaseType() != null && type.getDefaultValue() == null) {
+ while (type.getBaseType() != null && !type.getDefaultValue().isPresent()) {
type = type.getBaseType();
}
defaultValue = type.getDefaultValue();
- if (defaultValue != null) {
+ if (defaultValue.isPresent()) {
if (type instanceof IdentityrefTypeDefinition) {
- return qnameDomValueFromString(codec, schema, (String) defaultValue, schemaContext);
+ return qnameDomValueFromString(codec, schema, (String) defaultValue.get(), schemaContext);
}
return domValueFromString(codec, type, defaultValue);
}
if (prefixEndIndex != -1) {
String defaultValuePrefix = defaultValue.substring(0, prefixEndIndex);
- Module module = schemaContext.findModuleByNamespaceAndRevision(schema.getQName().getNamespace(),
- schema.getQName().getRevision());
-
+ Module module = schemaContext.findModule(schema.getQName().getModule()).get();
if (module.getPrefix().equals(defaultValuePrefix)) {
qname = QName.create(module.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());
+ Module importedModule = schemaContext.findModule(moduleImport.getModuleName(),
+ moduleImport.getRevision()).get();
qname = QName.create(importedModule.getQNameModule(), defaultValue.substring(prefixEndIndex + 1));
return codec.deserialize(qname);
}
@Override
public InstanceIdentifier.PathArgument deserializePathArgument(final YangInstanceIdentifier.PathArgument arg) {
- Preconditions.checkArgument(getDomPathArgument().equals(arg));
+ checkArgument(getDomPathArgument().equals(arg));
return null;
}
return schema;
}
- /**
- * Return the default value object.
- *
- * @return The default value object, or null if the default value is not defined.
- */
- @Nullable Object defaultObject() {
+ @Override
+ public ChildAddressabilitySummary getChildAddressabilitySummary() {
+ return ChildAddressabilitySummary.UNADDRESSABLE;
+ }
+
+ @Override
+ Object defaultObject() {
return defaultObject;
}
-}
\ No newline at end of file
+}