Castor Gurus:

I have the following xml to be unmarshalled:

<foo>
        <id>42</id>
        <bar>
                <greeting>hello world</greeting>        
        </bar>  
</foo>

into the following classes:


public class Foo {
        public Bar bar;
        public String id;
        
        public Bar getBar() {
                return bar;
        }

        
        public void setBar(Bar bar) {
                this.bar = bar;
        }


        public String getId() {
                return id;
        }

        public void setId(String id) {
                this.id = id;
        }

}


and 


public class Bar {
        
        public String greeting;
        public Foo foo;

        
        public String getGreeting() {
                return greeting;
        }

        
        public void setGreeting(String greeting) {
                this.greeting = greeting;
        }

        
        public Foo getFoo() {
                return foo;
        }

        
        public void setFoo(Foo foo) {
                this.foo = foo;
        }

}

where in Bar I would like a reference to the parent
class Foo.
I set up the mapping as such:

<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object
Mapping DTD Version 1.0//EN"
                        
"http://castor.exolab.org/mapping.dtd";>

<mapping>
        
        <class name="tudo.foobar.castor.domain.Foo">
                <map-to xml="foo"/>

                <field name="id"
type="java.lang.String">
                        <bind-xml name="id"
node="element"/>
                </field>
                
                <field name="bar"
type="tudo.foobar.castor.domain.Bar">
                        <bind-xml name="bar"
node="element"/>
                </field>
     </class>
     
     <class name="tudo.foobar.castor.domain.Bar">
                <map-to xml="bar"/>

                <field name="greeting"
type="java.lang.String">
                        <bind-xml name="greeting"
node="element"/>
                </field>
                
                <field name="foo"
type="tudo.foobar.castor.domain.Foo" >
                        <bind-xml name="foo" />
                </field>
     </class>
     
</mapping>


and test it as such:

private void execute(){
                Mapping      mapping = new Mapping();

                try {
                        // 1. Load the mapping information from the file
                        mapping.loadMapping( "fooMap.xml" );

                        // 2. Unmarshal the data
                        Unmarshaller unmar = new Unmarshaller(mapping);
                        Foo foo = (Foo)unmar.unmarshal(new InputSource(new
FileReader("FooTest.xml")));

                        // 3. Do some processing on the data
                        System.out.println(foo.getBar().getGreeting());
                        System.out.println(foo.getBar().getFoo().getId());
                } catch (Exception e) {
                        System.out.println(e);
                        return;
                }
        }


and the result is:

hello world
java.lang.NullPointerException

I have tried setting the location attribute to ".."
but it does not seem to go "backwards". I have also
tried handlers but can only get the current class- not
the parent class.

Does anyone know how to get a reference to the parent
class of which another class is a member- as just
described????
I tried many sources but have come up with nothing- is
this a Castor limitation?????

Thaanks,

Jim




__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

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

Reply via email to