Add Opaque{Data,Object} interfaces 26/81326/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Mar 2019 15:31:07 +0000 (16:31 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Mar 2019 16:09:31 +0000 (17:09 +0100)
This adds the baseline interfaces needed for generating
manifestations of anydata and anyxml node sin Binding world.

Since they are conceptually the same and cannot have the same
identifier, we can support them with a single BindingObject
sub-interface.

JIRA: MDSAL-428
Change-Id: I7d7e0ff6c7bcd7d2375d50c4e976bf68d4e47143
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 25952d26001a7ef4a04f713312f864b8af397f69)

binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/OpaqueData.java [new file with mode: 0644]
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/OpaqueObject.java [new file with mode: 0644]

diff --git a/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/OpaqueData.java b/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/OpaqueData.java
new file mode 100644 (file)
index 0000000..6825b83
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.Immutable;
+
+/**
+ * An immutable view of data. Data representation identity is available through {@link #getObjectModel()} and the actual
+ * data is available through {@link #getData()}.
+ *
+ * @param <T> Data object model type
+ */
+@Beta
+public interface OpaqueData<T> extends Immutable {
+    /**
+     * Return the object model class, which identifies it.
+     *
+     * @return Object model class
+     */
+    @NonNull Class<T> getObjectModel();
+
+    /**
+     * Return the data in associated object model.
+     *
+     * @return Data held in this object.
+     */
+    @NonNull T getData();
+}
diff --git a/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/OpaqueObject.java b/binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/OpaqueObject.java
new file mode 100644 (file)
index 0000000..1bedda4
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * An opaque object. This interface supports code generation for both {@code anyxml} and {@code anydata}. Both of these
+ * statements essentially share the same characteristic of storing data whose actual schema and representation is not
+ * known at compile-time. Schema may be unknown even at runtime, and furthermore the representation may vary during
+ * run-time, based on source of the data.
+ *
+ * <p>
+ * The code generation is therefore limited to a single interface, which only provides the default implementation
+ * of {@link #getImplementedInterface()} bound to itself. The value is communicated through {@link #getValue()}, which
+ * is only an encapsulation holding information about the object model and the data in that object model.
+ *
+ * @param <T> Generated interface
+ */
+@Beta
+public interface OpaqueObject<T extends OpaqueObject<T>> extends BindingObject, DataContainer,
+        ValueAware<OpaqueData<?>> {
+    @Override
+    Class<T> getImplementedInterface();
+}