Return-Path: X-Original-To: apmail-tuscany-user-archive@www.apache.org Delivered-To: apmail-tuscany-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5AF2BDAB5 for ; Wed, 15 May 2013 10:29:36 +0000 (UTC) Received: (qmail 71753 invoked by uid 500); 15 May 2013 10:29:36 -0000 Delivered-To: apmail-tuscany-user-archive@tuscany.apache.org Received: (qmail 71451 invoked by uid 500); 15 May 2013 10:29:34 -0000 Mailing-List: contact user-help@tuscany.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@tuscany.apache.org Delivered-To: mailing list user@tuscany.apache.org Received: (qmail 71422 invoked by uid 99); 15 May 2013 10:29:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 May 2013 10:29:33 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sebastian.millies@ids-scheer.com designates 193.26.194.27 as permitted sender) Received: from [193.26.194.27] (HELO server3.software-ag.de) (193.26.194.27) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 May 2013 10:29:29 +0000 Received: from server3.software-ag.de (localhost [127.0.0.1]) by localhost.software-ag.de (Postfix) with ESMTP id 8AD7914164 for ; Wed, 15 May 2013 12:29:06 +0200 (CEST) Received: from hqcas.eur.ad.sag (hqcas2.eur.ad.sag [10.20.40.42]) by server3.software-ag.de (Postfix) with ESMTPS id 7F1F9141A5 for ; Wed, 15 May 2013 12:29:06 +0200 (CEST) Received: from HQMBX5.eur.ad.sag ([fe80::d1b:bd0:4196:e9]) by HQCAS2.eur.ad.sag ([fe80::55b0:31d0:71f2:112a%13]) with mapi id 14.03.0123.003; Wed, 15 May 2013 12:28:45 +0200 From: "Millies, Sebastian" To: "user@tuscany.apache.org" Subject: RE: JAXBHelperContext, the POJO/SDO bridge for Tuscany SDO Thread-Topic: JAXBHelperContext, the POJO/SDO bridge for Tuscany SDO Thread-Index: Ac5RLEus5Pc08bdXTZuHWp2IoiE+TAAGsIOgAAOOcaA= Date: Wed, 15 May 2013 10:28:44 +0000 Message-ID: <32F15738E8E5524DA4F01A0FA4A8E490C2F6DBB5@HQMBX5.eur.ad.sag> References: <41F0201FD66F5443892576011E84E4CF0138DA043D@INHYMS110B.ca.com> In-Reply-To: <41F0201FD66F5443892576011E84E4CF0138DA043D@INHYMS110B.ca.com> Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.30.11.143] Content-Type: multipart/alternative; boundary="_000_32F15738E8E5524DA4F01A0FA4A8E490C2F6DBB5HQMBX5euradsag_" MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org --_000_32F15738E8E5524DA4F01A0FA4A8E490C2F6DBB5HQMBX5euradsag_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello Raman, I think there's nothing out of the box for Tuscany SDOs. I did experiment w= ith Pojo/SDO-conversion a while back based on the Eclipse example you cite. I use a common base class Pojo for all the pojos and customize my jaxb bind= ings with a annotation in bindings.xjb. This base class contains toXML() and fromXML() methods implemented in the usual JAXB way. A PojoSDOBridge for Tuscany then can be implemented like this: /** * Convert an SDO to a bean via the shared XML representation. *

