Hi,
answers inline, and let me try to rephrase my question as well.
Cheers
Werner
Lukasz Kustusz wrote:
> Thank you for answering. I'm not sure I understand the question
properly. I think the descriptors did get generated. It wasn't a
requirement, just the way I run the generator. I added the -nodesc flag
and now I have the mapping (attached) and the descriptors are gone.
Okay, fine. But why do you want to use a mapping file when you could use
the generated descriptor classes ? The descriptor classes hold all
information required so that Castor XML (during data binding operations)
will produce/unmarshal from the XML as defined in your XML schema. In
other words, there's no need to use a mapping file when all you want is
to use XML data binding.
> But when I try to use it I get the MappingException "Could not find
the class nikonpromosystem.PromoCall", even though the package is listed
in the source packages in my project, and the PromoCall class is in
there.
Did you compile the generated java classes, and put them on your
classpath (incl. the .castor.cdr files) ?
> Note that the declaration of PromoCall works, so the class is
> visible.
>
> Here's my code:
>
> nikonpromosystem.PromoCall promocall;
> Mapping mapping = new Mapping();
> URL url1 =
> this.getClass().getClassLoader().getResource("binding/promomap.xml");
> mapping.loadMapping(url1);
> Unmarshaller unmarshaller = new Unmarshaller(promocall.getClass());
> unmarshaller.setMapping(mapping); //error occurs here
>
> I also tried defining promocall as nikonpromosystem.PromoCallType, but I got
> the same error.
What does the exact stack trace look like ?
>
> Lukasz
>
> -----Original Message-----
> From: Werner Guttmann [mailto:[email protected]]
> Sent: April-29-09 6:05 AM
> To: [email protected]
> Subject: Re: [castor-user] [xml] The class for the root element ... could not
> be found
>
> Hi Lukasz,
>
> before trying to answer your questions (inline, that is), can I ask you
> something ? What's the reason to generate Java classes from your XML
> schema without descriptor classes (instead of a mapping file) ? I just
> would like to understand this requirement.
>
> Cheers
> Werner
>
> Lukasz Kustusz wrote:
>> Hello,
>>
>> Actually I have several newbie questions, as I'm not sure I know what
>> I'm doing with Castor, but the final message in the log (attached) is
>> where I finally hit the wall.
>>
>> I'm trying to: 1. Generate necessary objects from a xsd schema
>> (attached). To this effect I'm using the below command
>>
>>
>> java -classpath
>> .;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\castor-1.2\castor-1.2-codegen.jar;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\castor-1.2\castor-1.2.jar;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\castor-1.2\castor-1.2-xml.jar;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\commons-logging-1.1.1.jar;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\castor-1.2\castor-1.2-xml-schema.jar;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\castor-1.2\castor-1.2-ddlgen.jar;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\velocity-1.6.2.jar
>> org.exolab.castor.builder.SourceGeneratorMain -i
>> Resources\promo3_4.xsd -package nikonpromosystem -gen-mapping
>> promomap -verbose
>>
>> Here there's two issues: First the mapping (sic!) doesn't get generated, even
>> though the command executes without errors.
> In addition to the -gen-mapping option you will have to use the -nodesc
> option.
>
>> Second of all I get my
>> objects in 4 different packages:
>>
>> nikonpromosystem
>> nikonpromosystem.descriptors
>> nikonpromosystem.types
>> nikonpromosystem.types.descriptors
> Yes, this is default. When you start using the -nodesc option, the
> descriptors packages will disappear.
>
>> In classes.txt there's the listing of all the classes generated.
>> Definitelly more than I expected from the xsd. Nevertheless I tried
>> to use those classes in my code, using the code examples without the
>> mapping (castor-reference-guide-1.3 sections 1.8.2.2 & 1.8.2.3.2) .
>> Here's the code:
> Hi, if you did not use this with the mapping file(that did not get
> generated), there is no use trying this, as the XML
> generated/unmarshalled from will not meet the XML schema. You will have
> to use either the mapping generated and or the XML class descriptors.
>>
>> private Unmarshaller unmarshaller; private Marshaller marshaller;
>> private XMLContext context; private static Logger log; private
>> XMLClassDescriptorResolver classDescriptorResolver; private
>> nikonpromosystem.PromoCall promocall ;
>>
>> promocall = new nikonpromosystem.PromoCall(); String[] s = new
>> String[]{"nikonpromosystem","nikonpromosystem.descriptors","nikonpromosystem.types","nikonpromosystem.types.descriptiors"};
>> context = new XMLContext(); try { context.addPackages(s);
>> //that's where the error happens; } catch (ResolverException ex) {
>> log.error(ex);}
>>
>> unmarshaller = context.createUnmarshaller(); marshaller =
>> context.createMarshaller();
>>
>> reader = new FileReader("sample.xml"); promocall =
>> (nikonpromosystem.PromoCall) unmarshaller.unmarshal(reader);
>>
>>
>> I also tried to replace the XMLContext with classDescriptorResolver
>> bat that also failed:
>>
>> promocall = new nikonpromosystem.PromoCall(); classDescriptorResolver
>> =
>> (org.exolab.castor.xml.XMLClassDescriptorResolver)ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
>>
>> classDescriptorResolver.setClassLoader(promocall.getClass().getClassLoader());
>> //NullPointerException
>>
>> I also tried generating the mapping from within the code using the
>> MappingTool, but...:
>>
>> MappingTool tool = new MappingTool(); promocall = new
>> nikonpromosystem.PromoCall(); tool.addClass(promocall.getClass());
>> //NullPointerException
>>
>> At this point I don't know what else I can try... Help?
>>
>>
>> Lukasz.
>>
>>
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> 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