Matthew A. Miller | 8 Jul 16:20 2004
Picon

Re: gettting classcast exception when using XDataForm

 From my own testing, there were two ways I could reproduce what you're 
seeing.  The first was by not declaring the namespace of the element 
anywhere, and the second was by declaring a namespace mapping on the 
StreamContext, then using that prefix mapping in the imported DOM.

The second case is clearly a bug in JSO, and will be addressed*.  The 
first case would be a bug in your code, since JSO relies on the 
namespace-uri and local-name to determine what type of element to create.

For now, I recommend that you ensure the namespace for the imported 
elements are declared:

<x xmlns='jabber:x:data'>...</x>

If that still doesn't work, I'll need to see the dataset causing the 
problem, and probably more of your source.

-  LW

*  I cannot say exactly when, because the fix requires changes to a 
number of interfaces and classes.  It shouldn't break any code using 
JSO, but will very likely break any custom elements that have been defined.

suresh pendap wrote:
> 
> Hi ,
>         I am using the following code to parse the configuration xml 
> file and create a StreamElement from it.
> 
>      DocumentBuilder builder = _domFactory.newDocumentBuilder();
>    StringReader strReader = new StringReader(xml);
>    strReader.ready();
>    InputSource inputSrc = new InputSource(strReader);
>    Document doc = builder.parse(inputSrc);
>    org.w3c.dom.Element element = doc.getDocumentElement();
>          DOMImporter importer = 
> jso.createDOMImporter(stream.getOutboundContext());               
> StreamElement e = importer.read(element);
> 
> e is the stream element whose child element is supposed to be the 
> configure element which in turn contains the xdata form extension.
> Furrther i get the configure element and cast it to XForm and then try 
> to use the getField method which is when i get the class cast exception.
> 
> thanks
> suresh
> 
>  
> 
> Matthew A. Miller wrote:
> 
>> The method getField(String) retrieves XDataField instances, not 
>> XDataItem instances, and the source I have shows it to be doing that. 
>> Also, the cast should have been safe, but I'll make the adjustments to 
>> shore that up better.
>>
>> However, the only way I could see this happening if you tried to build 
>> the form completely outside the publicly available mechanisms (e.g. 
>> creating an ElementNode directly instead of through the factories). 
>> This is not supported behavior, and I'm making a note to add that to 
>> the FAQ.
>>
>> If you can provide your source code, then it might be clearer why you 
>> have this problem.
>>
>>
>> -  LW
>>
>> suresh pendap wrote:
>>
>>>
>>> Hi ,
>>>          I am getting a classcast exception when using the 
>>> XDataForm#getField(String var) method.  The code inside is trying to 
>>> typecast the object returned by the select method to XDataItem. But 
>>> when i printed the class name of the object it printed 
>>> net.outer-planes.jso.x.ElementNode.
>>> Below is the classcast exception.
>>> java.lang.ClassCastException
>>> at net.outer_planes.jso.x.xdata.FormNode.getField(FormNode.java 212)
>>>
>>> thanks
>>> suresh
>>>
>>> _______________________________________________
>>> jso-devel mailing list
>>> jso-devel <at> jabberstudio.org
>>> https://jabberstudio.org/mailman/listinfo/jso-devel
>>
>>
>> _______________________________________________
>> jso-devel mailing list
>> jso-devel <at> jabberstudio.org
>> https://jabberstudio.org/mailman/listinfo/jso-devel
> 
> 
> 
> _______________________________________________
> jso-devel mailing list
> jso-devel <at> jabberstudio.org
> https://jabberstudio.org/mailman/listinfo/jso-devel

Gmane