Backport QName externalizable proxy 54/81254/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 21 Mar 2019 08:12:13 +0000 (09:12 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Mar 2019 10:39:17 +0000 (11:39 +0100)
This is a backport of the proxy class only, so that yangtools-2.1.x
can understand data serialized by yangtools-3.0.x.

Change-Id: I1be13e02ed4eec537cb86f86e009ba058687f153
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 7768e923cc12f467ad7e5e32577bdd1a10a4d581)

yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QNv1.java [new file with mode: 0644]

diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QNv1.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QNv1.java
new file mode 100644 (file)
index 0000000..674087f
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.common;
+
+import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+/**
+ * Externalizable proxy for {@link QName}.
+ */
+final class QNv1 implements Externalizable {
+    private static final long serialVersionUID = 1L;
+
+    private QName qname;
+
+    @SuppressWarnings("checkstyle:redundantModifier")
+    public QNv1() {
+        // For Externalizable
+    }
+
+    QNv1(final QName qname) {
+        this.qname = requireNonNull(qname);
+    }
+
+    @Override
+    public void writeExternal(final ObjectOutput out) throws IOException {
+        qname.writeTo(out);
+    }
+
+    @Override
+    public void readExternal(final ObjectInput in) throws IOException {
+        qname = QName.readFrom(in);
+    }
+
+    Object readResolve() {
+        return verifyNotNull(qname);
+    }
+}