• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 package org.yaml.snakeyaml.events;
17 
18 import java.util.Map;
19 
20 import org.yaml.snakeyaml.DumperOptions.Version;
21 import org.yaml.snakeyaml.error.Mark;
22 
23 /**
24  * Marks the beginning of a document.
25  * <p>
26  * This event followed by the document's content and a {@link DocumentEndEvent}.
27  * </p>
28  */
29 public final class DocumentStartEvent extends Event {
30     private final boolean explicit;
31     private final Version version;
32     private final Map<String, String> tags;
33 
DocumentStartEvent(Mark startMark, Mark endMark, boolean explicit, Version version, Map<String, String> tags)34     public DocumentStartEvent(Mark startMark, Mark endMark, boolean explicit, Version version,
35             Map<String, String> tags) {
36         super(startMark, endMark);
37         this.explicit = explicit;
38         this.version = version;
39         // TODO enforce not null
40         // if (tags == null) {
41         // throw new NullPointerException("Tags must be provided.");
42         // }
43         this.tags = tags;
44     }
45 
getExplicit()46     public boolean getExplicit() {
47         return explicit;
48     }
49 
50     /**
51      * YAML version the document conforms to.
52      *
53      * @return <code>null</code>if the document has no explicit
54      *         <code>%YAML</code> directive. Otherwise an array with two
55      *         components, the major and minor part of the version (in this
56      *         order).
57      */
getVersion()58     public Version getVersion() {
59         return version;
60     }
61 
62     /**
63      * Tag shorthands as defined by the <code>%TAG</code> directive.
64      *
65      * @return Mapping of 'handles' to 'prefixes' (the handles include the '!'
66      *         characters).
67      */
getTags()68     public Map<String, String> getTags() {
69         return tags;
70     }
71 
72     @Override
is(Event.ID id)73     public boolean is(Event.ID id) {
74         return ID.DocumentStart == id;
75     }
76 }
77