Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/DesignDocs/322284"

(Solution)
(Open Issues)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<div style="border: 1px solid rgb(0, 0, 0); margin: 5px; padding: 5px; float: right;">__TOC__</div>  
 
<div style="border: 1px solid rgb(0, 0, 0); margin: 5px; padding: 5px; float: right;">__TOC__</div>  
= Dynamic JAXB: Support For Specifying The Collection Type Via XML metadata =
+
= Dynamic JAXB: Support For Specifying The Container Type Via XML metadata =
This design page will capture design and decisions involving adding support for specifying a collection class via XML metadata.  This support is required by Dynamic JAXB.
+
This design page will capture design and decisions involving adding support for specifying a container class via XML metadata.  This support is required by Dynamic JAXB.
  
 
== Problem ==
 
== Problem ==
For Dynamic JAXB, there must be a way of specifying the class of the collection being used, such that the underlying dynamic JavaModel can be built correctly.  We currently support setting the type via <code>type</code> attribute (based on the corresponding JAXB annotation) as follows:
+
For Dynamic JAXB, there must be a way of specifying the class of the container being used, such that the underlying dynamic JavaModel can be built correctly.  We currently support setting the type via <code>type</code> attribute (based on the corresponding JAXB annotation) as follows:
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0" encoding="US-ASCII"?>
 
<?xml version="1.0" encoding="US-ASCII"?>
Line 34: Line 34:
  
 
== Solution ==
 
== Solution ==
We will add an attribute named <code>collection-type</code> to the following:
+
We will add an attribute named <code>container-type</code> that will allow users to declare the type of the container:
 +
<source lang="xml">
 +
<xs:attribute name="container-type" type="xs:string" default="##default" />
 +
</source>
 +
 
 +
The new attribute will be added to the following:
 
* xml-attribute
 
* xml-attribute
 +
* xml-any-attribute
 
* xml-any-element
 
* xml-any-element
 
* xml-element
 
* xml-element
 
* xml-elements
 
* xml-elements
This attribute will allow users to declare the type of the collection.
+
* xml-value
  
 
== Example ==
 
== Example ==
Here is an example of how the collection type can be configured via XML metadata:<br>
+
Here is an example of how the container type can be configured via XML metadata:<br>
  
 
org/example/eclipselink-oxm.xml
 
org/example/eclipselink-oxm.xml
Line 53: Line 59:
 
         <xml-attribute java-attribute="id" type="java.lang.String" />
 
         <xml-attribute java-attribute="id" type="java.lang.String" />
 
         <xml-element java-attribute="name" type="java.lang.String" />
 
         <xml-element java-attribute="name" type="java.lang.String" />
         <xml-element java-attribute="phoneNumbers" type="org.example.PhoneNumber" collection-type="java.util.ArrayList" />
+
         <xml-element java-attribute="phoneNumbers" type="org.example.PhoneNumber" container-type="java.util.ArrayList" />
 
       </java-attributes>
 
       </java-attributes>
 
     </java-type>
 
     </java-type>
Line 96: Line 102:
 
! Owner  
 
! Owner  
 
! Description / Notes
 
! Description / Notes
|-
+
|-  
| 3
+
|
+
| How will arrays be handled?  JPA does the following:  <code>attribute-type="java.lang.Integer[]"</code>.  Can we do the same thing, i.e. <code>collection-type="java.lang.Integer[]"</code>?
+
 
|}
 
|}
  
Line 114: Line 117:
 
| 1
 
| 1
 
| For MOXy, the the property type is set via <code>type</code> attribute.  Adding an attribute named <code>attribute-type</code> to support setting the container class would be confusing for users.  Should a different name be used, and if so, what should it be named?
 
| For MOXy, the the property type is set via <code>type</code> attribute.  Adding an attribute named <code>attribute-type</code> to support setting the container class would be confusing for users.  Should a different name be used, and if so, what should it be named?
| We will add an attribute named <code>collection-type</code>
+
| We will add an attribute named <code>container-type</code>
 
|-
 
|-
 
| 2
 
