Hi Matt,
We're using Morph now at Woolworths as the "Assembler" implementation in
ROO to transform between rich domain object and DTO. If I have to catch
a TransformationException (that wraps our business exception) in an MVC
controller, it means we're tied to that implementation. If for what ever
reason we swapped Dozer or a different implementation back in as the
Assembler, then the controllers break. I believe architecturally it
would be more pure not to have the Morph exceptions in client code.
Regards
Alan
Matt Sgarlata wrote:
> Hi Ben -
>
> Before adopting the change to not wrap RuntimeExceptions as
> TransformationExceptions, I would like to discuss the pros and cons of
> this change in greater detail. To me, the benefit of wrapping these
> exceptions as TransformationExceptions is that higher up the stack you
> know that an error occurred while a Morph transformation was being
> performed, as opposed to an error happening in Hibernate or some other
> library or an error happening in higher level objects that are
> directly servicing client requests (MVC controllers, Swing Actions, etc)
>
> I can understand that if you've gone to the trouble of introducing
> your own business exceptions that you want to work with those
> exceptions rather than Morph's exceptions. However, couldn't you just
> catch the MorphException and retrieve its cause with a call to
> getCause() ? Or is the issue that in a nested transformation you end
> up with your business exceptions being buried 3 or 4 exceptions deep?
> If that's the problem, I propose what we should do is change Morph so
> that it doesn't wrap its own exceptions 3 or 4 deep, or that if it
> does do so, it at least has an easy way to reference the first
> original non-Morph exception. Perhaps we could introduce a new method
> called getFirstCause or something similar.
>
> Matt S
>
> Ben Alex wrote:
>> Hi all
>>
>> Please find attached another patch.
>>
>> It fixes a bug introduced in recent changes to ContainerCopier. It was
>> the same bug we saw earlier this month, being building with Ant requires
>> casting ternary operators.
>>
>> I've also modified BaseTransformer to NOT wrap RuntimeExceptions in a
>> TransformationException. This is really critical for us. If we have a
>> mutator method throw SomeBusinessException which extends
>> RuntimeException, it's necessary that SomeBusinessException is what
>> Morph eventually returns - not wrapped in a TransformationException.
>> There's no technical need for it in the case of a RuntimeException, so
>> that attached patch provides this enhancement. I hope you agree with
>> this change.
>>
>> Cheers
>> Ben
>>
>> ------------------------------------------------------------------------
>>
>>
>> Property changes on: /home/balex/workspace/morph
>> ___________________________________________________________________
>> Name: svn:ignore
>> +
>> dist
>> target
>> build
>>
>>
>> Index: /home/balex/workspace/morph/src/core/net/sf/morph/transform/copiers/ContainerCopier.java
>> ===================================================================
>> --- /home/balex/workspace/morph/src/core/net/sf/morph/transform/copiers/ContainerCopier.java (revision 94)
>> +++ /home/balex/workspace/morph/src/core/net/sf/morph/transform/copiers/ContainerCopier.java (working copy)
>> @@ -207,7 +207,7 @@
>> // final Iterator that will be returned to the user of the
>> // ContainerCopier
>> Iterator iterator = getContainerReflector().getIterator(source);
>> - return iter ? iterator : new IteratorEnumeration(iterator);
>> + return iter ? iterator : (Object) new IteratorEnumeration(iterator);
>> }
>> return super.convertImpl(destinationClass, source, locale);
>> }
>> Index: /home/balex/workspace/morph/src/core/net/sf/morph/transform/transformers/BaseTransformer.java
>> ===================================================================
>> --- /home/balex/workspace/morph/src/core/net/sf/morph/transform/transformers/BaseTransformer.java (revision 94)
>> +++ /home/balex/workspace/morph/src/core/net/sf/morph/transform/transformers/BaseTransformer.java (working copy)
>> @@ -127,8 +127,9 @@
>> }
>> catch (TransformationException e) {
>> throw e;
>> - }
>> - catch (StackOverflowError e) {
>> + } catch (RuntimeException e) {
>> + throw (RuntimeException) e;
>> + } catch (StackOverflowError e) {
>> throw new TransformationException(
>> "Stack overflow detected. This usually occurs when a transformer implements "
>> + ObjectUtils.getObjectDescription(ExplicitTransformer.class)
>> @@ -234,8 +235,9 @@
>> }
>> catch (TransformationException e) {
>> throw e;
>> - }
>> - catch (Exception e) {
>> + } catch (RuntimeException e) {
>> + throw (RuntimeException) e;
>> + } catch (Exception e) {
>> throw new TransformationException(
>> "Could not initialize transformer "
>> + ObjectUtils.getObjectDescription(this), e);
>> @@ -296,11 +298,11 @@
>>
>> try {
>> return convertImpl(destinationClass, source, locale);
>> - }
>> - catch (TransformationException e) {
>> + } catch (TransformationException e) {
>> throw (TransformationException) e;
>> - }
>> - catch (Throwable t) {
>> + } catch (RuntimeException e) {
>> + throw (RuntimeException) e;
>> + } catch (Throwable t) {
>> if (isTransformable(destinationClass, ClassUtils.getClass(source))) {
>> throw new TransformationException(destinationClass, source, t);
>> }
>> @@ -392,8 +394,9 @@
>> }
>> catch (TransformationException e) {
>> throw e;
>> - }
>> - catch (Exception e) {
>> + } catch (RuntimeException e) {
>> + throw (RuntimeException) e;
>> + } catch (Exception e) {
>> if (isTransformable(destination.getClass(), source.getClass())) {
>> throw new TransformationException("Error copying source "
>> + ObjectUtils.getObjectDescription(source) + " to destination "
>>
>> ------------------------------------------------------------------------
>>
>> -------------------------------------------------------------------------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to share your
>> opinions on IT & business topics through brief surveys - and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> morph-developer mailing list
>> mor...@li...
>> https://lists.sourceforge.net/lists/listinfo/morph-developer
>>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> ------------------------------------------------------------------------
>
> _______________________________________________
> morph-developer mailing list
> mor...@li...
> https://lists.sourceforge.net/lists/listinfo/morph-developer
>
|