Hi Sathya,
You have properly set the mapping, but then you are calling one of the
static "marshal" methods. The static methods will create a new
marshaller and won't have access to your mapping file. Please change
this from:
StringWriter sw2 = new StringWriter();
Marshaller marshaller = new Marshaller(sw2);
marshaller.setMapping(castorMapping);
Schedule schedule = new Schedule();
schedule.setDirection("E");
marshaller.marshal( schedule, sw2 );
to:
StringWriter sw2 = new StringWriter();
Marshaller marshaller = new Marshaller(sw2);
marshaller.setMapping(castorMapping);
Schedule schedule = new Schedule();
schedule.setDirection("E");
marshaller.marshal( schedule );
--Keith
"Krishnasamy, Sathya" wrote:
>
> Team,
>
> IF I uncomment marshaller.setMapping(castorMapping) call , it does not seem
> to make a differrence in the output. I tried to follow the simple example
> in the CASTOR site.
>
> Am I missing anything? There is a tip in the site saying " Are your class
> descriptors compiled along with the source"? But I am using a mapping file
> at runtime, rather than compile time descriptors.
>
> EXPECTED OUTPUT:
>
> xmlResult ::: <?xml version="1.0" encoding="UTF-8"?>
> <scheduleRenamed dir="ES">
> </scheduleRenamed>
>
> CURRENT OUTPUT:
>
> xmlResult ::: <?xml version="1.0" encoding="UTF-8"?>
> <schedule>
> <direction>ES</direction>
> </schedule>
>
> import java.util.*;
> import org.xml.sax.ContentHandler;
> import org.exolab.castor.xml.Marshaller;
> import org.exolab.castor.mapping.Mapping;
> import org.apache.xml.serialize.*;
>
> import com.cpships.vss.schedule.Schedule;
> import com.cpships.vss.domain.Port;
> import com.cpships.vss.domain.PortStop;
>
> import java.io.*;
> import java.net.*;
>
> public class Test
> {
> public static final String mappingFile = "vssmapping.xml";
>
> public void test() throws Exception{
>
> PrintWriter pw = new
> PrintWriter(System.out);
>
> Mapping castorMapping = new Mapping();
>
>
>
> URL vssMappingURL =
> getClass().getClassLoader().getResource("vssmapping.xml");
> System.out.println(" the mapping url loaded
> is "+ vssMappingURL );
>
> InputStream is =
> getClass().getClassLoader
> ().getResourceAsStream("vssmapping.xml");
> int avail = is.available();
> byte[] b = new byte[avail];
> int noRead = is.read(b);
>
> String isString = new String(b);
> System.out.println("Writing to
> System.out");
>
> pw.write(isString);
>
>
> castorMapping.loadMapping(vssMappingURL);
>
> StringWriter sw2 = new
> StringWriter();
> Marshaller marshaller = new Marshaller(sw2);
>
> marshaller.setMapping(castorMapping);
>
> Schedule schedule = new Schedule();
> schedule.setDirection("ES");
> marshaller.marshal( schedule, sw2
> );
> String xmlResult = sw2.toString();
> System.out.println( "xmlResult ::: " +
> xmlResult );
> pw.close();
> }
>
> public static void main( String[] args )
> {
> try
> {
> Test test = new Test();
> test.test();
> }
> catch ( Exception except )
> {
> except.printStackTrace( System.out );
> }
> }
> }
>
> MAPPING FILE..
>
> <?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="com.cpships.vss.schedule.Schedule">
> <map-to xml="ScheduleRenamed"/>
> <field name="direction"
> type="java.lang.String">
> <bind-xml name="dir" node="attribute"/>
> </field>
> </class>
> </mapping><?xml version="1.0"?>
>
> /* Generated by Together */
>
> package com.cpships.vss.schedule;
> import java.util.ArrayList;
> import com.cpships.vss.domain.Voyage;
> import com.cpships.vss.domain.Port;
> import com.cpships.vss.domain.PortStop;
>
> public class Schedule
> {
> private String direction = null;
>
> public Schedule()
> {
> }
>
> public void setDirection( String direction )
> {
> this.direction = direction;
> }
>
> public String getDirection()
> {
> return this.direction;
> }
> }
>
> -----Original Message-----
> From: Keith Visco [mailto:[EMAIL PROTECTED]
> Sent: Monday, September 08, 2003 6:09 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] Mapping Exception: setMapping Call not finding
> the application class.
>
> Hi Sathya,
>
> Remove the "java:" from the classname and it should work for you.
>
> --Keith
>
> "Krishnasamy, Sathya" wrote:
> >
> > Team,
> >
> > I am getting the exception on the line marked in Red. If I comment that
> > line, the marshalling works ( wothout the mapping info). But if I include
> > the mapping, I get the error.
> >
> > The class being referenced in part of an application jar file called
> > common.jar, and is available in the same dir as Test.java
> >
> > The classpath entry shows that the common.jar is set in the classpath.
> >
> > C:\Projects\cvswork\vssweb\castorTest>dir
> > Volume in drive C has no label.
> > Volume Serial Number is 8C9E-8ADB
> >
> > Directory of C:\Projects\cvswork\vssweb\castorTest
> >
> > 09/08/2003 05:26p <DIR> .
> > 09/08/2003 05:26p <DIR> ..
> > 06/03/2003 03:30p 1,141,033 castor-0.9.5-xml.jar
> > 06/03/2003 03:30p 1,613,261 castor-0.9.5.jar
> > 09/08/2003 04:49p 255 castor.properties
> > 09/08/2003 04:49p 255 castor.properties.bak
> > 09/08/2003 04:51p 24,560 common.jar
> > 09/08/2003 10:27a 2,567 Copy of vssmapping.xml
> > 07/30/2003 03:47a 445,345 dom4j.jar
> > 09/08/2003 05:25p 296 runTest.cmd
> > 09/08/2003 05:26p 150 setEnv.cmd
> > 09/08/2003 05:25p 296 setEnv.cmd.bak
> > 09/08/2003 05:26p 2,366 Test.class
> > 09/08/2003 05:13p 2,756 Test.java
> > 09/08/2003 05:12p 2,756 Test.java.bak
> > 09/08/2003 04:07p 538 vssmapping.xml
> > 09/08/2003 04:04p 538 vssmapping.xml.bak
> > 15 File(s) 3,236,972 bytes
> > 2 Dir(s) 27,528,147,456 bytes free
> >
> > C:\Projects\cvswork\vssweb\castorTest>set classpath
> > classpath =
> >
> ;./castor-0.9.5-xml.jar;./castor-0.9.5.jar;./common.jar;./dom4j.jar;c:\xmlli
> > bs\lib\crims
> > on.jar;c:\xmllibs\lib\xerces.jar;.;
> >
> > C:\Projects\cvswork\vssweb\castorTest>
> >
> > Do I need any additional configuration ?
> >
> > Help would be appreciated.
> >
> > Thanks,
> > Sathya
> >
> > org.exolab.castor.mapping.MappingException: Could not find the class
> > java:com.cpships.vss.schedule.S
> > chedule
> > at
> >
> org.exolab.castor.mapping.loader.MappingLoader.createDescriptor(MappingLoade
> > r.java:341)
> > at
> >
> org.exolab.castor.xml.XMLMappingLoader.createDescriptor(XMLMappingLoader.jav
> > a:192)
> > at
> >
> org.exolab.castor.mapping.loader.MappingLoader.loadMapping(MappingLoader.jav
> > a:233)
> > at org.exolab.castor.mapping.Mapping.getResolver(Mapping.java:291)
> > at org.exolab.castor.mapping.Mapping.getResolver(Mapping.java:246)
> > at
> org.exolab.castor.xml.Marshaller.setMapping(Marshaller.java:512)
> > at Test.test(Test.java:56)
> > at Test.main(Test.java:74)
> >
> > Test.java
> >
> > import java.util.*;
> > import org.xml.sax.ContentHandler;
> > import org.exolab.castor.xml.Marshaller;
> > import org.exolab.castor.mapping.Mapping;
> > import org.apache.xml.serialize.*;
> >
> > import com.cpships.vss.schedule.Schedule;
> > import com.cpships.vss.domain.Port;
> > import com.cpships.vss.domain.PortStop;
> >
> > import java.io.*;
> > import java.net.*;
> >
> > public class Test
> > {
> > public static final String mappingFile = "vssmapping.xml";
> >
> > public void test() throws Exception{
> >
> > System.out.println(" ............ 1 ");
> >
> > System.out.println(" ............ 2 ");
> >
> > //Mapping castorMapping = new
> > Mapping(getClass().getClassLoader());
> > Mapping castorMapping = new Mapping();
> >
> > System.out.println(" ............ 3 mapping
> > getClass().getClassLoader() is " + getClass().getClassLoader() );
> >
> > URL vssMappingURL =
> > getClass().getClassLoader().getResource("vssmapping.xml");
> > System.out.println(" the mapping url
> loaded
> > is "+ vssMappingURL );
> >
> > castorMapping.loadMapping(vssMappingURL);
> > System.out.println(" ............ 4 ");
> >
> > StringWriter sw2 = new StringWriter();
> > Marshaller marshaller = new
> > Marshaller(sw2);
> > System.out.println(" ............ 5 ");
> >
> > marshaller.setMapping(castorMapping);
> >
> > System.out.println(" ............ 6 ");
> > Schedule schedule = new Schedule();
> > schedule.setDirection("E");
> > System.out.println(" Schedule class loader
> > is " + schedule.getClass().getClassLoader());
> > System.out.println(" ............ 7 " +
> > schedule.getDirection());
> > marshaller.marshal( schedule, sw2 );
> > String xmlResult = sw2.toString();
> >
> > System.out.println( "xmlResult ::: " + xmlResult );
> > }
> >
> > public static void main( String[] args )
> > {
> > try
> > {
> > Test test = new Test();
> > test.test();
> > }
> > catch ( Exception except )
> > {
> > except.printStackTrace( System.out );
> > }
> > }
> > }
> >
> > Mapping file..
> >
> > <?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="java:com.cpships.vss.schedule.Schedule">
> > <map-to xml="Schedule"/>
> >
> > <field name="direction"
> > type="java.lang.String"
> > direct="true">
> > <bind-xml name="reference" node="attribute"/>
> > </field>
> > </class>
> >
> > </mapping>
> >
> > -----------------------------------------------------------
> > 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