1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/unmarshaller/XmlVisitor.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,153 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.bind.v2.runtime.unmarshaller; 1.30 + 1.31 +import javax.xml.namespace.NamespaceContext; 1.32 + 1.33 +import org.xml.sax.SAXException; 1.34 + 1.35 +/** 1.36 + * Walks the XML document structure. 1.37 + * 1.38 + * Implemented by the unmarshaller and called by the API-specific connectors. 1.39 + * 1.40 + * <h2>Event Call Sequence</h2> 1.41 + * 1.42 + * The {@link XmlVisitor} expects the event callbacks in the following order: 1.43 + * <pre> 1.44 + * CALL SEQUENCE := startDocument ELEMENT endDocument 1.45 + * ELEMENT := startPrefixMapping ELEMENT endPrefixMapping 1.46 + * | startElement BODY endElement 1.47 + * BODY := text? (ELEMENT text?)* 1.48 + * </pre> 1.49 + * Note in particular that text events may not be called in a row; 1.50 + * consecutive characters (even those separated by PIs and comments) 1.51 + * must be reported as one event, unlike SAX. 1.52 + * 1.53 + * <p> 1.54 + * All namespace URIs, local names, and prefixes of element and attribute 1.55 + * names must be interned. qnames need not be interned. 1.56 + * 1.57 + * 1.58 + * <h2>Typed PCDATA</h2> 1.59 + * For efficiency, JAXB RI defines a few {@link CharSequence} implementations 1.60 + * that can be used as a parameter to the {@link #text(CharSequence)} method. 1.61 + * For example, see {@link Base64Data}. 1.62 + * 1.63 + * <h2>Error Handling</h2> 1.64 + * The visitor may throw {@link SAXException} to abort the unmarshalling process 1.65 + * in the middle. 1.66 + * 1.67 + * @author Kohsuke Kawaguchi 1.68 + */ 1.69 +public interface XmlVisitor { 1.70 + /** 1.71 + * Notifies a start of the document. 1.72 + * 1.73 + * @param locator 1.74 + * This live object returns the location information as the parsing progresses. 1.75 + * must not be null. 1.76 + * @param nsContext 1.77 + * Some broken XML APIs can't iterate all the in-scope namespace bindings, 1.78 + * which makes it impossible to emulate {@link #startPrefixMapping(String, String)} correctly 1.79 + * when unmarshalling a subtree. Connectors that use such an API can 1.80 + * pass in additional {@link NamespaceContext} object that knows about the 1.81 + * in-scope namespace bindings. Otherwise (and normally) it is null. 1.82 + * 1.83 + * <p> 1.84 + * Ideally this object should be immutable and only represent the namespace URI bindings 1.85 + * in the context (those done above the element that JAXB started unmarshalling), 1.86 + * but it can also work even if it changes as the parsing progress (to include 1.87 + * namespaces declared on the current element being parsed.) 1.88 + */ 1.89 + void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException; 1.90 + void endDocument() throws SAXException; 1.91 + 1.92 + /** 1.93 + * Notifies a start tag of a new element. 1.94 + * 1.95 + * namespace URIs and local names must be interned. 1.96 + */ 1.97 + void startElement(TagName tagName) throws SAXException; 1.98 + void endElement(TagName tagName) throws SAXException; 1.99 + 1.100 + /** 1.101 + * Called before {@link #startElement} event to notify a new namespace binding. 1.102 + */ 1.103 + void startPrefixMapping( String prefix, String nsUri ) throws SAXException; 1.104 + /** 1.105 + * Called after {@link #endElement} event to notify the end of a binding. 1.106 + */ 1.107 + void endPrefixMapping( String prefix ) throws SAXException; 1.108 + 1.109 + /** 1.110 + * Text events. 1.111 + * 1.112 + * <p> 1.113 + * The caller should consult {@link TextPredictor} to see 1.114 + * if the unmarshaller is expecting any PCDATA. If the above is returning 1.115 + * false, the caller is OK to skip any text in XML. The net effect is 1.116 + * that we can ignore whitespaces quickly. 1.117 + * 1.118 + * @param pcdata 1.119 + * represents character data. This object can be mutable 1.120 + * (such as {@link StringBuilder}); it only needs to be fixed 1.121 + * while this method is executing. 1.122 + */ 1.123 + void text( CharSequence pcdata ) throws SAXException; 1.124 + 1.125 + /** 1.126 + * Returns the {@link UnmarshallingContext} at the end of the chain. 1.127 + * 1.128 + * @return 1.129 + * always return the same object, so caching the result is recommended. 1.130 + */ 1.131 + UnmarshallingContext getContext(); 1.132 + 1.133 + /** 1.134 + * Gets the predictor that can be used for the caller to avoid 1.135 + * calling {@link #text(CharSequence)} unnecessarily. 1.136 + */ 1.137 + TextPredictor getPredictor(); 1.138 + 1.139 + interface TextPredictor { 1.140 + /** 1.141 + * Returns true if the visitor is expecting a text event as the next event. 1.142 + * 1.143 + * <p> 1.144 + * This is primarily intended to be used for optimization to avoid buffering 1.145 + * characters unnecessarily. If this method returns false and the connector 1.146 + * sees whitespace it can safely skip it. 1.147 + * 1.148 + * <p> 1.149 + * If this method returns true, all the whitespaces are considered significant 1.150 + * and thus need to be reported as a {@link XmlVisitor#text} event. Furthermore, 1.151 + * if the element has no children (like <foo/>), then it has to be reported 1.152 + * an empty {@link XmlVisitor#text} event. 1.153 + */ 1.154 + boolean expectText(); 1.155 + } 1.156 +}