Re: [morph-user] morph (dis-)assemble - howto?
Brought to you by:
orangeherbert,
sgarlatm
|
From: Matt B. <gud...@ya...> - 2009-10-08 15:06:35
|
Please use the mailing list, such as it is, for help.
For this situation, though it might technically be categorized as an assembly/disassembly situation, I would consider it to be a little awkward to do it that way in practice. I could suggest two ways to do this:
A. Define a PropertyMappingCopier of SourceClass to DestinationClass, mapping 'docType' to 'this'. Then define a PropertyMappingCopier of DocType to DestinationClass, mapping 'id' to 'docTypeId' and 'name' to 'docTypeName'.
B. Use a PropertyExpressionMappingCopier to map 'docType.id' to 'docTypeId' and 'docType.name' to 'docTypeName'.
If you also need basic property matching with either of these approaches, remember that CumulativeCopier is a big help for multi-pronged transformations.
HTH,
Matt B
--- On Thu, 10/8/09, Han...@co... <Han...@co...> wrote:
> From: Han...@co... <Han...@co...>
> Subject: morph (dis-)assemble - howto?
> To: gud...@ya..., sga...@li...
> Date: Thursday, October 8, 2009, 9:18 AM
>
>
> Hello all,
>
> I use the morph framework
> for a web
> project and I'm facing the following mapping
> challenge:
>
>
>
> SourceClass
>
>
> ...
>
>
> private
> DocType docType;
>
>
> ...
>
>
>
> Destination
> Class
>
>
> ...
>
>
> private
> String docTypeId
>
>
> private
> String docTypeName
>
>
>
>
>
> Class
> DocType
>
>
> private
> long id;
>
>
> private
> String name;
>
>
>
> (each class with
> corresponding getters/setters)
>
>
>
> We've set up
> transforming like this:
>
>
> SimpleDelegatingTransformer
> suche2form = new SimpleDelegatingTransformer();
>
>
> suche2FormComponents.add(new
> EcmStringConverter()); // own
> converter
>
>
> suche2FormComponents.add(new
> EcmDateToStringConverter()); // own
> converter
>
>
> suche2FormComponents.add(new
> NumberToTextConverter());
>
>
> suche2FormComponents.add(new
> BooleanToTextConverter());
>
>
> suche2FormComponents.add(new
> ContainerCopier());
>
>
> suche2FormComponents.add(new
> PropertyNameMatchingCopier());
>
> Object[]
> suche2FormComponentsA
> = (Object[])suche2FormComponents.toArray(new
> Object[suche2FormComponents.size()]);
>
>
>
> suche2form.setComponents(suche2FormComponentsA);
>
>
>
>
> suche2form.copy(result,source);
>
>
> System.out.println(result.getDocTypeName());
>
>
> System.out.println(result.getDocTypeId());
>
>
> System.out.println(result.getDocType());
>
>
>
> --> Question: How can
> we disassemble
> sourceclass.docType into destinationClass.docTypeId and
> docTypeName properties
> and vice versa (assemble docTypeId / docTypeName into
> docType)?
>
> --> Are there any
> samples available
> about the net.sf.morph.transform.copiers.DisassemblerCopier
> / net.sf.morph.transform.copiers.AssemblerCopier
> ?
>
>
>
> Thanks &
> regards,
>
> Hansjörg
>
>
>
>
>
>
> Cortal Consors S.A.
> Zweigniederlassung Deutschland, Bahnhofstraße 55, D-90402
> Nürnberg, HR Nürnberg B 20075, USt-IdNr. DE225900761
>
>
>
> Sitz der Cortal Consors S.A.: 1, boulevard Haussmann,
> F-75318 Paris cedex 09, Registergericht: R.C.S. Paris 327
> 787 909
>
> Président du Conseil d'Administration
> (Verwaltungsratsvorsitzender) und Directeur Général
> (Generaldirektor) der Cortal Consors S.A.: Olivier Le Grand
>
> Leitung der Zweigniederlassung Deutschland: Martin Daut
> (CEO Deutschland), Olivier Le Grand, Richard Döppmann,
> Pascal Grundrich
>
>
>
> Before printing, think about environmental
> responsibility!
>
> Bitte denken Sie
> über Ihre Verantwortung gegenüber der Umwelt nach, bevor
> Sie diese E-Mail ausdrucken.
|