src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/unmarshaller/StAXConnector.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2011, 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  */
    26 package com.sun.xml.internal.bind.v2.runtime.unmarshaller;
    28 import javax.xml.bind.ValidationEventLocator;
    29 import javax.xml.bind.helpers.ValidationEventLocatorImpl;
    30 import javax.xml.namespace.NamespaceContext;
    31 import javax.xml.stream.Location;
    32 import javax.xml.stream.XMLStreamException;
    34 import org.xml.sax.SAXException;
    36 /**
    37  * @author Kohsuke Kawaguchi
    38  */
    39 abstract class StAXConnector {
    40     public abstract void bridge() throws XMLStreamException;
    43     // event sink
    44     protected final XmlVisitor visitor;
    46     protected final UnmarshallingContext context;
    47     protected final XmlVisitor.TextPredictor predictor;
    49     private final class TagNameImpl extends TagName {
    50         public String getQname() {
    51             return StAXConnector.this.getCurrentQName();
    52         }
    53     }
    55     protected final TagName tagName = new TagNameImpl();
    57     protected StAXConnector(XmlVisitor visitor) {
    58         this.visitor = visitor;
    59         context = visitor.getContext();
    60         predictor = visitor.getPredictor();
    61     }
    63     /**
    64      * Gets the {@link Location}. Used for implementing the line number information.
    65      * @return must not null.
    66      */
    67     protected abstract Location getCurrentLocation();
    69     /**
    70      * Gets the QName of the current element.
    71      */
    72     protected abstract String getCurrentQName();
    74     protected final void handleStartDocument(NamespaceContext nsc) throws SAXException {
    75         visitor.startDocument(new LocatorEx() {
    76             public ValidationEventLocator getLocation() {
    77                 return new ValidationEventLocatorImpl(this);
    78             }
    79             public int getColumnNumber() {
    80                 return getCurrentLocation().getColumnNumber();
    81             }
    82             public int getLineNumber() {
    83                 return getCurrentLocation().getLineNumber();
    84             }
    85             public String getPublicId() {
    86                 return getCurrentLocation().getPublicId();
    87             }
    88             public String getSystemId() {
    89                 return getCurrentLocation().getSystemId();
    90             }
    91         },nsc);
    92     }
    94     protected final void handleEndDocument() throws SAXException {
    95         visitor.endDocument();
    96     }
    98     protected static String fixNull(String s) {
    99         if(s==null) return "";
   100         else        return s;
   101     }
   103     protected final String getQName(String prefix, String localName) {
   104         if(prefix==null || prefix.length()==0)
   105             return localName;
   106         else
   107             return prefix + ':' + localName;
   108     }
   109 }

mercurial