No worries. It's just a shame to have used all this time to help you,
had you told us earlier.

Regards
Werner

Lukasz Kustusz wrote:
> I finally switched to JAXB and with the help of ValidationEventCollector I 
> was able to pinpoint all the problems with my schema / xml. I tried briefly 
> to use the modified schema with the castor but I ended up with the same 
> marshalling exception. I didn't investigate further because the JAXB objects 
> work for me quite well and I'm on a very tight deadline. Thanks all for your 
> help.
> 
> Lukasz
> 
> -----Original Message-----
> From: Werner Guttmann [mailto:[email protected]]
> Sent: May-07-09 2:40 AM
> To: [email protected]
> Subject: Re: [castor-user] [xml] The class for the root element ... could not 
> be found
> 
> Lukasz,
> 
> I have just added some comments to one of the Jira issues raised by you.
>  Are they of any use to you ?
> 
> Cheers
> Werner
> 
> Lukasz Kustusz wrote:
>> I gave it a shot, but, just like before I'm getting a NullPointerException 
>> on the classDescriptorResolver.setClassLoader.
>> Here's my code again:
>>
>> Unmarshaller unmarshaller;
>> XMLClassDescriptorResolver classDescriptorResolver;
>> PromoCallType promocall ;
>> String[] s = new 
>> String[]{"nikonpromosystem","nikonpromosystem.descriptors","nikonpromosystem.types","nikonpromosystem.types.descriptiors"}
>>
>> classDescriptorResolver = 
>> (XMLClassDescriptorResolver)ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
>> classDescriptorResolver.setClassLoader(this.getClass().getClassLoader());    
>>    //NullPointerException
>> classDescriptorResolver.addPackages(s);
>> unmarshaller = new Unmarshaller();
>> unmarshaller.setResolver(classDescriptorResolver);
>> reader = new FileReader("promo_in_3_6.xml");
>> promocall = (nikonpromosystem.PromoCallType) unmarshaller.unmarshal(reader);
>>
>>
>> When I change to the XMLContext, I get a MarshalException : "The marshaller 
>> cannot marshal/unmarshal types of Void.class, Class.class or Object.class""
>> My code with the XMLContext:
>>
>> context = new XMLContext();
>> context.addPackages(s);
>> unmarshaller = context.createUnmarshaller();
>> unmarshaller.setClassLoader(getClass().getClassLoader());
>> reader = new FileReader("promo_in_3_6.xml");
>> promocall = (nikonpromosystem.PromoCallType) unmarshaller.unmarshal(reader); 
>>    //MarshalException happens here
>>
>>
>> Lukasz
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: Werner Guttmann [mailto:[email protected]]
>> Sent: May-04-09 6:32 AM
>> To: [email protected]
>> Subject: Re: [castor-user] [xml] The class for the root element ... could 
>> not be found
>>
>> Hi,
>>
>> to cut things short, can I ask you somthing ? Can you please - for the
>> time being - switch to using the generated descriptor classes, as I am
>> 100% sure that things should work out of the box.
>>
>> In other words, drop generation of the mapping file, re-enable
>> generation of the descriptor classes, and you should be flying. As you
>> compile and package your applications, don't forget to include the
>> .castor.cdr files as generated during code generation.
>>
>> Can you please try that ?
>>
>> lG.
>> Werner
>>
>> Lukasz Kustusz wrote:
>>> Again I got a little bit ahead. The missing methods I just added manually 
>>> like so:
>>>
>>>    public nikonpromosystem.ExtraParameters[] getExtraParametersList() {
>>>       //this class is virtually the same as getExtraParameters(), that was 
>>> auto-generated. I just changed the name
>>>         nikonpromosystem.ExtraParameters[] array = new 
>>> nikonpromosystem.ExtraParameters[0];
>>>         return (nikonpromosystem.ExtraParameters[]) 
>>> this._extraParametersList.toArray(array);
>>>     }
>>>
>>>     public boolean isExtraParametersList(final 
>>> nikonpromosystem.ExtraParameters[] lst) {
>>>               //unfortunately there was no isExtraParameters(). I had to do 
>>> that from the scratch.
>>>         boolean retval =  this._extraParametersList.equals(lst);
>>>         return retval;
>>>     }
>>>
>>> If there's a better way, please let me know. I had to do that for every 
>>> class that had Lists.
>>>
>>> After that the addmapping works, but unmarshal returns all nulls. So again 
>>> the code:
>>>
>>>        Mapping mapping = new Mapping(getClass().getClassLoader());
>>>         URL url1 = 
>>> getClass().getClassLoader().getResource("binding/promomap.xml");
>>>         mapping.loadMapping(url1);
>>>         XMLContext context = new XMLContext();
>>>         context.addMapping(mapping);//I go past this point now
>>>
>>>       FileReader reader = new FileReader(sFileName);
>>>       nikonpromosystem.PromoCall  promocall = (nikonpromosystem.PromoCall) 
>>> unmarshaller.unmarshal(reader);
>>>
>>>       //The unmarshal works but all fields inside promocall are null. When 
>>> I step into this statement, It only executes the constructor, which calls 
>>> the  PromoCallType  constructor which creates new lists and returns.
>>>
>>>       I also tried to unmarshal into the type object
>>>       nikonpromosystem.PromoCallType  promocall = 
>>> (nikonpromosystem.PromoCallType) unmarshaller.unmarshal(reader);
>>>
>>>       but the result is the same - all fields are null.
>>>
>>>
>>> Here's the mapping of the PromoCall:
>>> <class name="nikonpromosystem.PromoCall" access="shared">
>>> <map-to xml="PromoCall" element-definition="true"/>
>>> </class>
>>>
>>> Now I noticed that all type classes in the mapping are trying to map to the 
>>> xml names like so, but in the xml there's no PromoCallType tag, because 
>>> it's a type that's only defined in the scheme.
>>> <class name="nikonpromosystem.PromoCallType" access="shared">
>>>       <map-to xml="PromoCallType" element-definition="false"/>
>>> <field name="promoCallID" type="nikonpromosystem.PromoCallID" 
>>> required="true">
>>> <bind-xml name="PromoCallID" node="element"/>
>>> </field>
>>> <field name="account" type="nikonpromosystem.Account">
>>> <bind-xml name="Account" node="element"/>
>>> </field>
>>> :
>>> :
>>> </class>
>>>
>>> How can I make it work?
>>>
>>>
>>>
>>>
>>> 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
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
> 
> 

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to