君子博学而日参省乎己 则知明而行无过矣

博客园 首页 新随笔 联系 订阅 管理

本文分析一下ConnectorInterfaces类的代码,该类主要提供了访问连接器的相关依赖类的一下方法,供ConnectorCoordinatorImpl类调用,其源码如下:

/**
 * Access to the AuthenticationManager, AuthorizationManager, and
 * TraversalManagager for a Connector instance.
 */
public class ConnectorInterfaces {

  private final String connectorName;
  private final Connector connector;

  // these are lazily constructed
  private TraversalManager traversalManager;
  private AuthenticationManager authenticationManager;
  private AuthorizationManager authorizationManager;

  ConnectorInterfaces(String connectorName, Connector connector) {
    this.connectorName = connectorName;
    this.connector = connector;
  }

  /**
   * Constructs a ConnectorIntefaces with Managers supplied by the caller
   * rather than the connector. This is for testing only.
   */
  ConnectorInterfaces(String connectorName, TraversalManager traversalManager,
                      AuthenticationManager authenticationManager,
                      AuthorizationManager authorizationManager) {
    this.connectorName = connectorName;
    this.connector = null;
    this.traversalManager = traversalManager;
    this.authenticationManager = authenticationManager;
    this.authorizationManager = authorizationManager;
  }

  /**
   * @return the authenticationManager
   * @throws InstantiatorException
   */
  AuthenticationManager getAuthenticationManager() throws InstantiatorException {
    if (authenticationManager == null) {
      Session s = getSession();
      try {
        authenticationManager = s.getAuthenticationManager();
      } catch (RepositoryException e) {
        // TODO(ziff): think about how this could be re-tried
        throw new InstantiatorException(e);
      } catch (Exception e) {
        throw new InstantiatorException(e);
      }
    }
    return authenticationManager;
  }

  /**
   * @return the authorizationManager
   * @throws InstantiatorException
   */
  AuthorizationManager getAuthorizationManager() throws InstantiatorException {
    if (authorizationManager == null) {
      Session s = getSession();
      try {
        authorizationManager = s.getAuthorizationManager();
      } catch (RepositoryException e) {
        // TODO(ziff): think about how this could be re-tried
        throw new InstantiatorException(e);
      } catch (Exception e) {
        throw new InstantiatorException(e);
      }
    }
    return authorizationManager;
  }

  /**
   * @return the connector
   */
  // TODO(strellis) Remove this method or make it private so all connector
  // access is through InstanceInfo.
  Connector getConnector() {
    return connector;
  }

  /**
   * @return the connectorName
   */
  String getConnectorName() {
    return connectorName;
  }

  /**
   * @return the traverser
   * @throws InstantiatorException
   */
  TraversalManager getTraversalManager() throws InstantiatorException {
    if (traversalManager == null) {
      Session s = getSession();
      try {
        traversalManager = s.getTraversalManager();
      } catch (RepositoryException ie) {
        throw new InstantiatorException(ie);
      } catch (Exception e) {
        throw new InstantiatorException(e);
      }
    }
    return traversalManager;
  }

  private Session getSession() throws InstantiatorException {
    Session s = null;
    try {
      s = connector.login();
    } catch (RepositoryLoginException e) {
      // this is un-recoverable
      throw new InstantiatorException(e);
    } catch (RepositoryException e) {
      // for this one, we could try again later
      // TODO(ziff): think about how this could be re-tried
      throw new InstantiatorException(e);
    } catch (Exception e) {
      throw new InstantiatorException(e);
    }
    return s;
  }

}

 可以看到,连接器的相关TraversalManager对象是通过这里获取的,该类源码容易读懂,我不解释了

本系列企业搜索引擎开发之连接器connector系本人原创

转载请注明出处 博客园 刺猬的温驯

本文链接http://www.cnblogs.com/chenying99/archive/2013/03/20/2970354.html

posted on 2013-03-20 00:33  刺猬的温驯  阅读(323)  评论(0编辑  收藏  举报