jaxb
  1. jaxb
  2. JAXB-270

fixed attribute value not used when using restriction inheritance

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.3
    • Fix Version/s: not determined
    • Component/s: xjc
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      270

      Description

      If a complex type with one attribute is inherited by restriction and in the
      inheriting element we define a fixed value for that attribute, the JAXB bean
      returns null for it except we set it explicitly.

      In my eyes this is a bug, as the JAXB bean should always return the fixed value.

      I've created some test files, but it seems like I can't upload them, so I just
      paste my files in here:

      ----------------------------------------------------------
      – XSD file ----------------------------------------------
      ----------------------------------------------------------

      <?xml version="1.0" encoding="UTF-8"?>
      <xsd:schema xmlns:core="http://paybox.net/xml/schema/core"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://paybox.net/xml/schema/core"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0">
      <xs:annotation>
      <xs:appinfo>
      <jxb:schemaBindings>
      <jxb:package name="net.paybox.mobiliser.jaxb" />
      </jxb:schemaBindings>
      </xs:appinfo>
      </xs:annotation>

      <xsd:simpleType name="IdentifierType">
      <xsd:restriction base="xsd:string">
      <xsd:enumeration value="id" />
      <xsd:enumeration value="imei" />
      <xsd:enumeration value="msisdn" />
      </xsd:restriction>
      </xsd:simpleType>

      <xsd:complexType name="Identifier">
      <xsd:simpleContent>
      <xsd:extension base="xsd:string">
      <xsd:attribute name="type" use="optional"
      type="core:IdentifierType" />
      </xsd:extension>
      </xsd:simpleContent>
      </xsd:complexType>

      <xsd:complexType name="IdIdentifier">
      <xsd:simpleContent>
      <xsd:restriction base="core:Identifier">
      <xsd:pattern value="\d

      {1,12}

      " />
      <xsd:attribute fixed="id" name="type"
      type="core:IdentifierType" />
      </xsd:restriction>
      </xsd:simpleContent>
      </xsd:complexType>

      <xsd:complexType name="BaseCustomer">
      <xsd:sequence>
      <xsd:element name="Identification" type="core:Identifier" />
      </xsd:sequence>
      </xsd:complexType>

      <xsd:complexType name="Merchant">
      <xsd:complexContent>
      <xsd:restriction base="core:BaseCustomer">
      <xsd:sequence>
      <xsd:element name="Identification"
      type="core:IdIdentifier">
      </xsd:element>
      </xsd:sequence>
      </xsd:restriction>
      </xsd:complexContent>
      </xsd:complexType>

      <xsd:element name="Root">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="Recipient" type="core:BaseCustomer" />
      <xsd:element name="Seller" type="core:Merchant" />
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>

      </xsd:schema>

      ----------------------------------------------------------
      – XML file ----------------------------------------------
      ----------------------------------------------------------
      <?xml version="1.0" encoding="UTF-8"?>
      <core:Root xmlns:core="http://paybox.net/xml/schema/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://paybox.net/xml/schema/core bugReport.xsd ">
      <Recipient>
      <Identification type="msisdn">+1781807531</Identification>
      </Recipient>
      <Seller>
      <Identification>123456789012</Identification>
      </Seller>
      </core:Root>

      ----------------------------------------------------------
      – JUnit -------------------------------------------------
      ----------------------------------------------------------
      import java.io.File;

      import javax.xml.bind.JAXBContext;
      import javax.xml.bind.JAXBException;
      import javax.xml.bind.Unmarshaller;
      import javax.xml.validation.SchemaFactory;

      import net.paybox.mobiliser.jaxb.Root;

      import org.junit.Assert;
      import org.junit.BeforeClass;
      import org.junit.Test;
      import org.xml.sax.SAXException;

      public class TestJaxb {

      private static Unmarshaller unMarshal;

      @BeforeClass
      public static void init() throws JAXBException, SAXException

      { unMarshal = JAXBContext.newInstance("net.paybox.mobiliser.jaxb") .createUnmarshaller(); unMarshal.setSchema(SchemaFactory.newInstance( "http://www.w3.org/2001/XMLSchema").newSchema( new File("bugReport.xsd"))); }

      @Test
      public void parse() throws JAXBException

      { Root root = (Root) unMarshal.unmarshal(new File("bugReport.xml")); Assert.assertNotNull(root.getRecipient().getIdentification().getType()); Assert.assertNotNull(root.getSeller().getIdentification().getType()); }

      }

        Activity

        Hide
        kohsuke added a comment -

        I believe the current behavior is in accordance with the spec.

        I agree with you that the behavior you are describing would make a lot of sense,
        and such behavior is certainly worth considering for vendor extensions. It's
        just that there are so many ways to restrict a content model, and have the
        compiler recognize those correctly would be a non-trivial work.

        Show
        kohsuke added a comment - I believe the current behavior is in accordance with the spec. I agree with you that the behavior you are describing would make a lot of sense, and such behavior is certainly worth considering for vendor extensions. It's just that there are so many ways to restrict a content model, and have the compiler recognize those correctly would be a non-trivial work.
        Hide
        kohsuke added a comment -

        Since this is not a "bug" in the sense of spec violation, I'm changing it to
        ENHANCEMENT.

        Show
        kohsuke added a comment - Since this is not a "bug" in the sense of spec violation, I'm changing it to ENHANCEMENT.

          People

          • Assignee:
            jaxb-issues
            Reporter:
            sebastiankirsch
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: