KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transformers > AbstractEventAwareTransformer


1 /*
2  * $Id: AbstractEventAwareTransformer.java 3982 2006-11-22 14:28:01Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.transformers;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.impl.RequestContext;
16 import org.mule.umo.UMOEventContext;
17 import org.mule.umo.transformer.TransformerException;
18
19 /**
20  * <code>AbstractEventAwareTransformer</code> is a transformer that has a reference
21  * to the current message. This message can be used obtains properties associated
22  * with the current message useful to the transform. Note that when part of a
23  * transform chain, the Message payload reflects the pre-transform message state,
24  * unless there is no current event for this thread, then the message will be a new
25  * MuleMessage with the src as its payload. Transformers should always work on the
26  * src object not the message payload.
27  *
28  * @see org.mule.umo.UMOMessage
29  * @see org.mule.impl.MuleMessage
30  */

31
32 public abstract class AbstractEventAwareTransformer extends AbstractTransformer
33 {
34     public final Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
35     {
36         UMOEventContext event = RequestContext.getEventContext();
37         if (event == null && requiresCurrentEvent())
38         {
39             throw new TransformerException(new Message(Messages.NO_CURRENT_EVENT_FOR_TRANSFORMER), this);
40         }
41         return transform(src, encoding, event);
42     }
43
44     public abstract Object JavaDoc transform(Object JavaDoc src, String JavaDoc encoding, UMOEventContext context)
45         throws TransformerException;
46
47     protected boolean requiresCurrentEvent()
48     {
49         return true;
50     }
51 }
52
Popular Tags