View Javadoc

1   /*
2    * $Id: MuleObjectNameProcessor.java 11311 2008-03-10 20:15:57Z dfeist $
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 CPAL v1.0
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.spring.processors;
12  
13  import org.mule.api.agent.Agent;
14  import org.mule.api.model.Model;
15  import org.mule.api.service.Service;
16  import org.mule.api.transformer.Transformer;
17  import org.mule.api.transport.Connector;
18  
19  import org.springframework.beans.BeansException;
20  import org.springframework.beans.factory.config.BeanPostProcessor;
21  
22  /**
23   * <code>MuleObjectNameProcessor</code> is used to set spring ids to Mule object
24   * names so the the bean id and name property on the object don't both have to be
25   * set.
26   */
27  
28  public class MuleObjectNameProcessor implements BeanPostProcessor
29  {
30      private boolean overwrite = false;
31  
32      public Object postProcessBeforeInitialization(Object o, String s) throws BeansException
33      {
34  
35          if (o instanceof Connector)
36          {
37              if (((Connector)o).getName() == null || overwrite)
38              {
39                  ((Connector)o).setName(s);
40              }
41          }
42          else if (o instanceof Transformer)
43          {
44              if (((Transformer)o).getName() == null || overwrite)
45              {
46                 ((Transformer)o).setName(s);
47              }
48          }
49          else if (o instanceof Service)
50          {
51              if (((Service)o).getName() == null || overwrite)
52              {
53                  ((Service)o).setName(s);
54              }
55          }
56          else if (o instanceof Model)
57          {
58              if (((Model)o).getName() == null || overwrite)
59              {
60                  ((Model)o).setName(s);
61              }
62          }
63          else if (o instanceof Agent)
64          {
65              ((Agent)o).setName(s);
66          }
67          return o;
68      }
69  
70      public Object postProcessAfterInitialization(Object o, String s) throws BeansException
71      {
72          return o;
73      }
74  
75      public boolean isOverwrite()
76      {
77          return overwrite;
78      }
79  
80      public void setOverwrite(boolean overwrite)
81      {
82          this.overwrite = overwrite;
83      }
84  
85  }