users@jaxb.java.net

Re: Issues with arbitrary transformation of boolean to String

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Wed, 23 Sep 2009 19:56:01 +0200

I think what you need is

<jxb:bindings
node="/xsd:schema/xsd:element[@name='Foo']/xsd:complexType/xsd:attribute[@name='bar']">
  <jxb:property>
    <jxb:baseType>
      <jxb:javaType name="java.lang.String"
           parseMethod="com.Transform.parse01ToString"
           printMethod="com.Transform.printStringTo01" />
    </jxb:baseType>
  </jxb:property>
</jxb:bindings>

which converts "0" or "1" in the XML to whatever the com.Transform decides:

package com;
import java.util.*;
public class Transform {
    private static String ouiChar;
    private static String nonChar;
    public static void setOuiNon( String oui, String non ){
        ouiChar = oui;
        nonChar = non;
    }
    public static String parse01ToString( String value ){
        return value.equals( "0" ) ? nonChar : ouiChar;
    }
    public static String printStringTo01( String impl ){
        return impl.equals( ouiChar ) ? "1" : "0";
    }
}

All you have to do, is call the static method to define the "oui" or "non"
character.

Although I don't see why the application cannot handle the "0" or "1".
Whatever.

-W






On Wed, Sep 23, 2009 at 6:29 PM, Ioannis Mavroukakis <
imavroukakis_at_gameaccount.com> wrote:

> I should also add, that on top of that, I need to be able to pass at
> runtime an XMLAdapter that will override this functionality,
> so that String 0 or 1 can be mapped to any other textual representation :-/
>
> Y.
>
> On 23 Sep 2009, at 17:27, Ioannis Mavroukakis wrote:
>
> No the XML will be a String 0 or 1, but what I want to transform it to, is
> String S or N respectively :-)
>
> Thanks!
>
> Yiannis
>
> On 23 Sep 2009, at 17:15, Wolfgang Laun wrote:
>
> If the XML is a single letter, then parse must convert from string to
> boolean, print vice versa. And the javaType name is java.lang.Boolean.
>
> -W
>
>
> On Wed, Sep 23, 2009 at 4:51 PM, Ioannis Mavroukakis <
> imavroukakis_at_gameaccount.com> wrote:
>
>> Hello fellow listers,
>>
>> I've got the following conundrum I'd like some help with.
>>
>> Assume this schema (shortened for brevity)
>>
>> <xs:element name="Foo">
>> <xs:complexType>
>> <xs:complexContent>
>> <xs:attribute name="bar" type="xs:string"/>
>> </xs:complexContent>
>> </xs:complexType>
>> </xs:element>
>>
>> In reality, bar is a boolean attribute (stay with me) which I need for
>> business reasons to convert to a single character lexical
>> equivalent of true/false in another language, for transport over a WSDL
>> call.
>>
>> I thought that I could perhaps use a custom binding to do my biding and
>> extend that for different use cases hence
>>
>> <bindings
>> node="/xsd:schema/xsd:element[@name='Foo']/xsd:complexType/xsd:complexContent/xsd:attribute[@name='bar']">
>> <property>
>> <baseType>
>> <javaType name="java.lang.String"
>>
>> parseMethod="com.transform.PartnerTransform.parseBooleanToString"
>>
>> printMethod="com.transform.PartnerTransform.printStringToBoolean" />
>> </baseType>
>> </property>
>> </bindings>
>>
>> However I quickly realised that my cunning plan to assign another
>> XMLAdapter while initialising the marshaller for each use case was blown out
>> of the water
>> as the adapter is randomly named by xjc, and touching the generated
>> classes is a no-no.
>>
>> Therefore, the grand question here is , is there some arcane way to make
>> jaxb do that, or should I be looking at a different solution?
>>
>> Thanks!
>>
>> Yiannis
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
>
>
>