javaee / jaxb-v2

Other
211 stars 101 forks source link

Support for catalog in binding files #1115

Open glassfishrobot opened 7 years ago

glassfishrobot commented 7 years ago

I am unsure if this is the right place to raise this item and whether it is a feature request or a bug.

I have a project, which uses a third party XML schemas and in that connection I am trying to generate some JAXB classes.

In addition to the XML schemas there is a binding file used together with it, which refers to the XML schemas using the schemaLocation attribute and it is using relative path e.g. ../../../../main/src/resources...

The organization of the third party project seems a bit non intuitively, and I decided to reorganize the location of the xsd and the binding file to be closer however when I try to generate the JAXB classes. I get an error that the xsd file is not part of the compilation.

I thought by introducing a catalog file this should be fixed. However it didn't.

I have debugged the xjc generator and tracked down the error to the method com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap

in the following code snippet.

try { // TODO: use the URI class // TODO: honor xml:base URL loc = new URL( new URL(forest.getSystemId(bindings.getOwnerDocument())), schemaLocation ); schemaLocation = loc.toExternalForm(); target = forest.get(schemaLocation); if ((target == null) && (loc.getProtocol().startsWith("file")))

{ File f = new File(loc.getFile()); schemaLocation = new File(f.getCanonicalPath()).toURI().toString(); }

} catch( MalformedURLException e ) { } catch( IOException e )

{ Logger.getLogger(Internalizer.class.getName()).log(Level.FINEST, e.getLocalizedMessage()); }

target = forest.get(schemaLocation); if(target==null)

{ reportError( bindings, Messages.format(Messages.ERR_INCORRECT_SCHEMA_REFERENCE, schemaLocation, EditDistance.findNearest(schemaLocation,forest.listSystemIDs()))); return; // abort processing this }

For me it seems like the catalog is not supported in the current implementation.

There are several workarounds for this issue, however the todo comment about to support xml:base seems to suggest that there should have been support for xml catalog.

I can't seem to find any reports on this issue so I am raising it. In case it is a feature that should have been in. I would be happy to try to contribute

My suggestion would be to use the entity resolver available an use that to resolve it.

As I wrote initially if this is not the right to place the feature request or bug, please point me to the right place. Thanks in advance

glassfishrobot commented 7 years ago

Reported by mat013

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA JAXB-1115