Cleanup NormalizedNodeContext lifecycle
[netconf.git] / restconf / restconf-common / src / main / java / org / opendaylight / restconf / common / context / NormalizedNodeContext.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.common.context;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableMap;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
15
16 public class NormalizedNodeContext {
17     private final InstanceIdentifierContext<? extends SchemaNode> context;
18     private final ImmutableMap<String, Object> headers;
19     private final WriterParameters writerParameters;
20     private final NormalizedNode data;
21
22     public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
23             final NormalizedNode data, final WriterParameters writerParameters,
24             final ImmutableMap<String, Object> headers) {
25         this.context = context;
26         this.data = data;
27         this.writerParameters = writerParameters;
28         this.headers = requireNonNull(headers);
29     }
30
31     public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
32                                  final NormalizedNode data, final WriterParameters writerParameters) {
33         this(context, data, writerParameters, ImmutableMap.of());
34     }
35
36     public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
37                                  final NormalizedNode data) {
38         this(context, data, WriterParameters.EMPTY, ImmutableMap.of());
39     }
40
41     public NormalizedNodeContext(final InstanceIdentifierContext<? extends SchemaNode> context,
42             final NormalizedNode data, final ImmutableMap<String, Object> headers) {
43         this(context, data, WriterParameters.EMPTY, headers);
44     }
45
46     public InstanceIdentifierContext<? extends SchemaNode> getInstanceIdentifierContext() {
47         return context;
48     }
49
50     public NormalizedNode getData() {
51         return data;
52     }
53
54     public WriterParameters getWriterParameters() {
55         return writerParameters;
56     }
57
58     /**
59      * Return headers of {@code NormalizedNodeContext}.
60      *
61      * @return map of headers
62      */
63     public ImmutableMap<String, Object> getNewHeaders() {
64         return headers;
65     }
66 }