1 /**
2 * Copyright (c) 2008-2011, 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 */
16
17 package org.yaml.snakeyaml.nodes;
18
19 import org.yaml.snakeyaml.error.Mark;
20
21 /**
22 * Represents a scalar node.
23 * <p>
24 * Scalar nodes form the leaves in the node graph.
25 * </p>
26 */
27 public class ScalarNode extends Node {
28 private Character style;
29 private String value;
30
31 public ScalarNode(Tag tag, String value, Mark startMark, Mark endMark, Character style) {
32 this(tag, true, value, startMark, endMark, style);
33 }
34
35 public ScalarNode(Tag tag, boolean resolved, String value, Mark startMark, Mark endMark,
36 Character style) {
37 super(tag, startMark, endMark);
38 if (value == null) {
39 throw new NullPointerException("value in a Node is required.");
40 }
41 this.value = value;
42 this.style = style;
43 this.resolved = resolved;
44 }
45
46 /**
47 * Get scalar style of this node.
48 *
49 * @see org.yaml.snakeyaml.events.ScalarEvent
50 * @see http://yaml.org/spec/1.1/#id864487
51 * @return
52 */
53 public Character getStyle() {
54 return style;
55 }
56
57 @Override
58 public NodeId getNodeId() {
59 return NodeId.scalar;
60 }
61
62 /**
63 * Value of this scalar.
64 *
65 * @return Scalar's value.
66 */
67 public String getValue() {
68 return value;
69 }
70
71 public String toString() {
72 return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue()
73 + ")>";
74 }
75 }