View Javadoc

1   /*
2    * $Id: MetaTransportServiceDescriptor.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  package org.mule.transport.service;
11  
12  import org.mule.api.registry.ServiceException;
13  import org.mule.api.registry.ServiceType;
14  import org.mule.api.transport.Connector;
15  import org.mule.config.i18n.CoreMessages;
16  import org.mule.transport.AbstractConnector;
17  import org.mule.util.PropertiesUtils;
18  import org.mule.util.SpiUtils;
19  
20  import java.util.Properties;
21  
22  /**
23   * Used to describe a Meta transport, one which only defines an endpoint, not a connector, receiver, dispatcher, etc
24   *
25   * @since 3.0.0
26   */
27  public class MetaTransportServiceDescriptor extends DefaultTransportServiceDescriptor
28  {
29      private String metaScheme;
30  
31      public MetaTransportServiceDescriptor(String metaScheme, String scheme, Properties props, ClassLoader classLoader) throws ServiceException
32      {
33          super(metaScheme, props, classLoader);
34          this.metaScheme = metaScheme;
35          Properties p = SpiUtils.findServiceDescriptor(ServiceType.TRANSPORT, scheme);
36          //Load any overrides for the for the endpoint scheme
37          if (p == null)
38          {
39              throw new ServiceException(CoreMessages.failedToCreate("transport: " + metaScheme + ":" + scheme));
40          }
41          Properties temp = new Properties();
42          PropertiesUtils.getPropertiesWithPrefix(props, scheme + ".", temp);
43          if (temp.size() > 0)
44          {
45              p.putAll(PropertiesUtils.removeNamespaces(temp));
46          }
47          setOverrides(p);
48      }
49  
50      /**
51       * Override the connector cration and register our Meta scheme with the connecotr so that the connector can
52       * be used when creating endpoints using this meta transport
53       *
54       * @return a transport connector matching the scheme of the descriptor with the meta scheme registered with the
55       *         connector
56       * @throws TransportServiceException if the connector cannot be created
57       */
58      @Override
59      public Connector createConnector() throws TransportServiceException
60      {
61          AbstractConnector c = (AbstractConnector) super.createConnector();
62          c.registerSupportedMetaProtocol(metaScheme);
63          return c;
64      }
65  }