Re: Problem about generating Java Source Code with XMLBeans from xsd

Cezar Andrei <[email protected]> Tue, 5 Nov 2013 09:19:38 -0800 (PST)
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <[email protected]>
--Apple-Mail=_958A891E-F49E-4EEE-9C20-4C9151CCD927
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

Federico,

The schema looks fine, if you look closely at SubInfo type def:

<xs:complexType name=3D"SubInfo">
		<xs:complexContent>
			<xs:restriction base=3D"Info">
				<xs:sequence>
					<xs:element name=3D"Nome" =
type=3D"Testo70Custom"/>
				</xs:sequence>
			</xs:restriction>
		</xs:complexContent>
	</xs:complexType>
	<xs:complexType name=3D"Info">
		<xs:sequence>
			<xs:element name=3D"Nome" type=3D"Testo140" =
minOccurs=3D"0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:simpleType name=3D"Testo70Custom">
		<xs:restriction base=3D"Testo140">
			<xs:maxLength value=3D"70"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name=3D"Testo140">
		<xs:restriction base=3D"xs:string">
			<xs:minLength value=3D"1"/>
			<xs:maxLength value=3D"140"/>
		</xs:restriction>
	</xs:simpleType>

SubInfo is a restriction of type Info, i.e. it has to have a property =
called Nome of type Testo140.
But in the same type the element Nome inside the SubInfo sequence is =
declared of type Testo70Custom, which is fine because Testo70Custom is a =
subtype of Testo140.

This is a case where java rules and schema rules don't match fully. But =
if you're a little careful everything works fine,  make sure that you =
use SubInfo.xsetNome() only with objects of type Testo70Custom.

Cezar


On Nov 5, 2013, at 10:29 AM, Federico Rossetti =
<[email protected]> wrote:

> Hi all
>=20
>=20
>=20
> i have a starting xsd no editable, from which to generate the Java =
source code with XMLBeans. My problem is on the generated java class =
SubInfo.java.
>=20
>=20
>=20
> In the xsd, the element =93Nome=94, child of the element =93SubInfo=94, =
has as type =93Testo70Custom=94, but in the generated java code the type =
is =93Testo140=94. Is the xsd poorly written the problem? Or is the =
process of code generation the problem?
>=20
>=20
>=20
> The correct type is important because in my java code =96 client side =
=96 I use it to get some attributes of the xsd elements (like max length =
of string, to truncate strings in surplus) from the schemaytpe in order =
to perform the validation before sending out the message. If the type is =
wrong, I could send erroneous messages.
>=20
>=20
>=20
> In binary file .xsb generated with XmlBeans,  i see that in the =
properties of the element =93Nome=94 there is a difference between the =
Type (testo70custom8e3etype) and the Type for Java Signature =
(testo1405c59type).
>=20
>=20
>=20
> The three files are attached to the message.
>=20
>=20
>=20
> Thanks for a response
>=20
>=20
>=20
> Federico
>=20
> <SubInfo.java><subinfo0d05type.xsb><xsdtest.xsd>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]


--Apple-Mail=_958A891E-F49E-4EEE-9C20-4C9151CCD927
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
charset=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
"><div>Federico,</div><div><br></div><div>The schema looks fine, if you =
look closely at SubInfo type =
def:</div><div><br></div><div><div>&lt;xs:complexType =
name=3D"SubInfo"&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		=
</span>&lt;xs:complexContent&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">			=
</span>&lt;xs:restriction base=3D"Info"&gt;</div><div><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">				=
</span>&lt;xs:sequence&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">					=
</span>&lt;xs:element name=3D"Nome" =
type=3D"Testo70Custom"/&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">				=
</span>&lt;/xs:sequence&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">			=
</span>&lt;/xs:restriction&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		=
</span>&lt;/xs:complexContent&gt;</div><div><span class=3D"Apple-tab-span"=
 style=3D"white-space:pre">	=
