zoukankan      html  css  js  c++  java
  • 企业搜索引擎开发之连接器connector(十三)

    本文分析一下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

  • 相关阅读:
    Seam的安全框架授权(Authorization)(译) (三)
    Seam的安全框架授权(Authorization)(译) (一)
    Seam的安全框架错误信息(Error Messages)(译)
    如何编出健壮的代码,java编程30条规则(转)
    Seam的安全框架身份管理(Identity Management)(译)
    Seam的安全框架授权(Authorization)(译) (二)
    集成Seam,Spring和jBPM指南(译)
    拖拉是种病,不治会要命!(转)
    Jboss Seam, mysql中文乱码问题4步骤总结(转)
    ubuntu上的mysql字符集设置(转)
  • 原文地址:https://www.cnblogs.com/chenying99/p/2970354.html
Copyright © 2011-2022 走看看