blob: fb1d6ad653e9b3b8cfd46ea9c73d34f21523ace9 [file] [log] [blame]
/**
* Copyright (c) 2008-2009 Andrey Somov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.yaml.snakeyaml.nodes;
import org.yaml.snakeyaml.error.Mark;
/**
* @see <a href="http://pyyaml.org/wiki/PyYAML">PyYAML</a> for more information
*/
public abstract class Node {
private String tag;
private Mark startMark;
protected Mark endMark;
private Class<? extends Object> type;
private boolean twoStepsConstruction;
// Plain scalars without explicitly defined tag are subject to implicit tag
// resolution. The scalar value is checked against a set of regular
// expressions.
// This is false when the tag was resolved
protected boolean explicitTag;
public Node(String tag, Mark startMark, Mark endMark) {
setTag(tag);
this.startMark = startMark;
this.endMark = endMark;
this.type = Object.class;
this.twoStepsConstruction = false;
this.explicitTag = false;
}
public String getTag() {
return this.tag;
}
public Mark getEndMark() {
return endMark;
}
/**
* For error reporting.
*
* @see class variable 'id' in PyYAML
* @return scalar, sequence, mapping
*/
public abstract NodeId getNodeId();
public Mark getStartMark() {
return startMark;
}
public void setTag(String tag) {
if (tag == null) {
throw new NullPointerException("tag in a Node is required.");
}
this.tag = tag;
}
/*
* It is not allowed to overwrite this method. Two Nodes are never equal.
*/
@Override
public final boolean equals(Object obj) {
return super.equals(obj);
}
public Class<? extends Object> getType() {
return type;
}
public void setType(Class<? extends Object> type) {
this.type = type;
}
public void setTwoStepsConstruction(boolean twoStepsConstruction) {
this.twoStepsConstruction = twoStepsConstruction;
}
public boolean isTwoStepsConstruction() {
return twoStepsConstruction;
}
@Override
public final int hashCode() {
return super.hashCode();
}
/**
* Check if the tag is defined in the YAML document
*
* @return true when the tag is explicit, false when the tag is resolved
*/
public boolean hasExplicitTag() {
return explicitTag;
}
}