You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by "Mark R. Diggory" <md...@apache.org> on 2004/09/08 22:50:36 UTC

Accessing parent elements.

Is there any way I can get JaxMe to generate objects that maintain a 
reference to their parent in the element hierarchy?

-Mark

-- 
Mark Diggory
Open Source Software Developer
Apache Jakarta Project
http://jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Re: Accessing parent elements.

Posted by Jochen Wiedmann <jo...@freenet.de>.
Mark R. Diggory wrote:

> I also see that when I use the "extends" element of w3c schema, it would 
> be good to have the generated interface also "extend" the indicated 
> interface. For instance:

It is not only "would be good": It is a bug. The JAXB specification 
clearly requires, that xs:extension should be mapped to an extension of 
classes. (There is no bug report in Jira for that yet, but it's 
definitely worth.)

The problem is, that the issue requires a number of subtle changes. In 
particular, the extended classes have to be changed, attributes have to 
be checked, whether they are present in the super class or not, and 
likewise for elements. Possibly the marshaller and unmarshaller code can 
be left as it is (noone actually cares, whether the unmarshaller is 
internally using a super class), but for obvious reasons, it would be
better.


> This would allow extensibility and polymorphism available in the schema 
> to propagate into the objects that were generated. Any recommendations 
> on how to approach this?

As I said, the issue is complex. IMO the best approach would be, to 
split the task into several subtasks (for example, start with the 
extension, then the attributes, and so on). It is easier to discuss the 
various minor issues. But, believe me, it's a lot of work! (However, for 
that very reason, you'd do something very valuable!)


Jochen

-- 
http://lilypie.com/baby1/050423/1/5/1/+1

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Re: Accessing parent elements.

Posted by "Mark R. Diggory" <md...@apache.org>.
Thanks for the response, I see this will take some additions to and 
rebuilding of the package. this is ok, I believe I can handle it and 
make some contributions back to the project.

I also see that when I use the "extends" element of w3c schema, it would 
be good to have the generated interface also "extend" the indicated 
interface. For instance:

>     <xs:complexType name="topicType">
>         <xs:complexContent>
>             <xs:extension base="tocType">
>                 <xs:sequence>
>                     <xs:element name="content" type="contentType" minOccurs="0"/>
>                 </xs:sequence>
>             </xs:extension>
>         </xs:complexContent>
>     </xs:complexType>
>     <xs:complexType name="tocType">
>         <xs:attribute name="type" type="xs:string" use="required"/>
>         <xs:attribute name="href" type="xs:anyURI" use="required"/>
>     </xs:complexType>

could resulting a Interface hierarchy that looks like

public interface TopicType extends TocType {
	...
}

public interface TocType {
	...
}

This would allow extensibility and polymorphism available in the schema 
to propagate into the objects that were generated. Any recommendations 
on how to approach this?

-Mark

Jochen Wiedmann wrote:

> Mark R. Diggory wrote:
> 
>> Is there any way I can get JaxMe to generate objects that maintain a 
>> reference to their parent in the element hierarchy?
> 
> 
> This could be done relatively easy in the following way:
> 
> - Specify a property (for example "generator.parent.references")
>   and set it; see the nested element "property" in
>     http://ws.apache.org/jaxme/manual/ch02.html
> - In JAXBComplexTypeSGChain.generateXMLImplementationMethods:
>   Check whether the property is set. If so, add an instance of
>   JavaField to the class pSource, roughly like this:
>     pSource.newJavaField("parent", JMElement.class, "public");
> - In JAXBTypeSG.getXMLSetMethod: Check, whether the child
>   element is complex. Check, whether the property is set.
>   If so, change its "parent" field.
> 
> I am leaving out details, in particular, I am ignoring the question of 
> maxOccurs > 1. However, I'd be willing to integrate a patch, if you 
> create one.
> 
> 
> Jochen
> 
> 

-- 
Mark Diggory
Open Source Software Developer
Apache Jakarta Project
http://jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Re: Accessing parent elements.

Posted by Jochen Wiedmann <jo...@freenet.de>.
Mark R. Diggory wrote:

> Is there any way I can get JaxMe to generate objects that maintain a 
> reference to their parent in the element hierarchy?

This could be done relatively easy in the following way:

- Specify a property (for example "generator.parent.references")
   and set it; see the nested element "property" in
     http://ws.apache.org/jaxme/manual/ch02.html
- In JAXBComplexTypeSGChain.generateXMLImplementationMethods:
   Check whether the property is set. If so, add an instance of
   JavaField to the class pSource, roughly like this:
     pSource.newJavaField("parent", JMElement.class, "public");
- In JAXBTypeSG.getXMLSetMethod: Check, whether the child
   element is complex. Check, whether the property is set.
   If so, change its "parent" field.

I am leaving out details, in particular, I am ignoring the question of 
maxOccurs > 1. However, I'd be willing to integrate a patch, if you 
create one.


Jochen


-- 
http://lilypie.com/baby1/050423/1/5/1/+1

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org