View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.processors;
8   
9   import org.mule.api.agent.Agent;
10  import org.mule.api.model.Model;
11  import org.mule.api.service.Service;
12  import org.mule.api.transformer.Transformer;
13  import org.mule.api.transport.Connector;
14  
15  import org.springframework.beans.BeansException;
16  import org.springframework.beans.factory.config.BeanPostProcessor;
17  
18  /**
19   * <code>MuleObjectNameProcessor</code> is used to set spring ids to Mule object
20   * names so the the bean id and name property on the object don't both have to be
21   * set.
22   */
23  
24  public class MuleObjectNameProcessor implements BeanPostProcessor
25  {
26      private boolean overwrite = false;
27  
28      public Object postProcessBeforeInitialization(Object o, String s) throws BeansException
29      {
30  
31          if (o instanceof Connector)
32          {
33              if (((Connector)o).getName() == null || overwrite)
34              {
35                  ((Connector)o).setName(s);
36              }
37          }
38          else if (o instanceof Transformer)
39          {
40              if (((Transformer)o).getName() == null || overwrite)
41              {
42                 ((Transformer)o).setName(s);
43              }
44          }
45          else if (o instanceof Service)
46          {
47              if (((Service)o).getName() == null || overwrite)
48              {
49                  ((Service)o).setName(s);
50              }
51          }
52          else if (o instanceof Model)
53          {
54              if (((Model)o).getName() == null || overwrite)
55              {
56                  ((Model)o).setName(s);
57              }
58          }
59          else if (o instanceof Agent)
60          {
61              ((Agent)o).setName(s);
62          }
63          return o;
64      }
65  
66      public Object postProcessAfterInitialization(Object o, String s) throws BeansException
67      {
68          return o;
69      }
70  
71      public boolean isOverwrite()
72      {
73          return overwrite;
74      }
75  
76      public void setOverwrite(boolean overwrite)
77      {
78          this.overwrite = overwrite;
79      }
80  
81  }