2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.binding.impl;
10 import com.google.common.collect.ImmutableBiMap;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.lang.reflect.Method;
13 import java.util.Iterator;
15 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
16 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
17 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
18 import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
19 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
20 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.binding.RpcService;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
31 @SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Migration path")
32 public class BindingToNormalizedNodeCodec
33 extends org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec {
35 private DataNormalizer legacyToNormalized = null;
37 public BindingToNormalizedNodeCodec(final ClassLoadingStrategy classLoadingStrategy,
38 final BindingNormalizedNodeCodecRegistry codecRegistry) {
39 super(classLoadingStrategy, codecRegistry);
42 public BindingToNormalizedNodeCodec(final ClassLoadingStrategy classLoadingStrategy,
43 final BindingNormalizedNodeCodecRegistry codecRegistry, final boolean waitForSchema) {
44 super(classLoadingStrategy, codecRegistry, waitForSchema);
47 DataNormalizer getDataNormalizer() {
48 return this.legacyToNormalized;
52 public YangInstanceIdentifier toYangInstanceIdentifierBlocking(
53 final InstanceIdentifier<? extends DataObject> binding) {
54 return super.toYangInstanceIdentifierBlocking(binding);
58 public YangInstanceIdentifier toYangInstanceIdentifierCached(final InstanceIdentifier<?> binding) {
59 return super.toYangInstanceIdentifierCached(binding);
63 public void onGlobalContextUpdated(final SchemaContext schemaContext) {
64 this.legacyToNormalized = new DataNormalizer(schemaContext);
65 super.onGlobalContextUpdated(schemaContext);
69 * Returns an default object according to YANG schema for supplied path.
71 * @param path DOM Path
72 * @return Node with defaults set on.
75 public NormalizedNode<?, ?> getDefaultNodeFor(final YangInstanceIdentifier path) {
76 final Iterator<PathArgument> iterator = path.getPathArguments().iterator();
77 DataNormalizationOperation<?> currentOp = this.legacyToNormalized.getRootOperation();
78 while (iterator.hasNext()) {
79 final PathArgument currentArg = iterator.next();
81 currentOp = currentOp.getChild(currentArg);
82 } catch (final DataNormalizationException e) {
83 throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
86 return currentOp.createDefault(path.getLastPathArgument());
90 public ImmutableBiMap<Method, RpcDefinition> getRpcMethodToSchema(final Class<? extends RpcService> key) {
91 return super.getRpcMethodToSchema(key);
95 public Map.Entry<InstanceIdentifier<?>, BindingDataObjectCodecTreeNode<?>> getSubtreeCodec(
96 final YangInstanceIdentifier domIdentifier) {
97 return super.getSubtreeCodec(domIdentifier);