Thanks Tim, finally I got it to work

>> It's possible you are having to different classloaders loading the
class and mapping file.
You were right!

I changed the way that I was instantiating map to this:

Mapping map =  new Mapping( getClass().getClassLoader() );
 
And it seemes to be working. 

Thanks again


-----Original Message-----
From: Tim Mulle [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 09, 2005 5:20 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 

Correction,

We prefix our getResourceAsStream and getResource with
Thread.currentThread().getContextClassLoader().

Which is the preferred way to load classes from the classpath because of
the way the classloaders work inside of a web/application container.

It's possible you are having to different classloaders loading the class
and mapping file.



-----Original Message-----
From: Tim Mulle [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 5:14 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 

That should be fine..

We use the following code and it works for us:

URL url = getClass().getClassLoader().getResource("UserMapping.xml");
map.loadMapping (URLDecoder.decode(url.getPath()));

This way we load the mapping file from the classpath using the URL so we
can actually write back to the file later on. If you use the URL class,
we found that we have to URLDecode the path because if the path has
directories with spaces they get URL encoded automatically.

If you don't need to know where the file came from you can use:

InputStream url =
getClass().getClassLoader().getResourceAsStream("UserMapping.xml");
map.loadMapping (url);

And that will load the mapping file from the classpath as well along
with our other classes


Hope this helps...


-----Original Message-----
From: Ali Emami [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 5:04 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 


Yes, I'm sure. 
The only thing is that my packaging is a war file so my classes is under


../WEB-INF/classes/com/x/y/z/

 rather than being in a jar file


-----Original Message-----
From: Tim Mulle [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 4:55 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 

And you are sure your User class is in the classpath?
 

-----Original Message-----
From: Ali Emami [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 4:52 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 

I also tried that, the same error message I have:

URL url = getClass().getClassLoader().getResource("com/x/y/z/");
map.setBaseURL(url.toString());

map.loadMapping ("UserMapping.xml");
//this works and load the xml file 

In my mapping xml I have
<class name="com.x.y.z.User" auto-complete="true">

And it gives me error
org.exolab.castor.mapping.MappingException: Could not find the class
com.x.y.z.User

It's very frustrating! 

I appreciate any help 

thanks



 

-----Original Message-----
From: Tim Mulle [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 4:45 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 

You have to specify the fully qualified name of your User class.. i.e
com.mypackage.User

Unless your User class isn't in any package..

- Tim
 

-----Original Message-----
From: Ali Emami [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 3:49 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 

Now, after loading the mapping file it cannot find the class !!

org.exolab.castor.mapping.MappingException: Could not find the class
User ...


<mapping>
  <description>Basic mapping example</description>

  <class name="User" auto-complete="true">

    <map-to xml="user_info"/>
        .
        .
        .
  </class>
</mapping>

Any idea?

Thanks A LOT

-----Original Message-----
From: Ali Emami [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 3:27 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 


Thanks Jacky! 

This is how it works in case anyone else needed to use loadMapping

        map.loadMapping (
getClass().getClassLoader().getResource("com/x/y/z/UserMapping.xml")); 


-----Original Message-----
From: Jacky Lu [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 3:17 PM
To: [email protected]
Subject: RE: [castor-user] loadMapping does not fine the mapping file 

The getResource() method in Class might be what you want.

--Jacky

> -----Original Message-----
> From: Ali Emami [mailto:[EMAIL PROTECTED]
> Sent: Thursday, June 09, 2005 3:10 PM
> To: [email protected]; Bruce Snyder
> Subject: [castor-user] loadMapping does not fine the mapping file
> 
> 
> Hi All
> I'm trying to mashal a java object using a map file, My mapfile is 
> UserMapping.xml and its in a X.jar and the jar file is in 
> WEB-INF\classes\com\x\y\z\UserMapping.xml
> But
> Every time I use 
>         map.loadMapping("com/fwp/snap/user/UserMapping.xml");
>       or
>         map.loadMapping("UserMapping.xml");
> 
> I get FileNotFoundException!!! 
> 
> Can you help me with this? THANKS A LOT
> 
> 
> 
> -------------------------------------------------
> If you wish to unsubscribe from this list, please send an empty 
> message to the following address:
> 
> [EMAIL PROTECTED]
> -------------------------------------------------
> 
> 

-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message
to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to