[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] MOXy - [ERROR] Property “Any” is already defined

Hi Blaise,

Thanks for your suggestion.  Bug 395328 has been submitted which included a tar file that contains all the XML schema to replicate the problem.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=395328

For now I will generate bindings via JDK JAXB and then use MOXy during runtime.

Well before that, I have to spend time looking on JSON as well.  One of the reason I would like to use MOXy is it can create JSON bindings as well.

Thanks,

David


On Wed, Nov 28, 2012 at 1:48 PM, Blaise Doughan <blaise.doughan@xxxxxxxxxx> wrote:
Hi David,

Looks like there is a bug in the compiler script.  Would you mind entering a bug at the following link:
MOXy ships a version of the XJC tool from the JAXB reference implementation.  It wraps it with the MOXyXJC class.  MOXyXJC simply ensures that a jaxb.properties file specifying MOXy as the JAXB provider is placed in the model directory.  As a workaround you can use the XJC command from the JDK and manually add the jaxb.properties file in the generated directory.
-Blaise


On 12-11-28 1:29 PM, Chun Tat David Chu wrote:
Hi Blaise, MOXy Users,

You found my post on stackoverflow.  :-)
Sorry for the multiple posts but I guess I will stick with this mailing list since this is the EclipseLink MOXy community.  I will post back the answer to stackoverflow once I have a resolution.

Your suggestion does work only with the JAXB implementation bundles with the JAVA JDK.  See below for more detail...

Using the following external JAXB binding XML works when using the JAXB implementation bundles with java-1.6.0-openjdk-devel-1.6.0.0-1.45.1.11.1.el6.i686
Command Line Arg: xjc -d ./bindings ./xccdf-1.1.4.xsd -b ./xccdf-1.1.4_jaxb_property.xml

        <bindings node="//xsd:complexType[@name='metadataType']/xsd:sequence/xsd:choice">
            <bindings node=".//xsd:any[@namespace='http://purl.org/dc/elements/1.1/']">
                <property name="any_purl"/>
            </bindings>
            <bindings node=".//xsd:any[@namespace='http://checklists.nist.gov/sccf/0.1']">
                <property name="any_checklists"/>
            </bindings>
        </bindings>

However it doesn't work when using MOXy.  When running with MOXy eclipselink-2.4.1.v20121003-ad44345, I got the following...
Command Line Arg: ${ECLIPSELINK_HOME}/bin/jaxb-compiler.sh -d ./bindings ./xccdf-1.1.4.xsd -b ./xccdf-1.1.4_jaxb_property.xml

Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
    at $Proxy32.required(Unknown Source)
    at com.sun.tools.xjc.generator.bean.field.AbstractField.annotateReference(AbstractField.java:197)
    at com.sun.tools.xjc.generator.bean.field.AbstractField.annotate(AbstractField.java:156)
    at com.sun.tools.xjc.generator.bean.field.AbstractListField.generate(AbstractListField.java:124)
    at com.sun.tools.xjc.generator.bean.field.UntypedListField.<init>(UntypedListField.java:107)
    at com.sun.tools.xjc.generator.bean.field.UntypedListFieldRenderer.generate(UntypedListFieldRenderer.java:72)
    at com.sun.tools.xjc.generator.bean.field.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:79)
    at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:747)
    at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:535)
    at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:235)
    at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:175)
    at com.sun.tools.xjc.model.Model.generateCode(Model.java:286)
    at com.sun.tools.xjc.Driver.run(Driver.java:343)
    at org.eclipse.persistence.jaxb.xjc.MOXyXJC.main(MOXyXJC.java:48)
Caused by: java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required()
    at java.lang.Class.getDeclaredMethod(Class.java:1954)
    at com.sun.codemodel.TypedAnnotationWriter.invoke(TypedAnnotationWriter.java:107)

Is this a bug in MOXy?

Thanks,

David

On Wed, Nov 28, 2012 at 1:25 PM, Blaise Doughan <blaise.doughan@xxxxxxxxxx> wrote:
Hello David,

You can use an external bindings file to rename one of the any properties.

binding.xml

<jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">

    <jxb:bindings schemaLocation="schema.xsd">
        <jxb:bindings
            node="//xsd:complexType[@name='foo']/xsd:sequence/xsd:choice/xsd:any[@namespace='http://checklists.nist.gov/sccf/0.1']">
            <jxb:property name="any2" />
        </jxb:bindings>
    </jxb:bindings>

</jxb:bindings>

XML Schema (schema.xsd)

Below is a simplified version of your XML schema:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/schema" 
    xmlns="http://www.example.org/schema"
    elementFormDefault="qualified">

    <xsd:complexType name="foo">
<xsd:sequence> <xsd:choice minOccurs="1" maxOccurs="1"> <xsd:any namespace=""
minOccurs="1" maxOccurs="unbounded" /> <xsd:any namespace="http://checklists.nist.gov/sccf/0.1" processContents="skip" minOccurs="1" maxOccurs="unbounded" /> </xsd:choice> </xsd:sequence>
</xsd:complexType> </xsd:schema>

XJC Call

Below is how you make an XJC call that leverages an external binding file.

xjc -b binding.xml schema.xsd

Generated Class (Foo)

package org.example.schema;

import java.util.*;
import javax.xml.bind.annotation.*;
import org.w3c.dom.Element;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "foo", propOrder = {
    "any",
    "any2"
})
public class Foo {

    @XmlAnyElement(lax = true)
    protected List<Object> any;
    @XmlAnyElement
    protected List<Element> any2;


    public List<Object> getAny() {
        if (any == null) {
            any = new ArrayList<Object>();
        }
        return this.any;
    }

    public List<Element> getAny2() {
        if (any2 == null) {
            any2 = new ArrayList<Element>();
        }
        return this.any2;
    }

}
Link to discussion on Stack Overflow:
-Blaise


On 12-11-28 12:48 PM, Chun Tat David Chu wrote:
Hi MOXy Users,

I am trying to create JAXB binding for xccdf-1.1.4.xsd which is a standard schema that can be obtain from http://scap.nist.gov/specifications/xccdf/#resource-1.1.4

I fixed couple occasions where I hit the infamous "[ERROR] Property "value" is already defined" error using an external binding XML, and now I am hitting an error on

    [ERROR] Property "Any" is already defined. Use &lt;jaxb:property> to resolve this conflict.
    line 441 of file:/home/dchu/Playground/Java/eclipselink_moxy/xccdf_1.1.4/xccdf-1.1.4.xsd

    [ERROR] The following location is relevant to the above error
    line 444 of file:/home/dchu/Playground/Java/eclipselink_moxy/xccdf_1.1.4/xccdf-1.1.4.xs

Below is a snippet of the line in the XML schema where the error occurred.
        <xsd:sequence>
            <xsd:choice minOccurs="1" maxOccurs="1">
              <xsd:any namespace="http://purl.org/dc/elements/1.1/"
                       minOccurs="1" maxOccurs="unbounded"/>
              <xsd:any namespace="http://checklists.nist.gov/sccf/0.1"
                       processContents="skip"
                       minOccurs="1" maxOccurs="unbounded"/>
            </xsd:choice>
        </xsd:sequence>

Does anyone knows what could be wrong here and what should I do to resolve this?

Thanks!

David


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users