You have a few options at this point.
First, be sure you've compiled the generated *Descriptor.java files
and they're in the cp.

1) 
        _cdr = new ClassDescriptorResolverImpl();

          _cdr.resolve(/* one option for top level class */);
          _cdr.resolve(/* a different option for top level class */);
          _cdr.resolve(/* yet a third option for top level class */);
        
        _myUnmarshaller = new Unmarshaller((Class)null);
        _myUnmarshaller.setResolver(_cdr);        
        //Now you can safely unmarshall.

2) In the instance document, add an xsi:type attribute
        on the node that you'll pass to the unmarshaller.
        You don't need to specify it for the child nodes, b/c
        this info is code generated into the *Descriptor.java files.
        Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<Wrapper>
    <Aclass xsi:type="java:pollux.AxClass" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
        <sString>string23</sString>
        <xInt>23</xInt>
    </Aclass>
</Wrapper>



3) Instead of using xsi:type, you can specify a namespace.
        This option is nice because you can easily change
        your package structure without breaking the client.

        See this post for an example: 
http://www.mail-archive.com/[email protected]/msg09658.html

Hope this help,

--Erik

      > -----Original Message-----
      > From: Dean Hiller [mailto:[EMAIL PROTECTED]]
      > Sent: Thursday, December 05, 2002 7:42 AM
      > To: [EMAIL PROTECTED]
      > Subject: Re: [castor-dev] unmarshalling unkown xml with 
      > generated code
      > 
      > 
      > That didnt' seem to work, throws an exception saying 
      > "The class for the 
      > root element 'ButtonPress' could not be found from the 
      > UnmarshalHandler. 
      >  I am looking at the UnmarshalHandler and the classDesc 
      > returned from 
      > _cdResolver.resolveByXMLName(name, namespace, null); is 
      > null.  Because 
      > of this, the exception is thrown.  _cdResolver is a 
      > ClassDescriptorResolverImpl, so I am now looking at 
      > that.  It loads from 
      > the mapping first(which I don't have as I read this is 
      > for non-generated 
      > source code).  It then goes through the cached 
      > elements.  The cache size 
      > is 0.  There are no elements in the cache.  Am I 
      > missing something?
      > thanks very much for your help,
      > Dean
      > 
      > [EMAIL PROTECTED] wrote:
      > 
      > >Use this:
      > >
      > >        _myUnmarshaller = new Unmarshaller((Class)null);
      > >
      > >
      > >      > -----Original Message-----
      > >      > From: Dean Hiller [mailto:[EMAIL PROTECTED]]
      > >      > Sent: Wednesday, December 04, 2002 3:56 PM
      > >      > To: [EMAIL PROTECTED]
      > >      > Subject: [castor-dev] unmarshalling unkown xml with 
      > >      > generated code
      > >      > 
      > >      > 
      > >      > I am sorry, the mail archives seem to be down, so I 
      > >      > could not search 
      > >      > them yet.
      > >      > 
      > >      > I see Mapping is supposed to be used for non-generated 
      > >      > code from what I 
      > >      > read so far.  How do I unmarshal objects where I don't 
      > >      > know what the xml 
      > >      > is ahead of time.  I can't seem to just do this
      > >      > 
      > >      > UnMarshaller u = new UnMarshaller();
      > >      > Object o = u.unmarshal(myStream);
      > >      > if(o instanceof Device).......
      > >      > else if(o instanceof System).....
      > >      > 
      > >      > I am sure castor can handle this.  I am just not sure 
      > >      > how to do it.
      > >      > thanks for any help in this,
      > >      > Dean
      > >      > 
      > >      > 
      > ----------------------------------------------------------- 
      > >      > If you wish to unsubscribe from this mailing, 
      > send mail to
      > >      > [EMAIL PROTECTED] with a subject of:
      > >      >        unsubscribe castor-dev
      > >      > 
      > >      > 
      > >
      > >----------------------------------------------------------- 
      > >If you wish to unsubscribe from this mailing, send mail to
      > >[EMAIL PROTECTED] with a subject of:
      > >       unsubscribe castor-dev
      > >
      > >  
      > >
      > 
      > ----------------------------------------------------------- 
      > If you wish to unsubscribe from this mailing, send mail to
      > [EMAIL PROTECTED] with a subject of:
      >         unsubscribe castor-dev
      > 
      > 

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to