Bug 2983 - Throws ResultAlreadySet instead of IllegalStateException
[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}.
14  * which produces instance of NormalizedNode.
15  *
16  * Client may supply result holder to {@link ImmutableNormalizedNodeStreamWriter}
17  * which will be once updated, when result is available.
18  *
19  * This is intended for using {@link ImmutableNormalizedNodeStreamWriter}
20  * without supplying builder, so instantiated writer will select
21  * correct builder based on first event and sets resulting
22  *  {@link NormalizedNode} when end event is invoked for node.
23  *
24  */
25 public class NormalizedNodeResult {
26
27     private boolean finished = false;
28     private NormalizedNode<?,?> result;
29
30     public NormalizedNode<?, ?> getResult() {
31         return result;
32     }
33
34     void setResult(final NormalizedNode<?, ?> result) {
35         if (finished) {
36             throw new ResultAlreadySetException("Normalized Node result was already set.", this.result);
37         }
38         this.finished = true;
39         this.result = result;
40     }
41
42     public boolean isFinished() {
43         return finished;
44     }
45
46 }