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. 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" 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. 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
promomap.xml
Description: promomap.xml
<?xml version="1.0" encoding="utf-8" ?> <!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)--> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="PromoCall" type="PromoCallType" /> <xs:complexType name="PromoCallType"> <xs:sequence> <xs:element name="PromoCallID" type="JobIdentificationType" /> <xs:element minOccurs="0" maxOccurs="1" name="Account" type="AccountType" /> <xs:element minOccurs="0" maxOccurs="1" name="JobType"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="RX" /> <xs:enumeration value="CUSTCOAT" /> <xs:enumeration value="BULKSTK" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element minOccurs="0" maxOccurs="1" name="JobSource"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="INTERNAL" /> <xs:enumeration value="REMOTE" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element minOccurs="0" maxOccurs="1" name="PromoStatus"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="NOPROMOAPPLICABLE" /> <xs:enumeration value="PROMOAPPLICABLE" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element minOccurs="0" maxOccurs="unbounded" name="ForcedPromotions" type="PromotionType" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="LensItems" type="LensType" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="AddedValueItems" type="AddedValueType" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="PromoOutput" type="PromotionType" /> </xs:sequence> </xs:complexType> <xs:complexType name="AccountType"> <xs:sequence> <xs:element name="billToAccount" type="xs:string" /> <xs:element name="accountName" type="xs:string" /> <xs:element name="Address" type="AddressType" /> <xs:element name="SalesRep" type="SalesRepType" /> <xs:element name="BuyingGroup" type="BuyingGroupType" /> <xs:element name="Chain" type="ChainType" /> <xs:element name="BusinessType" type="xs:string" /> <xs:element name="PreferedLanguage"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="FRA" /> <xs:enumeration value="ENG" /> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> <xs:complexType name="AddressType"> <xs:sequence> <xs:element name="Address1" type="xs:string" /> <xs:element name="Address2" type="xs:string" /> <xs:element name="City" type="xs:string" /> <xs:element name="Province" type="xs:string" /> <xs:element name="PostalCode" type="xs:string" /> <xs:element name="Region" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="SalesRepType"> <xs:sequence> <xs:element name="ID" type="xs:string" /> <xs:element name="Name" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="BuyingGroupType"> <xs:sequence> <xs:element name="ID" type="xs:string" /> <xs:element name="Name" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="ChainType"> <xs:sequence> <xs:element name="ID" type="xs:string" /> <xs:element name="Name" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="JobIdentificationType"> <xs:sequence minOccurs="1" maxOccurs="1"> <xs:element name="jobNumber" type="xs:string" /> </xs:sequence> </xs:complexType> <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> <xs:complexType name="LensType"> <xs:sequence> <xs:element name="lensID" type="xs:string" /> <xs:element name="lensName" type="xs:string" /> <xs:element name="lensProductLineName" type="xs:string" /> <xs:element name="Coating" type="AddedValueType" /> <xs:element name="Material" type="MaterialType" /> <xs:element name="Manufacturer" type="ManufacturerType" /> <xs:element minOccurs="0" maxOccurs="unbounded" name="AddedValues" type="AddedValueType" /> <xs:element name="LensBilling" type="BillingType" /> </xs:sequence> </xs:complexType> <xs:complexType name="MaterialType"> <xs:sequence> <xs:element name="materialID" type="xs:string" /> <xs:element name="materialName" type="xs:string" /> <xs:element name="indexOfRefraction" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="ManufacturerType"> <xs:sequence> <xs:element name="manufacturerID" type="xs:string" /> <xs:element name="manufacturerName" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="AddedValueType"> <xs:sequence> <xs:element name="addedValueID" type="xs:string" /> <xs:element name="addedValueName" type="xs:string" /> <xs:element name="AddedValueBilling" type="BillingType" /> </xs:sequence> <xs:attribute name="source"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="PROMOSYSTEM" /> <xs:enumeration value="ORDERSYSTEM" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> <xs:complexType name="BillingType"> <xs:sequence> <xs:element name="quantity" type="xs:float" /> <xs:element name="ListPrice" type="MonetaryUnitType" /> <xs:element name="PromoDiscountAmount" type="MonetaryUnitType" minOccurs="0" /> </xs:sequence> </xs:complexType> <xs:complexType name="MonetaryUnitType"> <xs:attribute name="scale" type="xs:int" /> <xs:attribute name="precision" type="xs:int" /> <xs:attribute name="currencyAbbr" type="xs:string" /> </xs:complexType> <xs:complexType name="PromoImageType"> <xs:sequence> <xs:element name="imageID" type="xs:string" /> <xs:element name="imagePath" type="xs:string" /> </xs:sequence> </xs:complexType> <xs:complexType name="InvoiceMessageType" /> </xs:schema>
promo_in_3_6.xml
Description: promo_in_3_6.xml
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email

