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

Wed, 27 Apr 2016 01:27:09 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:27:09 +0800
changeset 0
373ffda63c9a
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17

     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.namespace.NamespaceContext;
    30 import org.xml.sax.Attributes;
    31 import org.xml.sax.SAXException;
    33 /**
    34  * {@link XmlVisitor} decorator that interns all string tokens.
    35  *
    36  * @author Kohsuke Kawaguchi
    37  */
    38 public final class InterningXmlVisitor implements XmlVisitor {
    39     private final XmlVisitor next;
    41     private final AttributesImpl attributes = new AttributesImpl();
    43     public InterningXmlVisitor(XmlVisitor next) {
    44         this.next = next;
    45     }
    47     public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
    48         next.startDocument(locator,nsContext);
    49     }
    51     public void endDocument() throws SAXException {
    52         next.endDocument();
    53     }
    55     public void startElement(TagName tagName ) throws SAXException {
    56         attributes.setAttributes(tagName.atts);
    57         tagName.atts = attributes;
    58         tagName.uri = intern(tagName.uri);
    59         tagName.local = intern(tagName.local);
    60         next.startElement(tagName);
    61     }
    63     public void endElement(TagName tagName ) throws SAXException {
    64         tagName.uri = intern(tagName.uri);
    65         tagName.local = intern(tagName.local);
    66         next.endElement(tagName);
    67     }
    69     public void startPrefixMapping( String prefix, String nsUri ) throws SAXException {
    70         next.startPrefixMapping(intern(prefix),intern(nsUri));
    71     }
    73     public void endPrefixMapping( String prefix ) throws SAXException {
    74         next.endPrefixMapping(intern(prefix));
    75     }
    77     public void text( CharSequence pcdata ) throws SAXException {
    78         next.text(pcdata);
    79     }
    81     public UnmarshallingContext getContext() {
    82         return next.getContext();
    83     }
    85     public TextPredictor getPredictor() {
    86         return next.getPredictor();
    87     }
    89     private static class AttributesImpl implements Attributes {
    90         private Attributes core;
    92         void setAttributes(Attributes att) {
    93             this.core = att;
    94         }
    96         public int getIndex(String qName) {
    97             return core.getIndex(qName);
    98         }
   100         public int getIndex(String uri, String localName) {
   101             return core.getIndex(uri, localName);
   102         }
   104         public int getLength() {
   105             return core.getLength();
   106         }
   108         public String getLocalName(int index) {
   109             return intern(core.getLocalName(index));
   110         }
   112         public String getQName(int index) {
   113             return intern(core.getQName(index));
   114         }
   116         public String getType(int index) {
   117             return intern(core.getType(index));
   118         }
   120         public String getType(String qName) {
   121             return intern(core.getType(qName));
   122         }
   124         public String getType(String uri, String localName) {
   125             return intern(core.getType(uri, localName));
   126         }
   128         public String getURI(int index) {
   129             return intern(core.getURI(index));
   130         }
   132         //
   133         // since values may vary a lot,
   134         // we don't (probably shouldn't) intern values.
   135         //
   137         public String getValue(int index) {
   138             return core.getValue(index);
   139         }
   141         public String getValue(String qName) {
   142             return core.getValue(qName);
   143         }
   145         public String getValue(String uri, String localName) {
   146             return core.getValue(uri, localName);
   147         }
   148     }
   150     private static String intern(String s) {
   151         if(s==null)     return null;
   152         else            return s.intern();
   153     }
   154 }

mercurial