Just tried to execute generate goal with build of latest castor-maven-plugin
2.0-SNAPSHOT sources, with generateMappings set to true. It still breaks but
provides more details. Here is build stack trace snippet:
Caused by: NestedIOException: Unable to resolve ID for instance of class
'java.lang.String' due to the following error: Unable to resolve
ClassDescriptor. { nested error: Unable to resolve ID for instance of class
'java.lang.String' due to the following error: Unable to resolve
ClassDescriptor.}
at
org.exolab.castor.builder.SourceGenerator.generateMappingFile(SourceGenerator.java:891)
at
org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:756)
at
org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:696)
at
org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:593)
at
org.codehaus.mojo.castor.GenerateMojo.processFile(GenerateMojo.java:452)
... 20 more
There seem to be several open issues
(CASTOR-1361<http://jira.codehaus.org/browse/CASTOR-1361>,
CASTOR-1894 <http://jira.codehaus.org/browse/CASTOR-1894>,
CASTOR-2667<http://jira.codehaus.org/browse/CASTOR-2667>)
with similar error. Currently neither of the used XSD's uses id/idref/key
and same happens regardless of marshal property value (default, true,
false).
One difference I noticed between 1.5 and 2.0-SNAPSHOT is that mapping.xml is
no longer empty, but it is incomplete. It (is not pretty printed and) ends
with:
...<class name="foo.bar.A" access="shared"><map-to xml="
B xsd complex type has an element of A type, and another element of C type
which has 0-unbounded element of A type:
one.xsd (ns1; imports "other XSD" and references ns2 types from it)
-------------------------
...
<xsd:complexType name="B">
<xsd:sequence>
<xsd:element name="c1" type="ns2:C" />
<xsd:element name="a1" type="ns2:A" />
</xsd:sequence>
</xsd:complexType>
...
-------------------------
other XSD (ns2)
-------------------------
...
<xsd:complexType name="A">
<xsd:sequence>
...
<xsd:sequence>
</xsd:complexType>
<xsd:complexType name="C">
<xsd:sequence>
<xsd:element name="a2" type="A" minOccurs="0" maxOccurs="unbounded"
/>
<xsd:sequence>
</xsd:complexType>
...
-------------------------
Castor generates mapping well for class B and C1, but fails for A1.
Hopefully some of the above will help to resolve the issue.
Was just wondering, since one can provide generate goal with multiple schema
files in one go, does Castor perform some resolution in which order it
should process XSD files? Can it handle situation where two XSD's import
same third XSD?
Regards,
Stevo.
On Tue, Aug 11, 2009 at 12:52 PM, Stevo Slavić <[email protected]> wrote:
> Hello Werner,
>
> I'm using Spring-WS with Spring-OXM abstractions over OXM frameworks, and
> its Castor support, all for easy replacement of OXM implementation. Thus,
> when generating sources with castor-maven-plugin I've set "marshal"
> parameter to false, and want to have mapping.xml generated along with
> classes from set of XSD's, and configure Spring's CastorMarshaller with
> generated mapping.xml. Rest of my comments are inline.
>
> Regards,
> Stevo.
>
> On Tue, Aug 11, 2009 at 10:21 AM, Werner Guttmann <[email protected]>wrote:
>
>> Hi Stevo,
>>
>> can you please let me know why you want a mapping file to be generated
>> at all ? Java classes plus descriptor classes should be sufficient for
>> you needs, if this is about (un-)marshalling to and from XML (as defined
>> by your XML schemas).
>>
>> Some more answers are inline.
>>
>> Regards
>> Werner
>>
>> Stevo Slavić wrote:
>> > OK, thank you very much!
>> >
>> > Generating classes works well now, but once I set generateMappings to
>> true,
>> > generate goal fails with following error:
>> >
>> > The following exception occured while validating field:
>> _classMappingList of
>> > class: org.exolab.castor.mapping.xml.MappingRoot: The following
>> exception
>> > occured while validating field: _classChoice of class:
>> > org.exolab.castor.mapping.xml.ClassMapping: The following exception
>> occured
>> > while validating field: _fieldMappingList of class:
>> > org.exolab.castor.mapping.xml.ClassChoice: The following exception
>> occured
>> > while validating field: _bindXml of class:
>> > org.exolab.castor.mapping.xml.FieldMapping: The following exception
>> occured
>> > while validating field: _name of class:
>> > org.exolab.castor.mapping.xml.BindXml: Name '-error-if-this-is-used-' is
>> not
>> > a valid QName.
>> If you do not set <generateMappings> to true, does code generation
>> succeed ?
>
>
> Yes, code generation alone succeeds.
>
>
>>
>> > Any idea what could be the problem? Guess I'm hit by this Castor
>> > issue<http://jira.codehaus.org/browse/CASTOR-676>.
>> > Advices/workarounds are welcome too.
>> >
>> > Version 1.5 of castor-maven-plugin is being used. There seems to be no
>> > (documented) way to set output directory for mappings file ("dest"
>> parameter
>> > does not seem to influence generation of mapping.xml).
>> Correct. But there's two more MOJOs that specialize in creating just
>> mapping files. Please have a look at
>>
>> http://mojo.codehaus.org/castor-maven-plugin/plugin-info.html
>
>
> Thanks for the info, missed those two. There are no usage examples for them
> documented neither
> here<http://mojo.codehaus.org/castor-maven-plugin/usage.html>nor
> here <http://www.castor.org/srcgen-maven-plugin.html>, this might have
> attributed to me missing these two goals . For mappings goal I'm having
> problems configuring classes parameter. Documentation for the field states
> it is a set but in fact it is a map. By looking on source code where map is
> used, key is extracted as class name while map value is mapping name. If
> classes parameter should be configured using usual way maven plugins
> configuration parameters of map type are configured, then classes should be
> defined something like this:
>
> ...
> <classes>
> <foo.bar.Class1>mapping.xml</foo.bar.Class1>
> <foo.bar.Class2>mapping.xml</foo.bar.Class2>
> ...
> </classes>
> ...
>
> With generate goal bound to generate-source phase, and mappings goal (by
> default) bound to process-classes phase with single class (generated by
> generate goal) configured to be processed by mappings goal, mappings goal
> fails with ClassNotFoundException (can not find class which has been
> generated by generate goal in an earlier phase). In eclipse with m2eclipse
> installed target/generated-sources/castor gets configured (Update project
> configuration) as source directory, but I'm not sure if Maven sees it as
> such when building project. Does castor-maven-plugin somehow suggest maven
> that castor-maven-plugin's dest directory should be treated as source
> directory? If not, am I supposed to use build-helper-maven-plugin to
> accomplish this? Nevertheless, I did it, used build-helper-maven-plugin's
> add-source goal configured with
> ${project.build.directory}/generated-sources/castor source. Unfortunately,
> castor-maven-plugin's mappings goal would still fail with same
> ClassNotFoundException being thrown. Wondering what could be the cause.
>
> Let's not forget that using mappings goal is a workaround for failing
> generate goal with generateMappings set to true.** In any non trivial
> usage, configuration of classes parameter of castor-maven-plugin's mappings
> goal will be ugly. Wish there was e.g. packages parameter, or wildcards
> support for more coarse grained selection of classes to be mapped.
>
> One more thought, in maven lifecycle compile phase comes after
> generate-resources and process-resources phases. castor-maven-plugin's
> mapping file basically generates a resource (mapping.xml), but I guess,
> since it requires compiled classes, it is bound to process-classes phase,
> first one after compile phase.
>
> Thinking of trying build with castor-maven-plugin 2.0-SNAPSHOT, maybe it
> will help overcome these issues. From the 1.5 announcement it was mentioned
> that 2.0 will be soon released - hopefully that's still the plan.
>
>
>
>>
>>
>> > Currently, in my case
>> > with the error above, (empty) mappings.xml file gets generated in
>> ${basedir}
>> > of the project. It's a resource so by default IMO it should be generated
>> in
>> > ${project.build.directory}/generated-resources/castor directory.
>> Couldn't
>> > find existing issue for this in MCASTOR JIRA. Is there a way to
>> configure
>> > mappings file output directory?
>> No, but please feel free to add a new issue. I guess I don't have to
>> mention that a patch would be warmly welcome as well.
>
>
> OK
>
>
>>
>>
>> > One more issue, plugin fails a build if there is no
>> > ${basedir}/src/main/castor directory in the project. If I understood
>> well,
>> > this will be fixed for v2.0 of the plugin.
>> That should have been fixed for 1.5 already. Odd. But if it still does,
>> please feel free to raise a issue (even if it's a duplicate).
>
>
> OK
>
>
>>
>>
>> > Regards,
>> > Stevo.
>> >
>> > On Mon, Aug 10, 2009 at 8:44 PM, Werner Guttmann <
>> [email protected]>wrote:
>> >
>> >> Hi,
>> >>
>> >> You can always supply a binding file to the (underlying) Castor XML
>> code
>> >> generator to override the default output type for <xs:date> instances.
>> >>
>> >> Regards
>> >> Werner
>> >>
>> >> Stevo Slavić wrote:
>> >>> Hello castor(-maven-plugin) users,
>> >>>
>> >>> Does anyone know why does castor-maven-plugin (1.5) for xs:date
>> elements
>> >>> generate class properties of org.exolab.castor.types.Date type? Is
>> there
>> >> any
>> >>> way to have it configured to generate java.util.Date instead?
>> >>>
>> >>> Regards,
>> >>> Stevo.
>> >>>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe from this list, please visit:
>> >>
>> >> http://xircles.codehaus.org/manage_email
>> >>
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>