Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy: can't xml-bindings xml-transient parent class when it has same name in different package(Class foo.MyOwnGrandpa extends class mumble.MyOwnGrandpa.)
MOXy: can't xml-bindings xml-transient parent class when it has same name in different package [message #667089] Tue, 26 April 2011 16:47 Go to next message
Ed Staub is currently offline Ed StaubFriend
Messages: 16
Registered: April 2011
Junior Member
I'm trying to use schemagen with an external <xml-bindings> file.
Class foo.MyOwnGrandpa extends class mumble.MyOwnGrandpa.

I can't really touch the classes involved - especially the parent class, which is generated.

If I set xml-transient on the parent class, I get an error out of the AnnotationsProcessor:
Exception Description: Name collision.  Two classes have the XML type with uri  and name myOwnGrandpa.

The bindings file for the mumble package has no effect in this context, because of xml-transient. The bindings passed in to the AnnotationsProcessor are for the child package. So the obvious workaround - change the parent-class xml name or namespace - can't be used.

Am I missing something?
Any suggestions for a workaround?
Should I report this as a bug?

[Updated on: Tue, 26 April 2011 19:06]

Report message to a moderator

Re: MOXy: can't xml-bindings xml-transient parent class when it has same name in different package [message #667118 is a reply to message #667089] Tue, 26 April 2011 20:16 Go to previous messageGo to next message
Ed Staub is currently offline Ed StaubFriend
Messages: 16
Registered: April 2011
Junior Member
Hi Ed,

Yes, please enter a bug for this issue. You can workaround it using a binding file like the following:

binding-a.xml

In the binding file specify a type name for the transient class. This type will not appear in the generated XML schema:

<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="example.a">
    <java-types>
        <java-type name="MyOwnGrandpa" xml-transient="true">
            <xml-type name="MyOwnGrandpa2"/>
        </java-type>
    </java-types>
</xml-bindings>


example.a.MyOwnGrandpa

package example.a;

public class MyOwnGrandpa {

}


example.b.MyOwnGrandpa


package example.b;

public class MyOwnGrandpa extends example.a.MyOwnGrandpa {

}


example.Demo

package example;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import org.eclipse.persistence.jaxb.JAXBContextFactory;

import example.b.MyOwnGrandpa;

public class Demo {

    public static void main(String[] args) throws Exception {
        Map<String, Object> properties = new HashMap<String, Object>(1);
        properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, new File("src/exanmple/a/binding-a.xml"));
        JAXBContext jc = JAXBContext.newInstance(new Class[] {MyOwnGrandpa.class} , properties);
        jc.generateSchema(new MySOR());
    }

    private static class MySOR extends SchemaOutputResolver {

        @Override
        public Result createOutput(String arg0, String arg1) throws IOException {
            StreamResult result = new StreamResult(System.out);
            result.setSystemId(arg1);
            return result;
        }
    }

}


Generated Schema

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:complexType name="myOwnGrandpa"/>
</xsd:schema>


-Blaise
Re: MOXy: can't xml-bindings xml-transient parent class when it has same name in different package [message #667598 is a reply to message #667118] Fri, 29 April 2011 20:14 Go to previous messageGo to next message
Ed Staub is currently offline Ed StaubFriend
Messages: 16
Registered: April 2011
Junior Member
Doesn't work for me.

"package-name" attribute isn't in the oxm 2.1 schema - what version is this for?

Also, the binding-file registration appears to be incompatible with that shown in http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingSta rted/ExternalizedMetadata, where an intermediate map from package to Source is registered under ECLIPSELINK_OXM_XML_KEY.

Even if it works, I'd guess that setting the package in the root element of a global binding file to the parent's package:
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    [B]package-name="example.a"[/B]>

would preclude any configuration of classes in the child package - where most of them are.
Re: MOXy: can't xml-bindings xml-transient parent class when it has same name in different package [message #667854 is a reply to message #667598] Mon, 02 May 2011 13:20 Go to previous messageGo to next message
Ed Staub is currently offline Ed StaubFriend
Messages: 16
Registered: April 2011
Junior Member
Sorry - stupid me, I thought 2.1 was latest, not sure how. Anyway, I need bindings on multiple packages, so a global oxm file won't work, AFAICT.

Where are the semantics of the oxm binding file documented?
Re: MOXy: can't xml-bindings xml-transient parent class when it has same name in different package [message #667868 is a reply to message #667854] Mon, 02 May 2011 14:25 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi Ed,

You can have a bindings file per package. The following describes how to do this using EclipseLink 2.2. This can also be done in EclipseLink 2.1, but the code required is more verbose:

package example;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import org.eclipse.persistence.jaxb.JAXBContextFactory;

import example.b.MyOwnGrandpa;

public class Demo {

    public static void main(String[] args) throws Exception {
        Map<String, Object> properties = new HashMap<String, Object>(1);
        List<File> bindingFiles = new ArrayList<File>();
        bindingFiles.add(new File("src/example/a/binding-a.xml"));
        bindingFiles.add(new File("src/example/b/binding-b.xml"));
        properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, bindingFiles);
        JAXBContext jc = JAXBContext.newInstance(new Class[] {MyOwnGrandpa.class} , properties);
        jc.generateSchema(new MySOR());
    }

    private static class MySOR extends SchemaOutputResolver {

        @Override
        public Result createOutput(String arg0, String arg1) throws IOException {
            StreamResult result = new StreamResult(System.out);
            result.setSystemId(arg1);
            return result;
        }
    }
}


binding-a.xml

In EclipseLink 2.2, the package name can be specified in the bindings file:

<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="example.a">
    <java-types>
        <java-type name="MyOwnGrandpa" xml-transient="true">
            <xml-type name="MyOwnGrandpa2"/>
        </java-type>
    </java-types>
</xml-bindings>


binding-b.xml

<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="example.b">
    <java-types>
        <java-type name="MyOwnGrandpa">
            <java-attributes>
                <xml-attribute java-attribute="b"/>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>


-Blaise
Previous Topic:Relationships/FKs to non-PK columns
Next Topic:Working with whole schema
Goto Forum:
  


Current Time: Tue Apr 23 09:49:58 GMT 2024

Powered by FUDForum. Page generated in 0.04298 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top