Bug 492282 - EclipseLink Moxy Dynamic JAXB support for standard XSD restrictions
Summary: EclipseLink Moxy Dynamic JAXB support for standard XSD restrictions
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://stackoverflow.com/questions/36...
Whiteboard:
Keywords: consistency, core, helpwanted, triaged, usability
Depends on:
Blocks:
 
Reported: 2016-04-22 16:09 EDT by Ruslan Zenin CLA
Modified: 2022-06-09 10:34 EDT (History)
1 user (show)

See Also:


Attachments
MyXMLSchema.xsd (2.32 KB, text/plain)
2016-04-22 16:09 EDT, Ruslan Zenin CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ruslan Zenin CLA 2016-04-22 16:09:24 EDT
Created attachment 261184 [details]
MyXMLSchema.xsd

EnhanceEclipseLink Moxy Dynamic entity to work with XSD restrictions. I have created a sample XSD types that demonstrates the issue (see attached XSD).

As you can see from the attached XSD, I've constructed my type hierarchy in the following manner: Base XSD type "PersonName" getting used in RegularCustomer.Name and in SecretCustomer.Name. In case of RegularCustomer.Name I want to restrict usage to only First/Middle/Last name values and for SecretCustomer.Name I want to restrict usage to only "AliasName".

When I try using EclipseLink Moxy Dynamic JAXB implementation (e.g. no JAXB beans getting generated/compiled) I see the following issue, my code:

import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;

public class DynamicJAXBXMLProducer
{

  public static void main(String[] args) throws JAXBException
  {
    DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(
        DynamicJAXBXMLProducer.class.getClassLoader().getResourceAsStream("MyXMLSchema.xsd"), null, null, null);

    DynamicEntity sCust = jaxbContext.newDynamicEntity("jaxb.dynamic.SecretCustomer");

    // Lets report available property names for SecretCustomer.Name - expecting only "aliasName"
    DynamicType secretNameType = jaxbContext.getDynamicType("jaxb.dynamic.SecretCustomer.Name");
    System.out.println("SecretCustomer.Name property names: " + secretNameType.getPropertiesNames());

    // Lets report available property names for RegularCustomer.Name - expecting only "firstName, lastName, middleName"
    DynamicType regularNameType = jaxbContext.getDynamicType("jaxb.dynamic.RegularCustomer.Name");
    System.out.println("RegularCustomer.Name property names: " + regularNameType.getPropertiesNames());

    // Lets generate an invalid XML by adding forbidden firstName to SecretCustomer.Name
    DynamicEntity secretName = jaxbContext.newDynamicEntity("jaxb.dynamic.SecretCustomer.Name");
    secretName.set("aliasName", "AliasName");
    secretName.set("firstName", "fName"); // <-- This should throw an exception as "firstName" is not a valid property!!!
    sCust.set("name", secretName);

    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
    marshaller.marshal(sCust, System.out);
  }
}

The output will be:
===========================
SecretCustomer.Name property names: [firstName, lastName, middleName, aliasName]
RegularCustomer.Name property names: [firstName, lastName, middleName, aliasName]
<?xml version="1.0" encoding="UTF-8"?>
<Name>
   <FirstName>fName</FirstName>
   <AliasName>AliasName</AliasName>
</Name> 



BUT according to the XSD restriction for SecretCustomer.Name allowed property name is only "aliasName" and 
for RegularCustomer.Name only firstName, lastName, middleName

Can this be fixed in MOXy to generate a proper implementation (at least for dynamic entity) as per XSD schema restrictions?
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:34:14 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink