--- /dev/null
+/*
+ * Copyright (c) 2023 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.mdsal.binding.api;
+
+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;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * A serialization proxy for {@link DataTreeIdentifier}.
+ */
+final class DTIv1 implements Externalizable {
+ @java.io.Serial
+ private static final long serialVersionUID = 1L;
+
+ private DataTreeIdentifier<?> id;
+
+ @SuppressWarnings("redundantModifier")
+ public DTIv1() {
+ // For Externalizable
+ }
+
+ DTIv1(final DataTreeIdentifier<?> id) {
+ this.id = requireNonNull(id);
+ }
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ id.getDatastoreType().writeTo(out);
+ out.writeObject(id.getRootIdentifier());
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+ id = DataTreeIdentifier.create(LogicalDatastoreType.readFrom(in), (InstanceIdentifier<?>) in.readObject());
+ }
+
+ @java.io.Serial
+ Object readResolve() {
+ return verifyNotNull(id);
+ }
+}
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import org.junit.jupiter.api.Test;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.binding.ChildOf;
assertNotEquals(TEST_IDENTIFIER1, new Object(), "Different object");
}
+ @Test
+ void serializationTest() throws Exception {
+ final var bos = new ByteArrayOutputStream();
+ try (var oos = new ObjectOutputStream(bos)) {
+ oos.writeObject(TEST_IDENTIFIER1);
+ }
+
+ final var bytes = bos.toByteArray();
+ assertEquals(728, bytes.length);
+
+ try (var ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
+ assertEquals(TEST_IDENTIFIER1, ois.readObject());
+ }
+ }
+
private interface TestDataObject1 extends ChildOf<DataRoot> {
@Override
default Class<? extends DataObject> implementedInterface() {
--- /dev/null
+/*
+ * Copyright (c) 2023 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.mdsal.dom.api;
+
+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;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+/**
+ * A serialization proxy for {@link DOMDataTreeIdentifier}.
+ */
+final class DTIv1 implements Externalizable {
+ @java.io.Serial
+ private static final long serialVersionUID = 1L;
+
+ private DOMDataTreeIdentifier id;
+
+ @SuppressWarnings("redundantModifier")
+ public DTIv1() {
+ // For Externalizable
+ }
+
+ DTIv1(final DOMDataTreeIdentifier id) {
+ this.id = requireNonNull(id);
+ }
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ id.getDatastoreType().writeTo(out);
+ out.writeObject(id.getRootIdentifier());
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+ id = new DOMDataTreeIdentifier(LogicalDatastoreType.readFrom(in), (YangInstanceIdentifier) in.readObject());
+ }
+
+ @java.io.Serial
+ Object readResolve() {
+ return verifyNotNull(id);
+ }
+}
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import org.junit.jupiter.api.Test;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.common.QName;
private static final String TEST_LISTS = "test-lists";
private static final String COMPARE_FIRST_LISTS = "A-test-lists";
private static final String COMPARE_SECOND_LISTS = "B-test-lists";
- private static final QNameModule TEST_MODULE = QNameModule.create(XMLNamespace.of(
- "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"));
- private static final YangInstanceIdentifier REF_YII_IID = YangInstanceIdentifier.of(
- QName.create(TEST_MODULE, REF_LISTS));
- private static final YangInstanceIdentifier TEST_YII_IID = YangInstanceIdentifier.of(
- QName.create(TEST_MODULE, TEST_LISTS));
- private static final DOMDataTreeIdentifier REF_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
- REF_YII_IID);
- private static final DOMDataTreeIdentifier
- TEST_DIFF_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,TEST_YII_IID);
+ private static final QNameModule TEST_MODULE =
+ QNameModule.create(XMLNamespace.of("urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"));
+ private static final YangInstanceIdentifier REF_YII_IID =
+ YangInstanceIdentifier.of(QName.create(TEST_MODULE, REF_LISTS));
+ private static final YangInstanceIdentifier TEST_YII_IID =
+ YangInstanceIdentifier.of(QName.create(TEST_MODULE, TEST_LISTS));
+ private static final DOMDataTreeIdentifier REF_TREE =
+ new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, REF_YII_IID);
+ private static final DOMDataTreeIdentifier TEST_DIFF_TREE =
+ new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,TEST_YII_IID);
@Test
void constructTest() {
+ "root=/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store)ref-lists}",
REF_TREE.toString());
}
+
+ @Test
+ void serializationTest() throws Exception {
+ final var bos = new ByteArrayOutputStream();
+ try (var oos = new ObjectOutputStream(bos)) {
+ oos.writeObject(REF_TREE);
+ }
+
+ final var bytes = bos.toByteArray();
+ assertEquals(561, bytes.length);
+
+ try (var ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
+ assertEquals(REF_TREE, ois.readObject());
+ }
+ }
}