Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB Compiling Issue - [ERROR] Property "Any" is already defined

I am trying to create JAXB binding for xccdf-1.1.4.xsd which is a standard schema that can be obtain from XCCDF Schema Location

I am currently using EclipseLink MOXy as my JAXB implementation since I like the fact that it can also generate JSON bindings as well.

I fixed couple of occasion 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 <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? Thanks!

like image 927
beyonddc Avatar asked Nov 28 '12 16:11

beyonddc


3 Answers

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;
    }

}
like image 97
bdoughan Avatar answered Nov 17 '22 08:11

bdoughan


Using Blaise's suggestion to create a JAXB external binding XML would work when using the JAVA JAXB implementation to generate the JAXB binding.

However it doesn't work when using EclipseLink MOXy jaxb-compiler.sh. Blaise said that it could be a possible bug in the compiler script. bug ticket 395328

The workaround to this problem for now is to use the JAVA XJC command from the JDK and manually add the jaxb.properties file in the generated directory. Specifying-eclipselink-moxy-as-yours

like image 35
beyonddc Avatar answered Nov 17 '22 08:11

beyonddc


I tried all these solutions when I was using Eclipse and they really did not help me. SO I switched to Netbeans, which really gave me the same error with just a dialog box displaying more or less the same error message but with lesser detail.

Here is the sweet part, Netbeans does create the client service! Yes, with that error message.

You can just create your web service client as follows:
1. Right click on the project,
2. New
3. Web Service Client
4. Select the WSDL URL and paste the URL
5. Click finish and then it creates the client with errors.

So I located the generated WSDL file in my project, searched for occurrences of "any" in the file and commented every second occurrences in the file in the same tag.

commented line number 216

Save the file after commenting for all the second occurrences in the same tag. Right Click on the Web Service (first expand Web Services References), click Refresh. And your Web Service Client will be good to be run, just dragging and dropping methods and calling them with the your parameters!

That worked for me...

like image 29
Farai Mugaviri Avatar answered Nov 17 '22 09:11

Farai Mugaviri