Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XSD to Java code generation with multiple import of the same namespace
XSD to Java code generation with multiple import of the same namespace [message #425606] Wed, 03 December 2008 12:01 Go to next message
Blazej Kroll is currently offline Blazej KrollFriend
Messages: 10
Registered: July 2009
Junior Member
I'd encountered a problem with generating Java code by EMF XSD generation
functionality within Eclipse 3.2.2. Within the *.xsd file a multiple
import of the same namespace was used, see egzample:

<!-- Imports -->
<xsd:import schemaLocation="Part1.xsd"
namespace="http://TestLibB"></xsd:import>

<xsd:import schemaLocation="Part2.xsd"
namespace="http://TestLibB"></xsd:import>

I'd like to ask if the XSD to Java code generation functionality in
Eclipse 3.4 respecting multiple import of the same namespace in a XSD file
and generates valid Java code?

The W3C Specification says it is up to a XML Schema application
(EMF XSD to Java transformation) to ignore multiple
imports of the same namespace or not.
-----
http://www.w3.org/TR/xmlschema-1
4.2.3 References to schema components across namespaces
.....
Note: ... Given that the schemaLocation attribute is only a hint,
it is open to applications to ignore all but the first <import> for
a given namespace, regardless of the actual value of schemaLocation,
but such a strategy risks missing useful information when new
schemaLocations are offered.
-----

Regards,
Blazej
Re: XSD to Java code generation with multiple import of the same namespace [message #425607 is a reply to message #425606] Wed, 03 December 2008 12:19 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Blazej,

Comments below.

Blazej Kroll wrote:
> I'd encountered a problem with generating Java code by EMF XSD
> generation functionality within Eclipse 3.2.2.
That's pretty old. Can you reproduce it with EMF 2.4?
> Within the *.xsd file a multiple import of the same namespace was
> used, see egzample:
>
> <!-- Imports -->
> <xsd:import schemaLocation="Part1.xsd"
> namespace="http://TestLibB"></xsd:import>
>
> <xsd:import schemaLocation="Part2.xsd"
> namespace="http://TestLibB"></xsd:import>
>
> I'd like to ask if the XSD to Java code generation functionality in
> Eclipse 3.4 respecting multiple import of the same namespace in a XSD
> file and generates valid Java code?
When resolving a name in that namespace it should visit all the imports
and will try to resolve each one.
>
> The W3C Specification says it is up to a XML Schema
> application (EMF XSD to Java transformation) to ignore
> multiple imports of the same namespace or
> not.
> -----
> http://www.w3.org/TR/xmlschema-1
> 4.2.3 References to schema components across
> namespaces
> ....
> Note: ... Given that the schemaLocation attribute is only a hint,
> it is open to applications to ignore all but the first <import>
> for a given namespace, regardless of the actual value of
> schemaLocation, but such a strategy risks missing useful
> information when new schemaLocations are
> offered. -----
The XSD model itself has always strictly followed the hints given by all
the schema locations, but the resolution mechanism is extensible and
things like WTP support an XML catalog than can be used to take
precedence over the hints within the schema (to support things like
redirecting a HTTP URL to a local cached version of that schema).
>
> Regards, Blazej
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XSD to Java code generation with multiple import of the same namespace [message #425616 is a reply to message #425607] Wed, 03 December 2008 13:01 Go to previous messageGo to next message
Blazej Kroll is currently offline Blazej KrollFriend
Messages: 10
Registered: July 2009
Junior Member
Hello!
Just to add some more to my concern:

I checked it with EMF 2.4 and it turned out that when I use this scenario
and want to generate Java:
1. if I use Xerces validator and the
<!-- Imports -->
<xsd:import schemaLocation="Part1.xsd">>
namespace="http://TestLibB"></xsd:import>
<xsd:import schemaLocation="Part2.xsd">>
namespace="http://TestLibB"></xsd:import>

it gives an error when I want to use an element from Part2.xsd reading
that it can not be defined.

2. using the same Validator and changing this declaration to:
some Intermediate.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://TestLib/B">
<xsd:include schemaLocation="Part1.xsd"></xsd:include>
<xsd:include schemaLocation="Part2.xsd"></xsd:include>
</xsd:schema>

and then imported single:
<xsd:import namespace="http://TestLib/B"
schemaLocation="Intermediate.xsd"></xsd:import>
results in no error indication.

Then generating Java files from these two results in almost the same
source.
The only difference is one generated java class file which includes class
file import statement below.
-> import org.eclipse.emf.ecore.xml.type.XMLTypePackage
But it is not included in the file generated at second step.

Does it shows that the multiple import statement does not work correctly?
How to check if the generated source code valid?

Thank you Ed for replying in just minutes after me posting!

Regards,
Blazej


> Blazej Kroll wrote:
>> I'd encountered a problem with generating Java code by EMF XSD
>> generation functionality within Eclipse 3.2.2.

> That's pretty old. Can you reproduce it with EMF 2.4?

>> Within the *.xsd file a multiple import of the same namespace was
>> used, see egzample:
>>
>> <!-- Imports -->
>> <xsd:import schemaLocation="Part1.xsd"
>> namespace="http://TestLibB"></xsd:import>
>>
>> <xsd:import schemaLocation="Part2.xsd"
>> namespace="http://TestLibB"></xsd:import>
>>
>> I'd like to ask if the XSD to Java code generation functionality in
>> Eclipse 3.4 respecting multiple import of the same namespace in a XSD
>> file and generates valid Java code?

> When resolving a name in that namespace it should visit all the imports
> and will try to resolve each one.

>>
>> The W3C Specification says it is up to a XML Schema
>> application (EMF XSD to Java transformation) to ignore
>> multiple imports of the same namespace or
>> not.
>> -----
>> http://www.w3.org/TR/xmlschema-1
>> 4.2.3 References to schema components across
>> namespaces
>> ....
>> Note: ... Given that the schemaLocation attribute is only a hint,
>> it is open to applications to ignore all but the first <import>
>> for a given namespace, regardless of the actual value of
>> schemaLocation, but such a strategy risks missing useful
>> information when new schemaLocations are
>> offered. -----

> The XSD model itself has always strictly followed the hints given by all
> the schema locations, but the resolution mechanism is extensible and
> things like WTP support an XML catalog than can be used to take
> precedence over the hints within the schema (to support things like
> redirecting a HTTP URL to a local cached version of that schema).

>>
>> Regards, Blazej
>>
Re: XSD to Java code generation with multiple import of the same namespace [message #425626 is a reply to message #425616] Wed, 03 December 2008 14:04 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Blazej,

Comments below.


Blazej Kroll wrote:
> Hello!
> Just to add some more to my concern:
>
> I checked it with EMF 2.4 and it turned out that when I use this
> scenario and want to generate Java:
> 1. if I use Xerces validator and the <!-- Imports -->
> <xsd:import schemaLocation="Part1.xsd">>
> namespace="http://TestLibB"></xsd:import>
> <xsd:import schemaLocation="Part2.xsd">>
> namespace="http://TestLibB"></xsd:import>
>
> it gives an error when I want to use an element from Part2.xsd reading
> that it can not be defined.
>
> 2. using the same Validator and changing this declaration to:
> some Intermediate.xsd
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://TestLib/B">
> <xsd:include schemaLocation="Part1.xsd"></xsd:include>
> <xsd:include schemaLocation="Part2.xsd"></xsd:include>
> </xsd:schema>
>
> and then imported single:
> <xsd:import namespace="http://TestLib/B"
> schemaLocation="Intermediate.xsd"></xsd:import>
> results in no error indication.
>
> Then generating Java files from these two results in almost the same
> source.
> The only difference is one generated java class file which includes
> class file import statement below. -> import
> org.eclipse.emf.ecore.xml.type.XMLTypePackage But it
> is not included in the file generated at second step.
> Does it shows that the multiple import statement does not work correctly?
It's a little too vague for me to understand what you're driving at.
> How to check if the generated source code valid?
Does it compile? :-P Can it read and write valid instances? What kinds
of things are defined in these other two schemas? Is an EPackage with
nsURI http://TestLibB produced? Does it contain EClassifiers for all
the types defined in that namespace? Does the document root of that
package have features for all the elements and attributes defined in
that namespace (from both files)?
>
> Thank you Ed for replying in just minutes after me posting!
>
> Regards,
> Blazej
>
>> Blazej Kroll wrote:
>>> I'd encountered a problem with generating Java code by EMF XSD
>>> generation functionality within Eclipse 3.2.2.
>
>> That's pretty old. Can you reproduce it with EMF 2.4?
>
>>> Within the *.xsd file a multiple import of the same namespace was
>>> used, see egzample:
>>>
>>> <!-- Imports -->
>>> <xsd:import schemaLocation="Part1.xsd"
>>> namespace="http://TestLibB"></xsd:import>
>>>
>>> <xsd:import schemaLocation="Part2.xsd"
>>> namespace="http://TestLibB"></xsd:import>
>>>
>>> I'd like to ask if the XSD to Java code generation functionality in
>>> Eclipse 3.4 respecting multiple import of the same namespace in a
>>> XSD file and generates valid Java code?
>
>> When resolving a name in that namespace it should visit all the
>> imports and will try to resolve each one.
>
>>>
>>> The W3C Specification says it is up to a XML Schema
>>> application (EMF XSD to Java transformation) to ignore
>>> multiple imports of the same namespace or
>>> not.
>>> -----
>>> http://www.w3.org/TR/xmlschema-1
>>> 4.2.3 References to schema components across
>>> namespaces
>>> ....
>>> Note: ... Given that the schemaLocation attribute is only a
>>> hint, it is open to applications to ignore all but the first
>>> <import> for a given namespace, regardless of the actual value
>>> of schemaLocation, but such a strategy risks missing useful
>>> information when new schemaLocations are
>>> offered. -----
>
>> The XSD model itself has always strictly followed the hints given by
>> all the schema locations, but the resolution mechanism is extensible
>> and things like WTP support an XML catalog than can be used to take
>> precedence over the hints within the schema (to support things like
>> redirecting a HTTP URL to a local cached version of that schema).
>
>>> Regards, Blazej
>>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XSD to Java code generation with multiple import of the same namespace [message #425708 is a reply to message #425626] Fri, 05 December 2008 11:26 Go to previous messageGo to next message
Blazej Kroll is currently offline Blazej KrollFriend
Messages: 10
Registered: July 2009
Junior Member
Hello,
to clarify the issue I'm facing:

I want to generate Java from XML Schema.
I am facing a validation error from Xerces when using multiple imports in
an xml schema file like:

<xsd:import schemaLocation="Part1.xsd"
namespace="http://TestLibB"></xsd:import>
<xsd:import schemaLocation="Part2.xsd"
namespace="http://TestLibB"></xsd:import>

After looking for a workaround I tried to make it another way (not to see
the validator's error)
and make a fsingle file which includes the necessary Part1.xsd and
Part2.xsd files and then import that file in the main Schema from which I
will generate the Java code.

Some file which gatheres all the necessery ones called Intermediate.xsd
which includes:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://TestLib/B">
<xsd:include schemaLocation="Part1.xsd"></xsd:include>
<xsd:include schemaLocation="Part2.xsd"></xsd:include>
</xsd:schema>

and then in the main file to generate Java code I use single import
operation:
<xsd:import namespace="http://TestLib/B"
schemaLocation="Intermediate.xsd"></xsd:import>

So the validator is giving no errors.

Just to summer things up I want to make sure that from the EMF side both
these scenarioes (multiple import usage) generate a valid Java code
despite the validator's error in the first case.

Regards,
Blazej
Re: XSD to Java code generation with multiple import of the same namespace [message #425710 is a reply to message #425708] Fri, 05 December 2008 11:43 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Blazej,

Comments below.


Blazej Kroll wrote:
> Hello, to clarify the issue I'm facing:
>
> I want to generate Java from XML Schema.
> I am facing a validation error from Xerces when using multiple imports
> in an xml schema file like:
> <xsd:import schemaLocation="Part1.xsd"
> namespace="http://TestLibB"></xsd:import>
> <xsd:import schemaLocation="Part2.xsd"
> namespace="http://TestLibB"></xsd:import>
It seems to me they ought to support that.
>
> After looking for a workaround I tried to make it another way (not to
> see the validator's error)
> and make a fsingle file which includes the necessary Part1.xsd and
> Part2.xsd files and then import that file in the main Schema from
> which I will generate the Java code.
>
> Some file which gatheres all the necessery ones called
> Intermediate.xsd which includes:
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://TestLib/B">
> <xsd:include schemaLocation="Part1.xsd"></xsd:include>
> <xsd:include schemaLocation="Part2.xsd"></xsd:include>
> </xsd:schema>
>
> and then in the main file to generate Java code I use single import
> operation:
> <xsd:import namespace="http://TestLib/B"
> schemaLocation="Intermediate.xsd"></xsd:import>
>
> So the validator is giving no errors.
Yes, that should work.
> Just to summer things up I want to make sure that from the EMF side
> both these scenarioes (multiple import usage) generate a valid Java
> code despite the validator's error in the first case.
Yes, EMF should treat them as entirely equivalent and should generate
the same code for each.
>
> Regards,
> Blazej
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XSD to Java code generation with multiple import of the same namespace [message #425725 is a reply to message #425710] Fri, 05 December 2008 15:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: blazej.kroll.gmail.com

Hello,

Thank you for the answer Ed.

Just to close the subject. Can I expect the multiple import to work in
EMF 2.2 or 2.3? Or is it a new introduced thing?

Regards,
Blazej


Ed Merks pisze:
> Blazej,
>
> Comments below.
>
>
> Blazej Kroll wrote:
>> Hello, to clarify the issue I'm facing:
>>
>> I want to generate Java from XML Schema.
>> I am facing a validation error from Xerces when using multiple imports
>> in an xml schema file like:
>> <xsd:import schemaLocation="Part1.xsd"
>> namespace="http://TestLibB"></xsd:import>
>> <xsd:import schemaLocation="Part2.xsd"
>> namespace="http://TestLibB"></xsd:import>
> It seems to me they ought to support that.
>>
>> After looking for a workaround I tried to make it another way (not to
>> see the validator's error)
>> and make a fsingle file which includes the necessary Part1.xsd and
>> Part2.xsd files and then import that file in the main Schema from
>> which I will generate the Java code.
>>
>> Some file which gatheres all the necessery ones called
>> Intermediate.xsd which includes:
>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>> targetNamespace="http://TestLib/B">
>> <xsd:include schemaLocation="Part1.xsd"></xsd:include>
>> <xsd:include schemaLocation="Part2.xsd"></xsd:include>
>> </xsd:schema>
>>
>> and then in the main file to generate Java code I use single import
>> operation:
>> <xsd:import namespace="http://TestLib/B"
>> schemaLocation="Intermediate.xsd"></xsd:import>
>>
>> So the validator is giving no errors.
> Yes, that should work.
>> Just to summer things up I want to make sure that from the EMF side
>> both these scenarioes (multiple import usage) generate a valid Java
>> code despite the validator's error in the first case.
> Yes, EMF should treat them as entirely equivalent and should generate
> the same code for each.
>>
>> Regards,
>> Blazej
>>
Re: XSD to Java code generation with multiple import of the same namespace [message #425730 is a reply to message #425725] Fri, 05 December 2008 16:04 Go to previous message
Ed Merks is currently online Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Błażej,

It's always worked.


Błażej Kroll wrote:
> Hello,
>
> Thank you for the answer Ed.
>
> Just to close the subject. Can I expect the multiple import to work in
> EMF 2.2 or 2.3? Or is it a new introduced thing?
>
> Regards,
> Blazej
>
>
> Ed Merks pisze:
>> Blazej,
>>
>> Comments below.
>>
>>
>> Blazej Kroll wrote:
>>> Hello, to clarify the issue I'm facing:
>>>
>>> I want to generate Java from XML Schema.
>>> I am facing a validation error from Xerces when using multiple
>>> imports in an xml schema file like:
>>> <xsd:import schemaLocation="Part1.xsd"
>>> namespace="http://TestLibB"></xsd:import>
>>> <xsd:import schemaLocation="Part2.xsd"
>>> namespace="http://TestLibB"></xsd:import>
>> It seems to me they ought to support that.
>>>
>>> After looking for a workaround I tried to make it another way (not
>>> to see the validator's error)
>>> and make a fsingle file which includes the necessary Part1.xsd and
>>> Part2.xsd files and then import that file in the main Schema from
>>> which I will generate the Java code.
>>>
>>> Some file which gatheres all the necessery ones called
>>> Intermediate.xsd which includes:
>>> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>> targetNamespace="http://TestLib/B">
>>> <xsd:include schemaLocation="Part1.xsd"></xsd:include>
>>> <xsd:include schemaLocation="Part2.xsd"></xsd:include>
>>> </xsd:schema>
>>>
>>> and then in the main file to generate Java code I use single import
>>> operation:
>>> <xsd:import namespace="http://TestLib/B"
>>> schemaLocation="Intermediate.xsd"></xsd:import>
>>>
>>> So the validator is giving no errors.
>> Yes, that should work.
>>> Just to summer things up I want to make sure that from the EMF side
>>> both these scenarioes (multiple import usage) generate a valid Java
>>> code despite the validator's error in the first case.
>> Yes, EMF should treat them as entirely equivalent and should generate
>> the same code for each.
>>>
>>> Regards,
>>> Blazej
>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:ExtendedMetaData and inheritance
Next Topic:EList performance issues
Goto Forum:
  


Current Time: Fri Apr 19 09:19:39 GMT 2024

Powered by FUDForum. Page generated in 0.02317 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top