Re: [morph-user] Some questions and a Map copy problem
Brought to you by:
orangeherbert,
sgarlatm
|
From: Matt S. <Mat...@wh...> - 2007-01-26 22:15:46
|
Hi Bruce, unfortunately the ZIP you sent me did not contain the full
stack trace. The file is there, but its size is 0.
Matt
Bruce Lombardi wrote:
>
> Hi Matt,
>
>
>
> A while back I wrote to you and asked about making a copy where all
> the fields that were to be copied were not put in a map, but rather
> only the fields to be translated were supplied and the rest were
> copied without translation. I'm now starting to implement the approach
> you suggested for doing that in number 1 below, but I'm getting an
> error. The main error is shown below:
>
>
>
> net.sf.morph.transform.TransformationException: Failed to copy
> property 'maker' of "Audi" (class java.lang.String) to property
> 'manufacturer' of
>
> at
> net.sf.morph.transform.copiers.PropertyNameMappingCopier.copyImpl(PropertyNameMappingCopier.java:143)
>
>
>
> I'm trying to copy a DAO to a VO and translate Maker to Manufacture.
> Both properties exist and have manufacturers. I have attached a zip
> file with a complete error trace, both beans, the copyUtil class that
> is trying to do the copy and the CopyTest that is running the test.
> I'm using the morph-1.0.2.jar, which is something you put together for
> me to solve a different problem (the one copying maps I think).
>
>
>
> Any help you can give would be appreciated.
>
>
>
> -- Bruce
>
>
>
>
>
> -----Original Message-----
> *From:* Matt Sgarlata [mailto:Mat...@wh...]
> *Sent:* Friday, October 13, 2006 10:35 AM
> *To:* blo...@no...
> *Subject:* Re: Some questions and a Map copy problem
>
>
>
> Hi Bruce, here are some answers for you:
>
> 1) When using the PropertyNameMappingCopier you have to specify all
> field names that you would like copied. You could always
> programmatically retrieve the list of property names that are the same
> between both objects (for example, using Morph.getPropertyNames),
> construct the map, and then change the Map to account for the
> 2) You can use the PropertyNameMappingCopier for this purpose, because
> it only copies the fields that you explicitly mention in the Map. You
> can also use the PropertyNameMatchingCopier and set its fieldsToCopy
> property to only those fields you would like copied.
> 3) It's hard to tell what's going on in your stack trace, because the
> cause of the transformation error has been "lost" in your output. If
> you look at BaseTransformer:414 you have
>
> throw new TransformationException("Error copying source "
> + ObjectUtils.getObjectDescription(source) + "
> to destination "
> +
> ObjectUtils.getObjectDescription(destination), e);
>
> So the base exception is included in the TransformationException, and
> that is what usually will tell you what's going wrong. I'm not seeing
> the nested exception in the stack trace. Are you doing any type of
> exception catching in CopyUtil? That could be what is suppressing the
> full stack trace output.
>
> Matt
>
> Bruce Lombardi wrote:
>
> Matt,
>
>
>
>
>
> I have a few questions on Morph:
>
>
>
> 1. I know that if I need to translate from names on one bean to
> different names on another bean, I can supply a Map with the
> translations (e.g., in your example you translate "addresses" to
> "primaryAddress" by setting up a PropertyNameMappingCopier.) My
> question is: do you have to supply a Map with all the fields names to
> be copied, or only those that need to be translated to another name?
>
> 2. A related question. If I want to copy from one bean to
> another, but I only want to copy one or two fields, can I somehow
> supply the names of those fields and limit the copy to those? (maybe
> in a map like above, but with only the name of the fields to copy).
>
> 3. Finally, I am getting the following error when attempting to
> copy from one object to another. Each object has the following methods:
>
>
>
> public Map getLineItems();
>
> public void setLineItems(Map lineItems);
>
>
>
>
>
> SimpleDelegatingTransformer@11eb9b11 (class
> net.sf.morph.transform.transformers.SimpleDelegatingTransformer)
>
> [10/12/06 18:36:28:258 EDT] 00000037 MyPropertyNam I Copying
> properties lineItemData and lineItems
>
> [10/12/06 18:36:28:274 EDT] 00000037 MapReflector W The
> net.sf.morph.reflect.reflectors.MapReflector@7327db10 (class
> net.sf.morph.reflect.reflectors.MapReflector) is set to EXTRACT_VALUES
> so com.comcore.product.order.LineItemVO@13f05b11 (class
> com.comcore.product.order.LineItemVO) will be added to the Map with a
> null key
>
> [10/12/06 18:36:28:274 EDT] 00000037 SystemOut O I am here
>
> [10/12/06 18:36:28:274 EDT] 00000037 SystemErr R
> net.sf.morph.transform.TransformationException: Error copying source
> {1=com.comcore.product.order.LineItemVO@13f05b11,
> 2=com.comcore.product.order.LineItemVO@10935b11,
> 3=com.comcore.product.order.LineItemVO@10c81b11} (class
> java.util.Collections$SynchronizedMap) to destination
> {1=com.comcore.product.order.LineItemVO@fdc1b37,
> 2=com.comcore.product.order.LineItemVO@6ef5b37,
> 3=com.comcore.product.order.LineItemVO@6241b37} (class
> java.util.Collections$SynchronizedMap)
>
> at
> net.sf.morph.transform.transformers.BaseTransformer.copy(BaseTransformer.java:414)
>
> at
> net.sf.morph.transform.transformers.SimpleDelegatingTransformer.copyImpl(SimpleDelegatingTransformer.java:201)
>
> at
> net.sf.morph.transform.transformers.BaseTransformer.copy(BaseTransformer.java:407)
>
> at
> net.sf.morph.util.TransformerUtils.transform(TransformerUtils.java:163)
>
> at
> net.sf.morph.transform.copiers.BasePropertyNameCopier.copyProperty(BasePropertyNameCopier.java:122)
>
> at
> net.sf.morph.transform.copiers.PropertyNameMatchingCopier.copyImpl(PropertyNameMatchingCopier.java:91)
>
> at
> net.sf.morph.transform.transformers.BaseTransformer.copy(BaseTransformer.java:407)
>
> at
> net.sf.morph.transform.transformers.SimpleDelegatingTransformer.copyImpl(SimpleDelegatingTransformer.java:201)
>
> at
> net.sf.morph.transform.transformers.BaseTransformer.copy(BaseTransformer.java:407)
>
> at
> net.sf.morph.transform.transformers.BaseTransformer.copy(BaseTransformer.java:429)
>
> at CopyUtil.copy(CopyUtil.java:64)
>
> at
> com.checkout.actions.ShoppingCartAction.processOutput(ShoppingCartAction.java:76)
>
>
>
>
>
>
>
>
>
|