Seal NormalizedNode hierarchy
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableAnyXmlNodeBuilder.java
1 /*
2  * Copyright (c) 2013 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.yangtools.yang.data.impl.schema.builder.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import javax.xml.transform.dom.DOMSource;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.AbstractAnyxmlNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.AnyxmlNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
18
19 public final class ImmutableAnyXmlNodeBuilder
20         extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode>
21         implements AnyxmlNode.Builder<DOMSource, DOMSourceAnyxmlNode> {
22     @Override
23     public ImmutableAnyXmlNodeBuilder withValue(final DOMSource withValue) {
24         super.withValue(withValue);
25         return this;
26     }
27
28     @Override
29     public DOMSourceAnyxmlNode build() {
30         return new ImmutableXmlNode(getNodeIdentifier(), getValue());
31     }
32
33     private static final class ImmutableXmlNode extends AbstractAnyxmlNode<DOMSource> implements DOMSourceAnyxmlNode {
34         private final @NonNull NodeIdentifier name;
35         private final @NonNull DOMSource value;
36
37         ImmutableXmlNode(final NodeIdentifier name, final DOMSource value) {
38             this.name = requireNonNull(name);
39             this.value = requireNonNull(value);
40         }
41
42         @Override
43         public NodeIdentifier name() {
44             return name;
45         }
46
47         @Override
48         protected DOMSource value() {
49             return value;
50         }
51
52         @Override
53         protected DOMSource wrappedValue() {
54             return value;
55         }
56     }
57 }