src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/AbstractReferenceFinderImpl.java

changeset 397
b99d7e355d4b
parent 368
0989ad8c0860
child 637
9c07ef4934dd
equal deleted inserted replaced
393:6cdc6ed98780 397:b99d7e355d4b
23 * questions. 23 * questions.
24 */ 24 */
25 25
26 package com.sun.tools.internal.xjc.reader.internalizer; 26 package com.sun.tools.internal.xjc.reader.internalizer;
27 27
28 import java.io.IOException;
29 import java.io.File;
30 import java.net.URI;
31 import java.net.URISyntaxException;
32
33 import com.sun.istack.internal.SAXParseException2; 28 import com.sun.istack.internal.SAXParseException2;
34
35 import org.xml.sax.Attributes; 29 import org.xml.sax.Attributes;
36 import org.xml.sax.Locator; 30 import org.xml.sax.Locator;
37 import org.xml.sax.SAXException; 31 import org.xml.sax.SAXException;
38 import org.xml.sax.SAXParseException; 32 import org.xml.sax.SAXParseException;
39 import org.xml.sax.helpers.XMLFilterImpl; 33 import org.xml.sax.helpers.XMLFilterImpl;
40 34
35 import java.io.File;
36 import java.io.IOException;
37 import java.net.URI;
38 import java.net.URISyntaxException;
39
41 /** 40 /**
42 * XMLFilter that finds references to other schema files from 41 * XMLFilter that finds references to other schema files from
43 * SAX events. 42 * SAX events.
44 * 43 * <p/>
45 * This implementation is a base implementation for typical case 44 * This implementation is a base implementation for typical case
46 * where we just need to look for a particular attribute which 45 * where we just need to look for a particular attribute which
47 * contains an URL to another schema file. 46 * contains an URL to another schema file.
48 * 47 *
49 * @author 48 * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
50 * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
51 */ 49 */
52 public abstract class AbstractReferenceFinderImpl extends XMLFilterImpl { 50 public abstract class AbstractReferenceFinderImpl extends XMLFilterImpl {
53 51
54 protected final DOMForest parent; 52 protected final DOMForest parent;
55 53
59 57
60 /** 58 /**
61 * IF the given element contains a reference to an external resource, 59 * IF the given element contains a reference to an external resource,
62 * return its URL. 60 * return its URL.
63 * 61 *
64 * @param nsURI 62 * @param nsURI Namespace URI of the current element
65 * Namespace URI of the current element 63 * @param localName Local name of the current element
66 * @param localName 64 * @return It's OK to return a relative URL.
67 * Local name of the current element
68 * @return
69 * It's OK to return a relative URL.
70 */ 65 */
71 protected abstract String findExternalResource(String nsURI, String localName, Attributes atts); 66 protected abstract String findExternalResource(String nsURI, String localName, Attributes atts);
72 67
73 @Override 68 @Override
74 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) 69 public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
81 } 76 }
82 try { 77 try {
83 // absolutize URL. 78 // absolutize URL.
84 String lsi = locator.getSystemId(); 79 String lsi = locator.getSystemId();
85 String ref; 80 String ref;
86 if (lsi.startsWith("jar:")) { 81 URI relRefURI = new URI(relativeRef);
87 int bangIdx = lsi.indexOf('!'); 82 if (relRefURI.isAbsolute())
88 if (bangIdx > 0) { 83 ref = relativeRef;
89 ref = lsi.substring(0, bangIdx + 1) 84 else {
90 + new URI(lsi.substring(bangIdx + 1)).resolve(new URI(relativeRef)).toString(); 85 if (lsi.startsWith("jar:")) {
86 int bangIdx = lsi.indexOf('!');
87 if (bangIdx > 0) {
88 ref = lsi.substring(0, bangIdx + 1)
89 + new URI(lsi.substring(bangIdx + 1)).resolve(new URI(relativeRef)).toString();
90 } else {
91 ref = relativeRef;
92 }
91 } else { 93 } else {
92 ref = relativeRef; 94 ref = new URI(lsi).resolve(new URI(relativeRef)).toString();
93 } 95 }
94 } else {
95 ref = new URI(lsi).resolve(new URI(relativeRef)).toString();
96 } 96 }
97 97
98 // then parse this schema as well, 98 // then parse this schema as well,
99 // but don't mark this document as a root. 99 // but don't mark this document as a root.
100 if (parent != null) { // this is there to allow easier testing 100 if (parent != null) { // this is there to allow easier testing
119 119
120 fatalError(spe); 120 fatalError(spe);
121 throw spe; 121 throw spe;
122 } 122 }
123 } 123 }
124
124 private Locator locator; 125 private Locator locator;
125 126
126 @Override 127 @Override
127 public void setDocumentLocator(Locator locator) { 128 public void setDocumentLocator(Locator locator) {
128 super.setDocumentLocator(locator); 129 super.setDocumentLocator(locator);
129 this.locator = locator; 130 this.locator = locator;
130 } 131 }
131 }; 132 }

mercurial