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.events; 18 19 import java.util.Map; 20 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 Integer[] version; 32 private final Map<String, String> tags; 33 34 public DocumentStartEvent(Mark startMark, Mark endMark, boolean explicit, Integer[] version, 35 Map<String, String> tags) { 36 super(startMark, endMark); 37 this.explicit = explicit; 38 this.version = version; 39 this.tags = tags; 40 } 41 42 public boolean getExplicit() { 43 return explicit; 44 } 45 46 /** 47 * YAML version the document conforms to. 48 * 49 * @return <code>null</code>if the document has no explicit 50 * <code>%YAML</code> directive. Otherwise an array with two 51 * components, the major and minor part of the version (in this 52 * order). 53 */ 54 public Integer[] getVersion() { 55 return version; 56 } 57 58 /** 59 * Tag shorthands as defined by the <code>%TAG</code> directive. 60 * 61 * @return Mapping of 'handles' to 'prefixes' (the handles include the '!' 62 * characters). 63 */ 64 public Map<String, String> getTags() { 65 return tags; 66 } 67 68 @Override 69 public boolean is(Event.ID id) { 70 return ID.DocumentStart == id; 71 } 72 }