* Implementation note: Does not depend on EclipseLink JAXBContextHelper,= only on standard JAXB. * @param sdo * @return the bean of the corresponding type * @throws JAXBException * @throws ClassNotFoundException */ public static Pojo toPojo( DataObject sdo ) throws JAXBException, ClassNo= tFoundException { SDOHelper helper =3D SDOHelperFactory.getHelper(); String xml =3D helper.toXML( sdo, null ); Class clazz =3D Pojo.load( sdo.getType().getURI(), sdo.= getType().getName() ); Pojo bean =3D Pojo.fromXML( xml, clazz ); return bean; } /** * Convert a bean to an SDO via the shared XML representation. *

* Implementation note: Does not depend on EclipseLink JAXBContextHelper,= only on Tuscany's SDO implementation. * @param bean * @return the SDO of the corresponding type * @throws JAXBException * @throws ClassNotFoundException */ public static DataObject toSDO( Pojo bean ) throws JAXBException, ClassNo= tFoundException { String xml =3D bean.toXML(); // The generated XML contains an xsi:type element, so the XML can be un= marshalled to an SDO of that type XMLHelper xmlHelper =3D HelperProvider.getDefaultContext().getXMLHelper= (); XMLDocument xmlDoc =3D xmlHelper.load( xml ); DataObject sdo =3D xmlDoc.getRootObject(); return sdo; } For loading the pojo class, one must find the FQCN corresponding to the giv= en type and namespace. That can be a challenge. XJC does it, but I haven't had time to figure out how exactly. I came up wi= th a simplification that works in most cases. I'd be grateful for a better suggestion: /** * Constructs the fully qualified class name corresponding to the given t= ype's namespace and name. *

* Intended as an analogue to what xjc does. * @param namespace must be a valid HTTP-URL. Used to contruct the packag= e name. * @param typeName the simple name of a type belonging to the namespace. = Corresponds to the simple class name. * @return the fully qualified class name */ // TODO find a utility library that does EXACTLY the same as XJC, even fo= r arbitrary URL's. private static final String fullyQualifiedClassName( String namespace, St= ring typeName ) { URL url; try { url =3D new URL( namespace ); } catch( MalformedURLException e ) { throw new IllegalStateException( "Namespace must be a valid URL", e )= ; } if( !url.getProtocol().equals( "http" ) ) { throw new IllegalArgumentException( "Namespace must be an HTTP-URL, n= ot " + url ); } String packagePrefix =3D join( reverse( url.getHost().split( "\\." ) ),= '.' ); String packageSuffix =3D url.getPath().replaceAll( "/", "." ); String className =3D packagePrefix + packageSuffix + "." + typeName; return className; } Hope that gets you started. Perhaps something like this would be worth incl= uding in a Tuscany utility class? Best Regards, Sebastian From: Malisetti, Ramanjaneyulu [mailto:Ramanjaneyulu.Malisetti@ca.com] Sent: Wednesday, May 15, 2013 10:35 AM To: user@tuscany.apache.org Subject: JAXBHelperContext, the POJO/SDO bridge for Tuscany SDO Hi, Is there POJO/SDO bridge for Tuscany SDO API like one discussed at = http://wiki.eclipse.org/EclipseLink/Examples/SDO/JAXB. We use SDO as data model for services, but some people have problem with de= aling dynamic DataObjects. So, I am looking for conversion from static Data= Object to dynamic DataObject or POJO to SDO. Regards Raman Software AG - Sitz/Registered office: Uhlandstra?e 12, 64297 Darmstadt, Ger= many - Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/M= anagement Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram = Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Superviso= ry Board: Dr. Andreas Bereczky - http://www.softwareag.com --_000_32F15738E8E5524DA4F01A0FA4A8E490C2F6DBB5HQMBX5euradsag_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello Raman,

 

I think there’s= nothing out of the box for Tuscany SDOs. I did experiment with Pojo/SDO-co= nversion a while back based on the Eclipse example you cite.

I use a common base c= lass Pojo for all the pojos and customize my jaxb bindings with a <xjc:s= uperclass> annotation in bindings.xjb. This base class

contains toXML() and = fromXML() methods implemented in the usual JAXB way.

 

A PojoSDOBridge for T= uscany then can be implemented like this:

 

/**

   * Conver= t an SDO to a bean via the shared XML representation.

   * <p&= gt;

   * Implem= entation note: Does not depend on EclipseLink JAXBContextHelper, only on st= andard JAXB.

   * @param= sdo

   * @retur= n the bean of the corresponding type

   * @throw= s JAXBException

   * @throw= s ClassNotFoundException

   */

  public static = Pojo toPojo( DataObject sdo ) throws JAXBException, ClassNotFoundException<= /span>

  {

    SD= OHelper helper =3D SDOHelperFactory.getHelper();

    St= ring xml =3D helper.toXML( sdo, null );

 

    Cl= ass<? extends Pojo> clazz =3D Pojo.load( sdo.getType().getURI(), sdo.= getType().getName() );

    Po= jo bean =3D Pojo.fromXML( xml, clazz );

    re= turn bean;

  }

 

  /**

   * Conver= t a bean to an SDO via the shared XML representation.

   * <p&= gt;

   * Implem= entation note: Does not depend on EclipseLink JAXBContextHelper, only on Tu= scany's SDO implementation.

   * @param= bean

   * @retur= n the SDO of the corresponding type

   * @throw= s JAXBException

   * @throw= s ClassNotFoundException

   */

  public static = DataObject toSDO( Pojo bean ) throws JAXBException, ClassNotFoundException<= /span>

  {

    St= ring xml =3D bean.toXML();

 

    //= The generated XML contains an xsi:type element, so the XML can be unmarsha= lled to an SDO of that type

    XM= LHelper xmlHelper =3D HelperProvider.getDefaultContext().getXMLHelper();

    XM= LDocument xmlDoc =3D xmlHelper.load( xml );

    Da= taObject sdo =3D xmlDoc.getRootObject();

 

    re= turn sdo;

  }

 

For loading the pojo = class, one must find the FQCN corresponding to the given type and namespace= . That can be a challenge.

XJC does it, but I ha= ven’t had time to figure out how exactly. I came up with a simplifica= tion that works in most cases. I’d be

grateful for a better= suggestion:

 

/**

   * Constr= ucts the fully qualified class name corresponding to the given type's names= pace and name.

   * <p&= gt;

   * Intend= ed as an analogue to what xjc does.

   * @param= namespace must be a valid HTTP-URL. Used to contruct the package name.

   * @param= typeName the simple name of a type belonging to the namespace. Corresponds= to the simple class name.

   * @retur= n the fully qualified class name

   */

  // TODO find a= utility library that does EXACTLY the same as XJC, even for arbitrary URL'= s.

  private static= final String fullyQualifiedClassName( String namespace, String typeName )<= /span>

  {

    UR= L url;

    tr= y {

   &nb= sp;  url =3D new URL( namespace );

    }<= /span>

    ca= tch( MalformedURLException e ) {

   &nb= sp;  throw new IllegalStateException( "Namespace must be a valid = URL", e );

    }<= /span>

 

    if= ( !url.getProtocol().equals( "http" ) ) {

   &nb= sp;  throw new IllegalArgumentException( "Namespace must be an HT= TP-URL, not " + url );

    }<= /span>

 

    St= ring packagePrefix =3D join( reverse( url.getHost().split( "\\." = ) ), '.' );

    St= ring packageSuffix =3D url.getPath().replaceAll( "/", ".&quo= t; );

    St= ring className =3D packagePrefix + packageSuffix + "." &#= 43; typeName;

 

    re= turn className;

  }

 

Hope that gets you st= arted. Perhaps something like this would be worth including in a Tuscany ut= ility class?

 

Best Regards,<= /p>

Sebastian

 

From: Malise= tti, Ramanjaneyulu [mailto:Ramanjaneyulu.Malisetti@ca.com]
Sent: Wednesday
, May 15, 2013 10:35 = AM
To: user@tuscany.apache.org
Subject: JAXBHelperContext, the POJO/SDO bridge for Tuscany SDO

 

Hi,

        Is there = POJO/SDO bridge for Tuscany SDO API like one discussed at http://wi= ki.eclipse.org/EclipseLink/Examples/SDO/JAXB.

 

We use SDO as data model for services, but some peop= le have problem with dealing dynamic DataObjects. So, I am looking for conv= ersion from static DataObject to dynamic DataObject or POJO to SDO.

 

Regards

Raman


Software AG – Sitz= /Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany –= Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Managem= ent Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram Jost, Arn= d Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board:= Dr. Andreas Bereczky - http://www.softwareag.com

--_000_32F15738E8E5524DA4F01A0FA4A8E490C2F6DBB5HQMBX5euradsag_--