You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/12/08 22:48:50 UTC
svn commit: r888581 - in /cxf/branches/2.2.x-fixes: ./
tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Author: dkulp
Date: Tue Dec 8 21:48:49 2009
New Revision: 888581
URL: http://svn.apache.org/viewvc?rev=888581&view=rev
Log:
Merged revisions 888567 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r888567 | dkulp | 2009-12-08 16:00:28 -0500 (Tue, 08 Dec 2009) | 1 line
[CXF-2571] ANother attempt at a fix for jar URL's with xjc
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=888581&r1=888580&r2=888581&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java (original)
+++ cxf/branches/2.2.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java Tue Dec 8 21:48:49 2009
@@ -45,6 +45,7 @@
import javax.xml.validation.SchemaFactory;
+import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -70,6 +71,8 @@
import com.sun.tools.xjc.api.TypeAndAnnotation;
import com.sun.tools.xjc.api.XJC;
+import org.apache.cxf.Bus;
+import org.apache.cxf.catalog.OASISCatalogManager;
import org.apache.cxf.common.WSDLConstants;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
@@ -101,8 +104,11 @@
boolean isImport;
boolean isInclude;
int locIdx = -1;
- LocationFilterReader(XMLStreamReader read) {
+ OASISCatalogManager catalog;
+
+ LocationFilterReader(XMLStreamReader read, OASISCatalogManager catalog) {
super(read);
+ this.catalog = catalog;
}
public int next() throws XMLStreamException {
@@ -110,9 +116,6 @@
if (i == XMLStreamReader.START_ELEMENT) {
QName qn = super.getName();
isInclude = qn.equals(WSDLConstants.QNAME_SCHEMA_INCLUDE);
- if (isInclude) {
- return nextTag();
- }
isImport = qn.equals(WSDLConstants.QNAME_SCHEMA_IMPORT);
if (isImport) {
findLocation();
@@ -131,10 +134,6 @@
if (i == XMLStreamReader.START_ELEMENT) {
QName qn = super.getName();
isInclude = qn.equals(WSDLConstants.QNAME_SCHEMA_INCLUDE);
- if (isInclude) {
- return super.nextTag();
- }
-
isImport = qn.equals(WSDLConstants.QNAME_SCHEMA_IMPORT);
if (isImport) {
findLocation();
@@ -170,9 +169,14 @@
}
return index;
}
+
+ private String mapSchemaLocation(String target) {
+ return JAXBDataBinding.mapSchemaLocation(target, this.getLocation().getSystemId(), catalog);
+ }
+
public String getAttributeValue(String namespaceURI, String localName) {
if (isInclude && "schemaLocation".equals(localName)) {
- return null;
+ return mapSchemaLocation(super.getAttributeValue(namespaceURI, localName));
}
return super.getAttributeValue(namespaceURI, localName);
}
@@ -180,7 +184,7 @@
if (isInclude) {
String n = getAttributeLocalName(index);
if ("schemaLocation".equals(n)) {
- return null;
+ return mapSchemaLocation(super.getAttributeValue(index));
}
}
return super.getAttributeValue(mapIdx(index));
@@ -385,6 +389,8 @@
ids.add(key);
}
}
+ Bus bus = context.get(Bus.class);
+ OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
@@ -393,7 +399,6 @@
if (ids.contains(key)) {
continue;
}
-
if (!key.startsWith("file:") && !key.startsWith("jar:")) {
XmlSchemaSerializer xser = new XmlSchemaSerializer();
xser.setExtReg(schemaCollection.getExtReg());
@@ -404,7 +409,7 @@
throw new RuntimeException(e);
}
Element ele = docs[0].getDocumentElement();
- ele = removeImportElement(ele);
+ ele = removeImportElement(ele, key, catalog);
if (context.get(ToolConstants.CFG_VALIDATE_WSDL) != null) {
String uri = null;
try {
@@ -447,8 +452,9 @@
} else {
in = new URL(key).openStream();
}
+
XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, in);
- reader = new LocationFilterReader(reader);
+ reader = new LocationFilterReader(reader, catalog);
InputSource is = new InputSource(key);
opts.addGrammar(is);
schemaCompiler.parseSchema(key, reader);
@@ -477,7 +483,7 @@
}
ids.add(key);
Element ele = sci.getElement();
- ele = removeImportElement(ele);
+ ele = removeImportElement(ele, key, catalog);
if (context.get(ToolConstants.CFG_VALIDATE_WSDL) != null) {
validateSchema(ele, sci.getSystemId());
}
@@ -619,7 +625,7 @@
return null;
}
- private Element removeImportElement(Element element) {
+ private Element removeImportElement(Element element, String sysId, OASISCatalogManager catalog) {
List<Element> impElemList = DOMUtils.findAllElementsByTagNameNS(element,
ToolConstants.SCHEMA_URI,
"import");
@@ -639,18 +645,17 @@
Node importNode = elem;
ns.add(importNode);
}
+ for (Node item : ns) {
+ Node schemaNode = item.getParentNode();
+ schemaNode.removeChild(item);
+ }
+
incElemList = DOMUtils.findAllElementsByTagNameNS(element,
ToolConstants.SCHEMA_URI,
"include");
for (Element elem : incElemList) {
- Node importNode = elem;
- ns.add(importNode);
- }
-
-
- for (Node item : ns) {
- Node schemaNode = item.getParentNode();
- schemaNode.removeChild(item);
+ Attr val = elem.getAttributeNode("schemaLocation");
+ val.setNodeValue(mapSchemaLocation(val.getNodeValue(), sysId, catalog));
}
return element;
}
@@ -985,6 +990,35 @@
}
}
}
-
+ private static String mapSchemaLocation(String target, String base, OASISCatalogManager catalog) {
+ if (catalog != null) {
+ try {
+ String resolvedLocation = catalog.resolveSystem(target);
+
+ if (resolvedLocation == null) {
+ resolvedLocation = catalog.resolveURI(target);
+ }
+ if (resolvedLocation == null) {
+ resolvedLocation = catalog.resolvePublic(target, base);
+ }
+ if (resolvedLocation != null) {
+ return resolvedLocation;
+ }
+
+ } catch (Exception ex) {
+ //ignore
+ }
+ }
+ try {
+ //JAXB xjc cannot properly do this for "jar" URL's so we'll go ahead and do
+ //the resolving ourselves.
+ URL url = new URL(base);
+ url = new URL(url, target);
+ return url.toString();
+ } catch (Exception ex) {
+ //ignore
+ }
+ return target;
+ }
}