</span>&lt;/xs:complexType&gt;</div></div><div><div><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">	=
</span>&lt;xs:complexType name=3D"Info"&gt;</div><div><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>&lt;xs:sequence&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">			</span>&lt;xs:element =
name=3D"Nome" type=3D"Testo140" minOccurs=3D"0"/&gt;</div><div><span =
class=3D"Apple-tab-span" style=3D"white-space:pre">		=
</span>&lt;/xs:sequence&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</span>&lt;/xs:complexType&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>&lt;xs:simpleType =
name=3D"Testo70Custom"&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span>&lt;xs:restriction =
base=3D"Testo140"&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">			</span>&lt;xs:maxLength =
value=3D"70"/&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		=
</span>&lt;/xs:restriction&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</span>&lt;/xs:simpleType&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	</span>&lt;xs:simpleType =
name=3D"Testo140"&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		</span>&lt;xs:restriction =
base=3D"xs:string"&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">			</span>&lt;xs:minLength =
value=3D"1"/&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">			</span>&lt;xs:maxLength =
value=3D"140"/&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">		=
</span>&lt;/xs:restriction&gt;</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">	=
</span>&lt;/xs:simpleType&gt;</div></div><div><br></div><div>SubInfo is =
a restriction of type Info, i.e. it has to have a property called Nome =
of type Testo140.</div><div>But in the same type the element Nome inside =
the SubInfo sequence is declared of type Testo70Custom, which is fine =
because Testo70Custom is a subtype of =
Testo140.</div><div><br></div><div>This is a case where java rules and =
schema rules don't match fully. But if you're a little careful =
everything works fine, &nbsp;make sure that you use SubInfo.xsetNome() =
only with objects of type =
Testo70Custom.</div><div><br></div><div>Cezar</div><div><br></div><br><div=
><div>On Nov 5, 2013, at 10:29 AM, Federico Rossetti &lt;<a =
href=3D"mailto:[email protected]">federico.rossetti.86@gmail.=
com</a>&gt; wrote:</div><br =
class=3D"Apple-interchange-newline"><blockquote type=3D"cite"><div =
dir=3D"ltr"><p class=3D"MsoNormal"><span lang=3D"EN-US">Hi =
all</span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US"><br></span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US">i have a
starting xsd no editable, from which to generate the Java source code =
with
XMLBeans. My problem is on the generated java class =
SubInfo.java.</span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US"><br></span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US">In the xsd,
the element =93Nome=94, child of the element =93SubInfo=94, has as type
=93Testo70Custom=94, but in the generated java code the type is =
=93Testo140=94. Is the
xsd poorly written the problem? Or is the process of code generation the
problem? </span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US"><br></span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US">The correct
type is important because in my java code =96 client
side =96 I use it to get some attributes
of the xsd elements (like
max length of string, to truncate strings in surplus) from
the schemaytpe in order to perform the validation before sending out the
message. If the type is wrong, I could send erroneous =
messages.</span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US"><br></span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US">In binary
file .xsb generated with XmlBeans,&nbsp; i see that in the properties of =
the
element =93Nome=94 there is a difference between
the Type (testo70custom8e3etype) and the Type for Java Signature
(testo1405c59type).</span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US"><br></span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US">The three
files are attached to the message.</span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US"><br></span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US">Thanks for
a response</span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US"><br></span></p><p class=3D"MsoNormal"><span =
lang=3D"EN-US">Federico</span></p></div>
=
<span>&lt;SubInfo.java&gt;</span><span>&lt;subinfo0d05type.xsb&gt;</span><=
span>&lt;xsdtest.xsd&gt;</span><br>---------------------------------------=
------------------------------<br>To unsubscribe, e-mail: <a =
href=3D"mailto:[email protected]">user-unsubscribe@xmlb=
eans.apache.org</a><br>For additional commands, e-mail: <a =
href=3D"mailto:[email protected]">[email protected]=
g</a></blockquote></div><br></body></html>=

--Apple-Mail=_958A891E-F49E-4EEE-9C20-4C9151CCD927--