KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > builders > TransformerReference


1 /*
2  * $Id: TransformerReference.java 4259 2006-12-14 03:12:07Z aperepel $
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.config.builders;
12
13 import org.apache.commons.beanutils.BeanUtils;
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16 import org.mule.config.i18n.Message;
17 import org.mule.config.i18n.Messages;
18 import org.mule.umo.lifecycle.InitialisationException;
19 import org.mule.umo.transformer.UMOTransformer;
20 import org.mule.util.MuleObjectHelper;
21
22 /**
23  * <code>TransformerReference</code> maintains a transformer reference.
24  * Transformers are clones when they are looked up, if there are container properties
25  * set on the transformer the clone will have an inconsistent state if container
26  * properties have not been resolved. This class holds the refernece and is invoked
27  * after the container properties are resolved.
28  */

29 public class TransformerReference
30 {
31     /**
32      * logger used by this class
33      */

34     protected static final Log logger = LogFactory.getLog(TransformerReference.class);
35
36     private final String JavaDoc propertyName;
37     private final String JavaDoc transformerName;
38     private final Object JavaDoc object;
39
40     public TransformerReference(String JavaDoc propertyName, String JavaDoc transformerName, Object JavaDoc object)
41     {
42         this.propertyName = propertyName;
43         this.transformerName = transformerName;
44         this.object = object;
45     }
46
47     public String JavaDoc getPropertyName()
48     {
49         return propertyName;
50     }
51
52     public String JavaDoc getTransformerName()
53     {
54         return transformerName;
55     }
56
57     public Object JavaDoc getObject()
58     {
59         return object;
60     }
61
62     public void resolveTransformer() throws InitialisationException
63     {
64         UMOTransformer trans = null;
65         try
66         {
67             trans = MuleObjectHelper.getTransformer(transformerName, " ");
68             if (trans == null)
69             {
70                 throw new InitialisationException(new Message(Messages.X_NOT_REGISTERED_WITH_MANAGER,
71                     "Transformer '" + transformerName + "'"), object);
72             }
73             logger.info("Setting transformer: " + transformerName + " on " + object.getClass().getName()
74                         + "." + propertyName);
75
76             BeanUtils.setProperty(object, propertyName, trans);
77         }
78         catch (InitialisationException e)
79         {
80             throw e;
81         }
82         catch (Exception JavaDoc e)
83         {
84             throw new InitialisationException(new Message(Messages.CANT_SET_PROP_X_ON_X_OF_TYPE_X,
85                 propertyName, (object != null ? object.getClass().getName() : "null"), (trans != null
86                                 ? trans.getClass().getName() : "null")), e, this);
87         }
88     }
89 }
90
Popular Tags