Added instance identifier support.
[yangtools.git] / yang / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / InstanceIdentifier.java
index 42cc11a5540bfb855f37b951b399567ac991667c..832a9ed58af5531a5ced7677ba84fe00f0913489 100644 (file)
@@ -1,19 +1,81 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.binding;
-
-/**
- * Created with IntelliJ IDEA.
- * User: lsedlak
- * Date: 27.6.2013
- * Time: 11:44
- * To change this template use File | Settings | File Templates.
- */
-public class InstanceIdentifier <T extends DataObject> {
-
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.yang.binding;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+/**\r
+ * Uniquely identifies instance of data tree. \r
+ *\r
+ *\r
+ */\r
+public class InstanceIdentifier <T extends DataObject> {\r
+\r
+    \r
+    private final List<PathArgument> path;\r
+    private final Class<T> targetType;\r
+    \r
+    public InstanceIdentifier(Class<T> type) {\r
+        path = Collections.emptyList();\r
+        this.targetType = type;\r
+    }\r
+    \r
+    \r
+    public InstanceIdentifier(List<PathArgument> path,Class<T> type) {\r
+        this.path = Collections.<PathArgument>unmodifiableList(new ArrayList<>(path));\r
+        this.targetType = type;\r
+    }\r
+    \r
+\r
+    /**\r
+     * \r
+     * @return\r
+     */\r
+    public List<PathArgument> getPath() {\r
+        return this.path;\r
+    }\r
+    \r
+    public Class<T> getTargetType() {\r
+        return this.targetType;\r
+    }\r
+    \r
+    \r
+    /**\r
+     * Path argument of instance identifier.\r
+     * \r
+     * Interface which implementations are used as path components\r
+     * of the instance path.\r
+     * \r
+     * @author ttkacik\r
+     *\r
+     */\r
+    public static interface PathArgument {\r
+        \r
+    }\r
+    \r
+    public static class IdentifiableItem<I extends Identifiable<T>,T extends Identifier<I>>  implements PathArgument {\r
+           \r
+        private final T key;\r
+        private final Class<? extends I> type;\r
+\r
+        public IdentifiableItem(Class<I> type, T key) {\r
+            this.type = type;\r
+            this.key = key;\r
+        }\r
+        \r
+        T getKey() {\r
+            return this.key;\r
+        }\r
+        \r
+        Class<? extends I> getType() {\r
+            return this.type;\r
+        }\r
+    }\r
+}\r