Eliminate NormalizedNodePayload
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / server / spi / NormalizedNodeWriterFactory.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.server.spi;
9
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.restconf.api.query.DepthParam;
15 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.RestconfNormalizedNodeWriter;
16 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
17
18 /**
19  * Interface for instantiating a {@link RestconfNormalizedNodeWriter} to handle the data writeout to a
20  * {@link NormalizedNodeStreamWriter}.
21  */
22 @NonNullByDefault
23 public abstract class NormalizedNodeWriterFactory {
24     /**
25      * Return the default {@link NormalizedNodeWriterFactory}.
26      *
27      * @return the default {@link NormalizedNodeWriterFactory}
28      */
29     public static final NormalizedNodeWriterFactory of() {
30         return DefaultNormalizedNodeWriterFactory.INSTANCE;
31     }
32
33     public static final NormalizedNodeWriterFactory of(final @Nullable DepthParam depth) {
34         return depth == null ? of() : new MaxDepthNormalizedNodeWriterFactory(depth);
35     }
36
37     /**
38      * Create a new {@link RestconfNormalizedNodeWriter} for specified {@link NormalizedNodeStreamWriter}.
39      *
40      * @param streamWriter target {@link NormalizedNodeStreamWriter}
41      * @return A {@link RestconfNormalizedNodeWriter}
42      */
43     protected abstract RestconfNormalizedNodeWriter newWriter(NormalizedNodeStreamWriter streamWriter);
44
45     protected abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
46
47     @Override
48     public final String toString() {
49         return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
50     }
51 }