/**
   * Creates an uninitialied connector from the provided MuleEndpointURI. The scheme is used to
   * determine what kind of connector to create. Any params set on the uri can be used to initialise
   * bean properties on the created connector.
   *
   * <p>Note that the initalise method will need to be called on the connector returned. This is so
   * that developers can control when the connector initialisation takes place as this is likely to
   * initialse all connecotr resources.
   *
   * @param url the MuleEndpointURI url to create the connector with
   * @return a new Connector
   * @throws TransportFactoryException
   */
  public Connector createConnector(EndpointURI url) throws TransportFactoryException {

    try {
      Connector connector;
      String scheme = url.getFullScheme();

      TransportServiceDescriptor sd =
          (TransportServiceDescriptor)
              muleContext
                  .getRegistry()
                  .lookupServiceDescriptor(ServiceType.TRANSPORT, scheme, null);
      if (sd == null) {
        throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
      }

      connector = sd.createConnector();
      if (connector != null) {
        if (connector instanceof AbstractConnector) {
          ((AbstractConnector) connector).initialiseFromUrl(url);
        }
      } else {
        throw new TransportFactoryException(
            CoreMessages.objectNotSetInService("Connector", scheme));
      }

      connector.setName(new ObjectNameHelper(muleContext).getConnectorName(connector));

      return connector;
    } catch (Exception e) {
      throw new TransportFactoryException(
          CoreMessages.failedToCreateObjectWith("Endpoint", url), e);
    }
  }
  /** Returns an initialized connector. */
  public Connector getOrCreateConnectorByProtocol(EndpointURI uri)
      throws TransportFactoryException {
    String connectorName = uri.getConnectorName();
    if (null != connectorName) {
      // TODO this lookup fails currently on Mule 2.x! MuleAdminAgentTestCase
      Connector connector = muleContext.getRegistry().lookupConnector(connectorName);
      if (connector != null) {
        return connector;
      }
    }

    Connector connector = getConnectorByProtocol(uri.getFullScheme());
    if (connector == null) {
      connector = createConnector(uri);
      try {
        BeanUtils.populate(connector, uri.getParams());
        muleContext.getRegistry().registerConnector(connector);
      } catch (Exception e) {
        throw new TransportFactoryException(e);
      }
    }
    return connector;
  }