1 /* 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.xml.internal.bind.v2.runtime.unmarshaller; 27 28 import java.net.URL; 29 30 import javax.xml.bind.ValidationEventLocator; 31 32 import org.xml.sax.Locator; 33 import org.w3c.dom.Node; 34 35 /** 36 * Object that returns the current location that the {@code com.sun.xml.internal.bind.v2.runtime.unmarshaller.XmlVisitor} 37 * is parsing. 38 * 39 * @author Kohsuke Kawaguchi 40 */ 41 public interface LocatorEx extends Locator { 42 /** 43 * Gets the current location in a {@link ValidationEventLocator} object. 44 * @return 45 */ 46 ValidationEventLocator getLocation(); 47 48 /** 49 * Immutable snapshot of a {@link LocatorEx} 50 */ 51 public static final class Snapshot implements LocatorEx, ValidationEventLocator { 52 private final int columnNumber,lineNumber,offset; 53 private final String systemId,publicId; 54 private final URL url; 55 private final Object object; 56 private final Node node; 57 58 public Snapshot(LocatorEx loc) { 59 columnNumber = loc.getColumnNumber(); 60 lineNumber = loc.getLineNumber(); 61 systemId = loc.getSystemId(); 62 publicId = loc.getPublicId(); 63 64 ValidationEventLocator vel = loc.getLocation(); 65 offset = vel.getOffset(); 66 url = vel.getURL(); 67 object = vel.getObject(); 68 node = vel.getNode(); 69 } 70 71 public Object getObject() { 72 return object; 73 } 74 75 public Node getNode() { 76 return node; 77 } 78 79 public int getOffset() { 80 return offset; 81 } 82 83 public URL getURL() { 84 return url; 85 } 86 87 public int getColumnNumber() { 88 return columnNumber; 89 } 90 91 public int getLineNumber() { 92 return lineNumber; 93 } 94 95 public String getSystemId() { 96 return systemId; 97 } 98 99 public String getPublicId() { 100 return publicId; 101 } 102 103 public ValidationEventLocator getLocation() { 104 return this; 105 } 106 } 107 }