-----Original Message----- From: Werner Guttmann [mailto:[email protected]] Sent: April-30-09 3:15 AM To: [email protected] Subject: Re: [castor-user] [xml] The class for the root element ... could not be found
Hi, replying sequentially .. ;-). Lukasz Kustusz wrote: > OK, I got a little bit further along now. The fix to the > MappingException was the incorrect classLoader. I found a fix here: > > http://www.mail-archive.com/[email protected]/msg00196.html > > After that I've had some issues with type-safe enums. The error was > like below: "org.exolab.castor.mapping.MappingException: The Java > class nikonpromosystem.PromoStatus is not constructable -- it does > not contain a default public constructor." The fix for that was in > http://castor.codehaus.org/xml-mapping.html in sections 7.5 and 7.4. > The PromoStatus was a special case. It was an enum but in an > attribute, so the verify-constructable="false" didn't work on it. I > had to change it to an element. Hmm, that should not be required. Can you please raise a Jira issue and attach a very simple sample for us to reply this ? Sure, http://jira.codehaus.org/browse/CASTOR-2701 > Now I've finally arrived at the following error: > > "The method getExtraParametersList/isExtraParametersList in class > nikonpromosystem.PromotionType accepting/returning object of type > class nikonpromosystem.ExtraParameters was not found" That indicates that in your mapping you have a field mapping for a property 'extraParametersList' with a type of 'ExtraParameters'. Is that meant to be a collection or not ? How does the mapping for this one property look like ? Here's the relevant mapping section: <class name="nikonpromosystem.PromoParameterType" access="shared"> <map-to xml="PromoParameterType" element-definition="false"/> . . . <field name="extraParametersList" type="nikonpromosystem.ExtraParameters"> <bind-xml name="ExtraParameters" node="element"/> </field> . </class> Here's the relevant schema section: <xs:complexType name="PromotionType"> <xs:sequence minOccurs="1" maxOccurs="1"> <xs:element name="promoSource"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="ORDERENTRY" /> <xs:enumeration value="PROMOSYSTEM" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="promotionID" type="xs:string" /> <xs:element name="promotionName" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="ExtraParameters" type="PromoParameterType" /> </xs:sequence> </xs:complexType> <xs:complexType name="PromoParameterType"> <xs:sequence> <xs:element name="parameterName" type="xs:string" /> <xs:element name="parameterType"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="IMAGEPATH" /> <xs:enumeration value="INVOICEMESSAGE" /> <xs:enumeration value="AGENTMESSAGE" /> <xs:enumeration value="INPUTPARAMETER" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="parameterValue" type="xs:string" /> </xs:sequence> </xs:complexType> This is the xml: <ns0:ForcedPromotions> <ns0:promoSource>ORDERENTRY</ns0:promoSource> <ns0:promotionID>130</ns0:promotionID> <ns0:promotionName>NIKON COUPONS 1</ns0:promotionName> <ns0:ExtraParameters> <ns0:parameterName>COUPON NUMBER1</ns0:parameterName> <ns0:parameterType>INPUTPARAMETER</ns0:parameterType> <ns0:parameterValue>12345AB</ns0:parameterValue> </ns0:ExtraParameters> <ns0:ExtraParameters> <ns0:parameterName>COUPON NUMBER2</ns0:parameterName> <ns0:parameterType>INPUTPARAMETER</ns0:parameterType> <ns0:parameterValue>1243C</ns0:parameterValue> </ns0:ExtraParameters> </ns0:ForcedPromotions> > > Do I have to try to create these methods by hand, or did I miss > something? I'm attaching the latest versions of my schema, sample > XML, and the mapping. Not really of use here. Please always try to be as specific as possible when asking questions. > > Lukasz > > -----Original Message----- From: Lukasz Kustusz Sent: April-29-09 > 1:12 PM To: [email protected] Subject: RE: [castor-user] [xml] > The class for the root element ... could not be found > > 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. > > 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. 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. > > 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-codeg >> >> en.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.ja >> >> r;C:\Progra~1\Java\jdk1.6.0_11\jre\lib\ext\castor-1.2\castor-1.2-xml-s >> >> chema.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","nikonpromo >> system.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)ClassDescriptorResol >> verFactory.createClassDescriptorResolver(BindingType.XML); >> >> classDescriptorResolver.setClassLoader(promocall.getClass().getClassLo >> ader()); //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 --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

