Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingToNormalizedNodeCodec.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.impl;
9
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;
14 import java.util.Map;
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;
29
30 @Deprecated
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 {
34
35     private DataNormalizer legacyToNormalized = null;
36
37     public BindingToNormalizedNodeCodec(final ClassLoadingStrategy classLoadingStrategy,
38             final BindingNormalizedNodeCodecRegistry codecRegistry) {
39         super(classLoadingStrategy, codecRegistry);
40     }
41
42     public BindingToNormalizedNodeCodec(final ClassLoadingStrategy classLoadingStrategy,
43             final BindingNormalizedNodeCodecRegistry codecRegistry, final boolean waitForSchema) {
44         super(classLoadingStrategy, codecRegistry, waitForSchema);
45     }
46
47     DataNormalizer getDataNormalizer() {
48         return this.legacyToNormalized;
49     }
50
51     @Override
52     public YangInstanceIdentifier toYangInstanceIdentifierBlocking(
53             final InstanceIdentifier<? extends DataObject> binding) {
54         return super.toYangInstanceIdentifierBlocking(binding);
55     }
56
57     @Override
58     public YangInstanceIdentifier toYangInstanceIdentifierCached(final InstanceIdentifier<?> binding) {
59         return super.toYangInstanceIdentifierCached(binding);
60     }
61
62     @Override
63     public void onGlobalContextUpdated(final SchemaContext schemaContext) {
64         this.legacyToNormalized = new DataNormalizer(schemaContext);
65         super.onGlobalContextUpdated(schemaContext);
66     }
67
68     /**
69      * Returns an default object according to YANG schema for supplied path.
70      *
71      * @param path DOM Path
72      * @return Node with defaults set on.
73      */
74     @Override
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();
80             try {
81                 currentOp = currentOp.getChild(currentArg);
82             } catch (final DataNormalizationException e) {
83                 throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
84             }
85         }
86         return currentOp.createDefault(path.getLastPathArgument());
87     }
88
89     @Override
90     public ImmutableBiMap<Method, RpcDefinition> getRpcMethodToSchema(final Class<? extends RpcService> key) {
91         return super.getRpcMethodToSchema(key);
92     }
93
94     @Override
95     public Map.Entry<InstanceIdentifier<?>, BindingDataObjectCodecTreeNode<?>> getSubtreeCodec(
96             final YangInstanceIdentifier domIdentifier) {
97         return super.getSubtreeCodec(domIdentifier);
98     }
99 }