/* * 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 parser.extension; import java.util.Map; import groovy.lang.GroovySystem; import groovy.util.Node; /** * This subclass of Node adds 4 extra slots holding information about the * source of the element, for use in error messages * */ public class NodeWithLoc extends Node { private static final long serialVersionUID = -7225399838380999241L; static { // wrap the standard MetaClass with the delegate setMetaClass(NodeWithLoc.class, GroovySystem.getMetaClassRegistry().getMetaClass(NodeWithLoc.class)); } private String publicId; private String systemId; private int lineNbr; private int colNbr; // Delegate all the constructors we need public NodeWithLoc(Node parent, Object name, Map attributes, Object value) { super(parent, name, attributes, value); } public NodeWithLoc(Node parent, Object name, Map attributes) { super(parent, name, attributes); } public NodeWithLoc(Node parent, Object name, Object value) { super(parent, name, value); } public NodeWithLoc(Node parent, Object name) { super(parent, name); } // Add a setter for Attributes // This allows things like // myNode.@attributename = 'abc' public void setAttribute(String key, Object value) { attributes().put(key, value); } public String getPublicId() { return publicId; } public void setPublicId(String publicId) { this.publicId = publicId.intern(); } public String getSystemId() { return systemId; } public void setSystemId(String systemId) { this.systemId = systemId.intern(); } public int getLineNbr() { return lineNbr; } public void setLineNbr(int lineNbr) { this.lineNbr = lineNbr; } public int getColNbr() { return colNbr; } public void setColNbr(int colNbr) { this.colNbr = colNbr; } }