xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Darius K." <suirad98-j...@yahoo.com>
Subject substitutionGroups not supported?
Date Wed, 28 Jul 2004 03:49:18 GMT
Reply to Radu Preotiuc-Pietro:

Thanks Radu. Appreciate your suggestions. 

It seems that changing the method name would not work
for me as this would invalidate the whole idea behind
the polymorphism of having a base schema that is
extended using a more specific schema where this
polymorphism gets preserved in generated java classes.


Wouldn't a better solution be to not change the return
element type?  That would work for the complex types.
It would also work for the simple types, but it would
require additional change not to use java.lang.String
but org.apache.xmlbeans.XmlString for
type="xs:string".  Obviously caller would need to cast
to an appropriate type, but that is better in my
opinion than changing the method name.  Also in the
future it might be possible to implement this with JDK
1.5 generics so that typecasting is not necessary. 

For now I guess I will use type extensions instead of
substitutionGroups - that does seem to work fine. 

Thanks again!

-Darius


Reply to:
----------------------
Subject: substitutionGroups not supported?
Content-Type: text/plain;
	charset="iso-8859-1"
Date: Tue, 27 Jul 2004 16:17:35 -0700
From: Radu Preotiuc-Pietro <radup@bea.com>

I actually contributed a patch to fix this problem,
but it was only commited in V2.
Because of the problem you mentioned when using String
(since String is final in Java, cannot be subclassed,
which is why XmlString is used) I thought the right
way to solve this was by changing the generated code
so that method names do not collide.
The V2 code does it automatically, in V1 you will have
to change the method name "by hand" (or maybe submit a
bug in JIRA mentioning this situation)

Radu

-----Original Message-----
From: Darius K. [mailto:suirad98-j2ee@yahoo.com]
Sent: Tuesday, July 27, 2004 2:20 PM
To: xmlbeans-user@xml.apache.org
Subject: substitutionGroups not supported?


Hi, I am having troubles with substitutionGroups. Here
are the excerpts from my schemas:

1. BaseSchema:
<xs:element name="RequestEnvelope">
  <xs:complexType>
    <xs:sequence minOccurs="0">
      <xs:element ref="Body"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
<xs:element name="Body" abstract="true"/>

2. SpecificSchema:
<xs:element name="Body"
substitutionGroup="baseRequest:Body">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="ID">
        <xs:simpleType>
	   <xs:restriction base="xs:string">
	     <xs:maxLength value="150"/>
	   </xs:restriction>
	</xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

scomp works well, but the generated java classes do
not compile. Specifically:
1. Base schema generates interface:

public interface BodyDocument extends
org.apache.xmlbeans.XmlObject {
...
  org.apache.xmlbeans.XmlObject getBody();
...

2. But a more specific schema generates following
interface:
public interface BodyDocument extends
mypackage.baseRequest.BodyDocument {
...
mypackage.specificRequest.BodyDocument.Body getBody();
..

Since mypackage.specificRequest.getBody() returns a
different type than mypackage.baseRequest.getBody(),
the src code does not compile.

I can fix this by hand in the java src code by making 
mypackage.specificRequest.getBody() to return
org.apache.xmlbeans.XmlObject.

But this gets even worse if the base element is of
type="xs:string" which gets translated into
java.lang.String and the more specific element is
<xs:restriction base="xs:string"><xs:enumeration ..>
In that case I can not trick mypackage.specificRequest
method to return String as enumeration translates into
the subclass of a org.apache.xmlbeans.XmlString - not
a subclass of java.lang.String.

Any ideas how to work with substitutionGroup(s) for
the global elements in a more specific schemas that
are derived from some generic schema?

Thanks

-Darius

 


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message