Added instance identifier support.
[yangtools.git] / yang / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / InstanceIdentifier.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.yangtools.yang.binding;\r
9 \r
10 import java.util.ArrayList;\r
11 import java.util.Collections;\r
12 import java.util.List;\r
13 \r
14 /**\r
15  * Uniquely identifies instance of data tree. \r
16  *\r
17  *\r
18  */\r
19 public class InstanceIdentifier <T extends DataObject> {\r
20 \r
21     \r
22     private final List<PathArgument> path;\r
23     private final Class<T> targetType;\r
24     \r
25     public InstanceIdentifier(Class<T> type) {\r
26         path = Collections.emptyList();\r
27         this.targetType = type;\r
28     }\r
29     \r
30     \r
31     public InstanceIdentifier(List<PathArgument> path,Class<T> type) {\r
32         this.path = Collections.<PathArgument>unmodifiableList(new ArrayList<>(path));\r
33         this.targetType = type;\r
34     }\r
35     \r
36 \r
37     /**\r
38      * \r
39      * @return\r
40      */\r
41     public List<PathArgument> getPath() {\r
42         return this.path;\r
43     }\r
44     \r
45     public Class<T> getTargetType() {\r
46         return this.targetType;\r
47     }\r
48     \r
49     \r
50     /**\r
51      * Path argument of instance identifier.\r
52      * \r
53      * Interface which implementations are used as path components\r
54      * of the instance path.\r
55      * \r
56      * @author ttkacik\r
57      *\r
58      */\r
59     public static interface PathArgument {\r
60         \r
61     }\r
62     \r
63     public static class IdentifiableItem<I extends Identifiable<T>,T extends Identifier<I>>  implements PathArgument {\r
64            \r
65         private final T key;\r
66         private final Class<? extends I> type;\r
67 \r
68         public IdentifiableItem(Class<I> type, T key) {\r
69             this.type = type;\r
70             this.key = key;\r
71         }\r
72         \r
73         T getKey() {\r
74             return this.key;\r
75         }\r
76         \r
77         Class<? extends I> getType() {\r
78             return this.type;\r
79         }\r
80     }\r
81 }\r