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/InterningXmlVisitor.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,154 @@ 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.Attributes; 1.34 +import org.xml.sax.SAXException; 1.35 + 1.36 +/** 1.37 + * {@link XmlVisitor} decorator that interns all string tokens. 1.38 + * 1.39 + * @author Kohsuke Kawaguchi 1.40 + */ 1.41 +public final class InterningXmlVisitor implements XmlVisitor { 1.42 + private final XmlVisitor next; 1.43 + 1.44 + private final AttributesImpl attributes = new AttributesImpl(); 1.45 + 1.46 + public InterningXmlVisitor(XmlVisitor next) { 1.47 + this.next = next; 1.48 + } 1.49 + 1.50 + public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException { 1.51 + next.startDocument(locator,nsContext); 1.52 + } 1.53 + 1.54 + public void endDocument() throws SAXException { 1.55 + next.endDocument(); 1.56 + } 1.57 + 1.58 + public void startElement(TagName tagName ) throws SAXException { 1.59 + attributes.setAttributes(tagName.atts); 1.60 + tagName.atts = attributes; 1.61 + tagName.uri = intern(tagName.uri); 1.62 + tagName.local = intern(tagName.local); 1.63 + next.startElement(tagName); 1.64 + } 1.65 + 1.66 + public void endElement(TagName tagName ) throws SAXException { 1.67 + tagName.uri = intern(tagName.uri); 1.68 + tagName.local = intern(tagName.local); 1.69 + next.endElement(tagName); 1.70 + } 1.71 + 1.72 + public void startPrefixMapping( String prefix, String nsUri ) throws SAXException { 1.73 + next.startPrefixMapping(intern(prefix),intern(nsUri)); 1.74 + } 1.75 + 1.76 + public void endPrefixMapping( String prefix ) throws SAXException { 1.77 + next.endPrefixMapping(intern(prefix)); 1.78 + } 1.79 + 1.80 + public void text( CharSequence pcdata ) throws SAXException { 1.81 + next.text(pcdata); 1.82 + } 1.83 + 1.84 + public UnmarshallingContext getContext() { 1.85 + return next.getContext(); 1.86 + } 1.87 + 1.88 + public TextPredictor getPredictor() { 1.89 + return next.getPredictor(); 1.90 + } 1.91 + 1.92 + private static class AttributesImpl implements Attributes { 1.93 + private Attributes core; 1.94 + 1.95 + void setAttributes(Attributes att) { 1.96 + this.core = att; 1.97 + } 1.98 + 1.99 + public int getIndex(String qName) { 1.100 + return core.getIndex(qName); 1.101 + } 1.102 + 1.103 + public int getIndex(String uri, String localName) { 1.104 + return core.getIndex(uri, localName); 1.105 + } 1.106 + 1.107 + public int getLength() { 1.108 + return core.getLength(); 1.109 + } 1.110 + 1.111 + public String getLocalName(int index) { 1.112 + return intern(core.getLocalName(index)); 1.113 + } 1.114 + 1.115 + public String getQName(int index) { 1.116 + return intern(core.getQName(index)); 1.117 + } 1.118 + 1.119 + public String getType(int index) { 1.120 + return intern(core.getType(index)); 1.121 + } 1.122 + 1.123 + public String getType(String qName) { 1.124 + return intern(core.getType(qName)); 1.125 + } 1.126 + 1.127 + public String getType(String uri, String localName) { 1.128 + return intern(core.getType(uri, localName)); 1.129 + } 1.130 + 1.131 + public String getURI(int index) { 1.132 + return intern(core.getURI(index)); 1.133 + } 1.134 + 1.135 + // 1.136 + // since values may vary a lot, 1.137 + // we don't (probably shouldn't) intern values. 1.138 + // 1.139 + 1.140 + public String getValue(int index) { 1.141 + return core.getValue(index); 1.142 + } 1.143 + 1.144 + public String getValue(String qName) { 1.145 + return core.getValue(qName); 1.146 + } 1.147 + 1.148 + public String getValue(String uri, String localName) { 1.149 + return core.getValue(uri, localName); 1.150 + } 1.151 + } 1.152 + 1.153 + private static String intern(String s) { 1.154 + if(s==null) return null; 1.155 + else return s.intern(); 1.156 + } 1.157 +}