1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/AbstractReferenceFinderImpl.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,119 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, 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.tools.internal.ws.wsdl.parser; 1.30 + 1.31 +import com.sun.istack.internal.SAXParseException2; 1.32 +import com.sun.tools.internal.ws.resources.WsdlMessages; 1.33 +import org.xml.sax.Attributes; 1.34 +import org.xml.sax.Locator; 1.35 +import org.xml.sax.SAXException; 1.36 +import org.xml.sax.SAXParseException; 1.37 +import org.xml.sax.helpers.XMLFilterImpl; 1.38 + 1.39 +import java.io.IOException; 1.40 +import java.net.URI; 1.41 +import java.net.URISyntaxException; 1.42 +import java.net.URL; 1.43 + 1.44 +/** 1.45 + * XMLFilter that finds references to other schema files from 1.46 + * SAX events. 1.47 + * 1.48 + * This implementation is a base implementation for typical case 1.49 + * where we just need to look for a particular attribute which 1.50 + * contains an URL to another schema file. 1.51 + * 1.52 + * @author 1.53 + * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 1.54 + * Vivek Pandey 1.55 + */ 1.56 +public abstract class AbstractReferenceFinderImpl extends XMLFilterImpl { 1.57 + protected final DOMForest parent; 1.58 + 1.59 + protected AbstractReferenceFinderImpl( DOMForest _parent ) { 1.60 + this.parent = _parent; 1.61 + } 1.62 + 1.63 + /** 1.64 + * IF the given element contains a reference to an external resource, 1.65 + * return its URL. 1.66 + * 1.67 + * @param nsURI 1.68 + * Namespace URI of the current element 1.69 + * @param localName 1.70 + * Local name of the current element 1.71 + * @return 1.72 + * It's OK to return a relative URL. 1.73 + */ 1.74 + protected abstract String findExternalResource( String nsURI, String localName, Attributes atts); 1.75 + 1.76 + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) 1.77 + throws SAXException { 1.78 + super.startElement(namespaceURI, localName, qName, atts); 1.79 + 1.80 + String relativeRef = findExternalResource(namespaceURI,localName,atts); 1.81 + if(relativeRef==null) return; // non found 1.82 + 1.83 + try { 1.84 + // absolutize URL. 1.85 + String lsi = locator.getSystemId(); 1.86 + String ref; 1.87 + if (lsi.startsWith("jar:")) { 1.88 + int bangIdx = lsi.indexOf('!'); 1.89 + if (bangIdx > 0) { 1.90 + ref = new URL(new URL(lsi), relativeRef).toString(); 1.91 + } else 1.92 + ref = relativeRef; 1.93 + } else 1.94 + ref = new URI(lsi).resolve(new URI(relativeRef)).toString(); 1.95 + 1.96 + // then parse this schema as well, 1.97 + // but don't mark this document as a root. 1.98 + parent.parse(ref,false); 1.99 + } catch( URISyntaxException e ) { 1.100 + SAXParseException spe = new SAXParseException2( 1.101 + WsdlMessages.ABSTRACT_REFERENCE_FINDER_IMPL_UNABLE_TO_PARSE(relativeRef,e.getMessage()), 1.102 + locator, e ); 1.103 + 1.104 + fatalError(spe); 1.105 + throw spe; 1.106 + } catch( IOException e ) { 1.107 + SAXParseException spe = new SAXParseException2( 1.108 + WsdlMessages.ABSTRACT_REFERENCE_FINDER_IMPL_UNABLE_TO_PARSE(relativeRef,e.getMessage()), 1.109 + locator, e ); 1.110 + 1.111 + fatalError(spe); 1.112 + throw spe; 1.113 + } 1.114 + } 1.115 + 1.116 + private Locator locator; 1.117 + 1.118 + public void setDocumentLocator(Locator locator) { 1.119 + super.setDocumentLocator(locator); 1.120 + this.locator = locator; 1.121 + } 1.122 +}