Hi Abangkis,

it is not neccessary for Castor to marshal/unmarshal objects that they have been generated by Castors code generator. Apart of marshaling/unmarshalling classes generated by Castor you can also marshal/unmarshal any POJO out of the box, we call that introspection. But with introspection you do not have control over the XML. To be able to control the XML marshalled/unmarshalled there is a third mode where you need to define a mapping file that tells Castor where and how a property should apear in your XML.

The mapping approach, in theory,would be what you need to marshal the POJOs generated by Hibernate. But there is one major problem with the mapping approach: When loading objects from database Hibernate wraps them with dynamic proxis using cglib or some similar libs. This behaviour of Hibernate successfully prevents Castor from detecting the right class and marshal this objects. We have identified this problem and intend to provide a workaround in Castor but currently it is not solved.

Over all I think the best solution at the moment will be to code up some classes that convert the hierarchy of Hibernate generated classes into one of Castor generated classes.

Regards
Ralf

abangkis schrieb:
hello Werner, sorry to reply so late, I'm absent from work yesterday.

I'm currently using Castor in the scope of implementing web service using XFire and Castor. I'm sorry if i confused you with my first question.

About my first question, its more like a hibernate and Castor issue than XFire issues. As i mentioned earlier, i'm creating a webservice. I'm trying to expose my domain class to outside actor using this webservice. my approach is to create an xml schema that define my domain class structure. Currently i'm using Hibernate ORM to persist/load my domain class from the database.

Now, if i generate the java class from my schema, the generated class from castor will override my domain class, that i already generate using hibernate. What i want to know, is there anyway to let castor know, to reuse my existing class, instead of generating it.

Another approach would be generating the schema, and then manually refactoring java import to point to my hibernate class instead of castor generated files. I think this should work because both classes is POJO style. Last effort would be to create a clone method, that copy from/to each domain class.

For the second question, i totally agree with you. Thats why i called my solution a hack :) Thanks for the alternative , i really appreciate it, i've submitted a jira request for this.


On 6/19/07, * Werner Guttmann* < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Not sure about your first question, to be honest, as I don't know
    anything about xfire and how it internally makes use of Castor. But lewt
    me try to address the second question.

    The isValid() method is a convenience method to 'ask' Castor to verify
    whether a given domain class (a POJO in your speak) can be successfully
    validated. Internally, this calls the Validator class, and I honestly
    would not want to add a setter for this (convenience one-way) method, as
    it would be semantically dead wrong. What I could offer is that no such
    method be generated during code generation, but you'd have to raise a
    feature request first (as no such functionality exists right now).

    abangkis wrote:
     > Hello,
     >
     > I'm currently implementing xfire with castor in my project. my xml
     > schema look like this
     >
     > <?xml version="1.0" encoding="UTF-8"?>
     > <xs:schema targetNamespace="
    http://xfire.codehaus.org/CastorService
    <http://xfire.codehaus.org/CastorService>"
     > xmlns:tns="http://xfire.codehaus.org/CastorService"; xmlns:xs="
     > http://www.w3.org/2001/XMLSchema
    <http://www.w3.org/2001/XMLSchema>" elementFormDefault="qualified"
     > attributeFormDefault="unqualified">
     >     <xs:element name="MReunionProtocol">
     >         <xs:annotation>
     >             <xs:documentation>Comment describing your root
     > element</xs:documentation>
     >         </xs:annotation>
     >         <xs:complexType>
     >             <xs:sequence>
     >                 <xs:element name="ToR" type="xs:int"/>
     >                 <xs:element name="Messages" type="xs:string"
     > minOccurs="0" maxOccurs="unbounded"/>
     >                 <xs:element name="Data" minOccurs="0">
     >                     <xs:complexType>
     >                         <xs:choice>
     >                             <xs:element name="Contact"
     > maxOccurs="unbounded">
     >                                 <xs:complexType>
     >                                     <xs:all>
     >                                         <xs:element name="contactId"
     > type="xs:int"/>
     >                                         <xs:element name="User">
     >                                             <xs:complexType>
     >                                                 <xs:all>
     >                                                     <xs:element
     > name="userId" type="xs:int"/>
     >                                                     <xs:element
     > name="userProfile" type="xs:string"/>
     >                                                 </xs:all>
     >                                             </xs:complexType>
     >                                         </xs:element>
     >                                         <xs:element name="firstName"
     > type="xs:string"/>
     >                                         <xs:element name="lastName"
     > type="xs:string"/>
     >                                     </xs:all>
     >                                 </xs:complexType>
     >                             </xs:element>
     >                             <xs:element name="SynchRequest">
     >                                 <xs:complexType>
     >                                     <xs:sequence>
     >                                         <xs:element name="Contact"
     > maxOccurs="unbounded">
     >                                             <xs:complexType>
     >                                                 <xs:all>
     >                                                     <xs:element
     > name="contactId" type="xs:int"/>
     >                                                     <xs:element
    name="User">
> <xs:complexType>
     >                                                             <xs:all>
     >
     > <xs:element name="userId" type="xs:int"/>
     >
     > <xs:element name="userProfile" type="xs:string"/>
     >                                                             </xs:all>
> </xs:complexType>
     >                                                     </xs:element>
     >                                                     <xs:element
     > name="firstName" type="xs:string"/>
     >                                                     <xs:element
     > name="lastName" type="xs:string"/>
     >                                                 </xs:all>
     >                                             </xs:complexType>
     >                                         </xs:element>
     >                                     </xs:sequence>
     >                                 </xs:complexType>
     >                             </xs:element>
     >                         </xs:choice>
     >                     </xs:complexType>
     >                 </xs:element>
     >                 <xs:element name="Version" type="xs:string"/>
     >             </xs:sequence>
     >         </xs:complexType>
     >     </xs:element>
     > </xs:schema>
     >
     > and i use Castor to generate the java class.
     >
     > My first problem is, the Contact element from my schema is a
    hibernate
     > generated POJO class. How can i make generated class to use this
    class,
     > instead generating a new contact class?
     >
     > My second problem is Castor generated an isValid() method for
    each java
     > class. Somehow xfire need both getter/setter for each property of a
     > class. I've managed to hack this by creating a setValid(boolean
    valid)
     > for each class. I was wondering whether there any other way i can
    avoid
     > this without have to manually add setValid method for each class.
     >
     >
     > Thanks in Advance
     > - abangkis -


    ---------------------------------------------------------------------
    To unsubscribe from this list please visit:

         http://xircles.codehaus.org/manage_email



--

Syscon Ingenieurbüro für Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
72127 Kusterdingen
Germany

Tel.   +49 7071 3690 52
Mobil: +49 173 9630135
Fax    +49 7071 3690 98

Internet: www.syscon.eu
E-Mail: [EMAIL PROTECTED]

Sitz der Gesellschaft: D-72127 Kusterdingen
Registereintrag: Amtsgericht Stuttgart, HRB 382295
Geschäftsleitung: Jens Joachim, Ralf Joachim

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to