Add utility wrappers for instantiating builders/nodes
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / NormalizedNodeResult.java
1 /*
2  * Copyright (c) 2014 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;
9
10 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
11
12 /**
13  * Client allocated result holder for {@link ImmutableNormalizedNodeStreamWriter} which produces instance
14  * of NormalizedNode.
15  *
16  * <p>
17  * Client may supply result holder to {@link ImmutableNormalizedNodeStreamWriter} which will be once updated when
18  * the result is available.
19  *
20  * <p>
21  * This is intended for using {@link ImmutableNormalizedNodeStreamWriter} without supplying builder, so instantiated
22  * writer will select correct builder based on first event and sets resulting {@link NormalizedNode} when end event is
23  * invoked for node.
24  */
25 public class NormalizedNodeResult {
26     private boolean finished = false;
27     private NormalizedNode<?,?> result;
28
29     public NormalizedNode<?, ?> getResult() {
30         return result;
31     }
32
33     void setResult(final NormalizedNode<?, ?> result) {
34         if (finished) {
35             throw new ResultAlreadySetException("Normalized Node result was already set.", this.result);
36         }
37         this.finished = true;
38         this.result = result;
39     }
40
41     public boolean isFinished() {
42         return finished;
43     }
44 }