Changed read to be type-safe in ReadTransaction
[controller.git] / opendaylight / md-sal / sal-binding-util / src / main / java / org / opendaylight / controller / md / sal / binding / util / TypeSafeDataReader.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.util;
9
10 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
11 import org.opendaylight.yangtools.yang.binding.DataObject;
12 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
13
14 /**
15  *
16  *
17  * @deprecated Use
18  *             {@link org.opendaylight.controller.md.sal.binding.api.ReadTransaction#read(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType, InstanceIdentifier)}
19  *             instead.
20  */
21 @Deprecated
22 public final class TypeSafeDataReader {
23
24     private final DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate;
25
26     public DataReader<InstanceIdentifier<?>, DataObject> getDelegate() {
27         return delegate;
28     }
29
30     public TypeSafeDataReader(
31             final DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate) {
32         this.delegate = delegate;
33     }
34
35     @SuppressWarnings("unchecked")
36     public <D extends DataObject> D readConfigurationData(
37             final InstanceIdentifier<D> path) {
38         return (D) delegate.readConfigurationData(path);
39     }
40
41     @SuppressWarnings("unchecked")
42     public <D extends DataObject> D readOperationalData(
43             final InstanceIdentifier<D> path) {
44         return (D) delegate.readOperationalData(path);
45     }
46
47     public static TypeSafeDataReader forReader(
48             final DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate) {
49         return new TypeSafeDataReader(delegate);
50     }
51 }