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.editors;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.transport.Connector;
11  import org.mule.config.i18n.CoreMessages;
12  
13  import java.beans.PropertyEditorSupport;
14  
15  /**
16   * Translates a connector name property into the corresponding {@link org.mule.api.transport.Connector}
17   * instance.
18   *
19   * TODO - Why isn't this simply a reference?
20   */
21  public class ConnectorPropertyEditor extends PropertyEditorSupport
22  {
23      private MuleContext muleContext;
24  
25      public ConnectorPropertyEditor(MuleContext muleContext)
26      {
27          this.muleContext = muleContext;
28      }
29  
30      public void setAsText(String text)
31      {
32  
33          Connector connector = muleContext.getRegistry().lookupConnector(text);
34  
35          if (connector == null)
36          {
37              throw new IllegalArgumentException(CoreMessages.objectNotRegistered("Connector", text).getMessage());
38          }
39          setValue(connector);
40      }
41  }