1/**
2 * Copyright (c) 2008, http://www.snakeyaml.org
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.yaml.snakeyaml.nodes;
17
18import org.yaml.snakeyaml.error.Mark;
19
20/**
21 * Represents a scalar node.
22 * <p>
23 * Scalar nodes form the leaves in the node graph.
24 * </p>
25 */
26public class ScalarNode extends Node {
27    private Character style;
28    private String value;
29
30    public ScalarNode(Tag tag, String value, Mark startMark, Mark endMark, Character style) {
31        this(tag, true, value, startMark, endMark, style);
32    }
33
34    public ScalarNode(Tag tag, boolean resolved, String value, Mark startMark, Mark endMark,
35            Character style) {
36        super(tag, startMark, endMark);
37        if (value == null) {
38            throw new NullPointerException("value in a Node is required.");
39        }
40        this.value = value;
41        this.style = style;
42        this.resolved = resolved;
43    }
44
45    /**
46     * Get scalar style of this node.
47     *
48     * @see org.yaml.snakeyaml.events.ScalarEvent
49     * @see <a href="http://yaml.org/spec/1.1/#id903915">Chapter 9. Scalar
50     *      Styles</a>
51     */
52    public Character getStyle() {
53        return style;
54    }
55
56    @Override
57    public NodeId getNodeId() {
58        return NodeId.scalar;
59    }
60
61    /**
62     * Value of this scalar.
63     *
64     * @return Scalar's value.
65     */
66    public String getValue() {
67        return value;
68    }
69
70    public String toString() {
71        return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue()
72                + ")>";
73    }
74}
75