Not to bug you, just wondering if this was fixed..
Thanks,
- Tim
-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]
Sent: Monday, November 01, 2004 4:51 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-user] XML: Un/Marshalling java.util.Locale objects
Tim Mulle' wrote:
>
> Keith,
>
> It says it right here:
> http://www.castor.org/xml-mapping.html#3.4-The-%3Cfield%3E-element the
> last item in the table says type="locale" is supported as a field type.
Hmmmm, how odd, I never saw that before. I think it's a side-effect from
when the xml-mapping documentation was for both JDO and XML. Anyway, you're
right, it's right there plain as day. So given that fact, I think I better
get it working! :-)
I'll create a LocaleDescriptor and get it checked into CVS.
--Keith
> If you look down in my earlier post, I had already tried what you
> suggested about the Locale mapping and it never seemed to create the
> locale objects when unmarshalling from the XML..It wrote it out just
> fine.. I did have to use the "verify-constructable" attribute on the
> Locale mapping becuase of the missing default constructor..but it
> still didn't make a difference. I've tried both the latest version and
> 0.9.5.3 and still the same thing..
>
> I looked in the source code for Castor and I noticed that the TypeInfo
> class has a mapping for "java.util.Locale.class"
>
> Thanks,
> - Tim
>
>
>
> Keith Visco wrote:
>
>>
>>
>> Hi Tim,
>>
>> Can you point to me in the docs where it says Locale has built-in
>> support. It might be the case with Castor-JDO, but not with Castor-XML.
>>
>> Castor XML has no built-in support for it.
>>
>> In order to get Locale to work, you'll need a mapping file and
>> specify the country and language values as attributes (since there is
>> no default constructor the values need to be mapped as attributes in
>> order to be passed to the constructor). Something like the following
>> should work:
>>
>> <class name="java.util.Locale">
>> <field name="language" type="string"
>> get-method="getLanguage" set-method="%1">
>> <bind-xml node="attribute"/>
>> </field>
>> <field name="country" type="string"
>> set-method="%2" get-method="getCountry">
>> <bind-xml node="attribute"/>
>> </field>
>> </class>
>>
>> --Keith
>>
>>
>> Tim Mulle' wrote:
>>
>>> Anyone have any ideas about this?
>>> -----Original Message-----
>>> From: Tim Mulle' [mailto:[EMAIL PROTECTED] Sent: Wednesday,
>>> October 27, 2004 1:51 PM
>>> To: [EMAIL PROTECTED]
>>> Subject: Re: [castor-user] XML: Un/Marshalling java.util.Locale
>>> objects
>>>
>>> Update:
>>> I tried the same code but using java.awt.Color objects as well as my
>>> own, and they seem to work meaning I get back the objects from the
>>> XML.
>>> For some
>>> reason, nothing I do makes the java.util.Locale object come back.
>>> Could it
>>> be a bug in the TypeInfo classes? I noticed in the docs that "locale"
>>> is a
>>> built-in supported type.
>>>
>>>
>>> -----Original Message-----
>>> From: Tim Mulle' [mailto:[EMAIL PROTECTED]
>>> Sent: Wednesday, October 27, 2004 11:23 AM
>>> To: [EMAIL PROTECTED]
>>> Subject: [castor-user] XML: Un/Marshalling java.util.Locale objects
>>>
>>>
>>> Hi,
>>>
>>> I'm wondering, is it possible to marshall/unmarshall
>>> java.util.Locale objects? I know they don't follow the JavaBean
>>> pattern in that they Follow more of the Enum pattern (only providing
>>> getters and can only be constructed with constructor params). With
>>> that being said, I tried the following code and mappings and while
>>> the marshalling appears to write the data out, when unmarshalling
>>> the object back in, I always get null. Almost like the Locale object
>>> is never being created and added to the collection. I saw a similar
>>> posting about the java.awt.Color object but never saw a solution either.
>>>
>>> If I print out the Config object before marshalling, I see the
>>> Locale objects in the list, after I unmarshal the object back My
>>> list is empty..
>>>
>>> // Output
>>> Before unmarshalling:AdminConfig{locales=[en_US, fr_FR]} After
>>> unmarshalling: AdminConfig{locales=[]}
>>>
>>>
>>> // Mapping file
>>> <mapping>
>>> <class name="AdminConfig">
>>> <map-to xml="admin-config"/>
>>>
>>> <field name="locales" type="java.util.Locale"
>>> collection="collection">
>>> <bind-xml name="locale" location="locales"/>
>>> </field>
>>> </class>
>>>
>>> <!-- Map a Locale object -->
>>> <class name="java.util.Locale" verify-constructable="false">
>>> <field name="language" set-method="%1" type="string">
>>> <bind-xml node="attribute"/>
>>> </field>
>>> <field name="country" set-method="%2" type="string">
>>> <bind-xml node="attribute"/>
>>> </field>
>>> </class>
>>> </mapping>
>>>
>>>
>>> My config object looks like this:
>>>
>>> Public class AdminConfig {
>>>
>>> private List locales = new ArrayList();
>>> public void setLocales(List locales) {
>>> this.locales = locales;
>>> }
>>> public List getLocales() {
>>> return locales;
>>> }
>>>
>>> public String toString() {
>>> final StringBuffer buf = new StringBuffer();
>>> buf.append("AdminConfig");
>>> buf.append("{locales=").append(locales);
>>> buf.append('}');
>>> return buf.toString();
>>> }
>>> }
>>>
>>> Public class Test {
>>>
>>> public static void main(String[] args) {
>>>
>>> AdminConfig cfg = new AdminConfig();
>>> List locales = new ArrayList();
>>> locales.add(new Locale("en", "US"));
>>> locales.add(new Locale("fr", "FR"));
>>>
>>> cfg.setLocale(locales);
>>> ....
>>> // Marshall object
>>> }
>>> }
>>> Resulting XML file...
>>>
>>> <?xml version="1.0" encoding="UTF-8"?> <admin-config>
>>> <locales>
>>> <locale name="en" value="US"/>
>>> <locale name="fr" value="FR"/>
>>> </locales>
>>> </cas-admin>
>>>
>>>
>>> - Tim Mull�
>>>
>>>
>>>
>>>
>>>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user