| 2
 
| Should the container type be limited to interfaces (Map, List, Set) via enumeration?
 
| Should the container type be limited to interfaces (Map, List, Set) via enumeration?
 
| No.
 
| No.
 +
|-
 +
| 3
 +
| How will arrays be handled?  JPA does the following:  <code>attribute-type="java.lang.Integer[]"</code>.  Can we do the same thing, i.e. <code>container-type="java.lang.Integer[]"</code> or <code>type="java.lang.Integer[]"</code>?
 +
| We will not add support for array types at this time.  An enhancement request has been opened to track this issue (https://bugs.eclipse.org/bugs/show_bug.cgi?id=326548).
 
|}
 
|}

Latest revision as of 12:43, 29 September 2010

Dynamic JAXB: Support For Specifying The Container Type Via XML metadata

This design page will capture design and decisions involving adding support for specifying a container class via XML metadata. This support is required by Dynamic JAXB.

Problem

For Dynamic JAXB, there must be a way of specifying the class of the container being used, such that the underlying dynamic JavaModel can be built correctly. We currently support setting the type via type attribute (based on the corresponding JAXB annotation) as follows:

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
    <java-types>
        <java-type name="org.example.Employee">
            <java-attributes>
                <xml-element java-attribute="zipCodes" type="java.lang.Integer"/>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

This level of support will NOT allow us to configure, for example, the following dynamically:

package org.example;
 
public class Employee {
    java.util.List<Integer> zipCodes;
}

JPA Metadata

Dynamic JPA allows setting the container class via attribute-type attribute, and the property type via target-entity, as follows:

<one-to-many name="phoneNumbers" mapped-by="owner" target-entity="PhoneNumber" attribute-type="java.util.List" />

Solution

We will add an attribute named container-type that will allow users to declare the type of the container:

<xs:attribute name="container-type" type="xs:string" default="##default" />

The new attribute will be added to the following:

  • xml-attribute
  • xml-any-attribute
  • xml-any-element
  • xml-element
  • xml-elements
  • xml-value

Example

Here is an example of how the container type can be configured via XML metadata:

org/example/eclipselink-oxm.xml

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm">
  <java-types>
    <java-type name="org.example.Employee">
      <java-attributes>
        <xml-attribute java-attribute="id" type="java.lang.String" />
        <xml-element java-attribute="name" type="java.lang.String" />
        <xml-element java-attribute="phoneNumbers" type="org.example.PhoneNumber" container-type="java.util.ArrayList" />
      </java-attributes>
    </java-type>
    <java-type name="org.example.PhoneNumber">
      <java-attributes>
        <xml-attribute java-attribute="id" type="java.lang.String" />
        <xml-attribute java-attribute="number" type="java.lang.String" />
      </java-attributes>
    </java-type>
  </java-types>
</xml-bindings>

The generated classes would look like: org.example.Employee.java

package org.example;
 
public class Employee {
    public String id;
    public String name;
    public java.util.ArrayList<PhoneNumber> phoneNumbers
}

org.example.PhoneNumber.java

package org.example;
 
public class PhoneNumber {
    public String id;
    public String number;
}

Open Issues

This section lists the open issues that are still pending that must be decided prior to fully implementing this project's requirements.

Issue # Owner Description / Notes

Decisions

This section lists decisions made. These are intended to document the resolution of open issues or constraints added to the project that are important.

Issue # Description / Notes Decision
1 For MOXy, the the property type is set via type attribute. Adding an attribute named attribute-type to support setting the container class would be confusing for users. Should a different name be used, and if so, what should it be named? We will add an attribute named container-type
2 Should the container type be limited to interfaces (Map, List, Set) via enumeration? No.
3 How will arrays be handled? JPA does the following: attribute-type="java.lang.Integer[]". Can we do the same thing, i.e. container-type="java.lang.Integer[]" or type="java.lang.Integer[]"? We will not add support for array types at this time. An enhancement request has been opened to track this issue (https://bugs.eclipse.org/bugs/show_bug.cgi?id=326548).

Back to the top