KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > extras > spring > config > MuleObjectNameProcessor


1 /*
2  * $Id: MuleObjectNameProcessor.java 3798 2006-11-04 04:07:14Z 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.extras.spring.config;
12
13 import org.mule.impl.endpoint.MuleEndpoint;
14 import org.mule.umo.UMODescriptor;
15 import org.mule.umo.endpoint.UMOEndpoint;
16 import org.mule.umo.manager.UMOAgent;
17 import org.mule.umo.model.UMOModel;
18 import org.mule.umo.provider.UMOConnector;
19 import org.mule.umo.transformer.UMOTransformer;
20 import org.mule.util.MuleObjectHelper;
21 import org.springframework.beans.BeansException;
22 import org.springframework.beans.factory.config.BeanPostProcessor;
23
24 /**
25  * <code>MuleObjectNameProcessor</code> is used to set spring ids to Mule object
26  * names so the the bean id and name property on the object don't both have to be
27  * set.
28  */

29
30 public class MuleObjectNameProcessor implements BeanPostProcessor
31 {
32     private boolean overwrite = false;
33
34     public Object JavaDoc postProcessBeforeInitialization(Object JavaDoc o, String JavaDoc s) throws BeansException
35     {
36         if (!MuleObjectHelper.class.getName().equals(s))
37         {
38             if (o instanceof UMOConnector)
39             {
40                 if (((UMOConnector)o).getName() == null || overwrite)
41                 {
42                     ((UMOConnector)o).setName(s);
43                 }
44             }
45             else if (o instanceof UMOTransformer)
46             {
47                 ((UMOTransformer)o).setName(s);
48             }
49             else if (o instanceof UMOEndpoint)
50             {
51                 // spring uses the class name of the object as the name if no other
52
// id is set; this is no good for endpoints
53
if ((((UMOEndpoint)o).getName() == null || overwrite)
54                     && !MuleEndpoint.class.getName().equals(s))
55                 {
56                     ((UMOEndpoint)o).setName(s);
57                 }
58             }
59             else if (o instanceof UMODescriptor)
60             {
61                 if (((UMODescriptor)o).getName() == null || overwrite)
62                 {
63                     ((UMODescriptor)o).setName(s);
64                 }
65             }
66             else if (o instanceof UMOModel)
67             {
68                 if (((UMOModel)o).getName() == null || overwrite)
69                 {
70                     ((UMOModel)o).setName(s);
71                 }
72             }
73             else if (o instanceof UMOAgent)
74             {
75                 ((UMOAgent)o).setName(s);
76             }
77         }
78         return o;
79     }
80
81     public Object JavaDoc postProcessAfterInitialization(Object JavaDoc o, String JavaDoc s) throws BeansException
82     {
83         return o;
84     }
85
86     public boolean isOverwrite()
87     {
88         return overwrite;
89     }
90
91     public void setOverwrite(boolean overwrite)
92     {
93         this.overwrite = overwrite;
94     }
95
96 }
97
Popular Tags