You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ha...@apache.org on 2002/03/05 17:30:17 UTC

cvs commit: jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/socket SocketObjectStreamFactoryHelper.java

hammant     02/03/05 08:30:17

  Added:       altrmi/src/java/org/apache/commons/altrmi/client
                        AltrmiInterfaceLookupFactory.java
               altrmi/src/java/org/apache/commons/altrmi/client/impl
                        AbstractFactoryHelper.java
                        AbstractInterfaceLookupFactory.java
                        DefaultInterfaceLookupFactory.java
               altrmi/src/java/org/apache/commons/altrmi/client/impl/socket
                        SocketObjectStreamFactoryHelper.java
  Removed:     altrmi/src/java/org/apache/commons/altrmi/client
                        AltrmiFactoryFactory.java
  Log:
  Start of work on String based lookup mechanism.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/AltrmiInterfaceLookupFactory.java
  
  Index: AltrmiInterfaceLookupFactory.java
  ===================================================================
  package org.apache.commons.altrmi.client;
  
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  
  /**
   * Interface AltrmiInterfaceLookupFactory
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface AltrmiInterfaceLookupFactory {
  
      /**
       * Method getAltrmiInterfaceLookup
       *
       * FactoryStrings as listed here should look like this:
       *
       *   "SocketObjectStream:abcde.com:1234:S:BO"
       *   "SocketCustomStream:abcde.com:1235:C:NBO"
       *   "RMI:abcde.com:1236:S:NBO"
       *
       *   S:BO and alike is
       *    - "S" for server side proxy classes
       *    - "C" for client side proxy classes
       *    - "BO" is BeanOnly (not castable to the interface)
       *    - "NBO" is NotBeanOnly (castable to the interface)
       *
       * @param factoryString
       *
       * @return
       *
       */
      AltrmiInterfaceLookup getAltrmiInterfaceLookup(String factoryString) throws AltrmiConnectionException;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/AbstractFactoryHelper.java
  
  Index: AbstractFactoryHelper.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.altrmi.client.impl;
  
  
  
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.client.AltrmiInterfaceLookupFactory;
  
  import java.util.Vector;
  import java.util.StringTokenizer;
  
  
  /**
   * Class AbstractFactoryHelper
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AbstractFactoryHelper implements AltrmiInterfaceLookupFactory {
  
      protected String[] processFactoryString(String factoryString) {
  
          Vector terms = new Vector();
          StringTokenizer st = new StringTokenizer(factoryString, ":");
  
          while (st.hasMoreTokens()) {
              terms.add(st.nextToken());
          }
  
          String[] retval = new String[terms.size()];
  
          terms.copyInto(retval);
  
          return retval;
      }
  
      protected AltrmiFactory createAltrmiFactory(String type, boolean beanOnly) {
  
          if (type.equalsIgnoreCase("s")) {
              return new ServerClassAltrmiFactory(beanOnly);
          } else if (type.equalsIgnoreCase("c")) {
              return new ClientClassAltrmiFactory(beanOnly);
          } else {
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/AbstractInterfaceLookupFactory.java
  
  Index: AbstractInterfaceLookupFactory.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.altrmi.client.impl;
  
  
  
  import org.apache.commons.altrmi.client.AltrmiInterfaceLookupFactory;
  import org.apache.commons.altrmi.client.AltrmiInterfaceLookup;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  import java.util.Vector;
  
  
  /**
   * Class AbstractInterfaceLookupFactory
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AbstractInterfaceLookupFactory implements AltrmiInterfaceLookupFactory {
  
      private Vector factories = new Vector();
  
      protected void addFactory(String factoryStringPrefix, AltrmiInterfaceLookupFactory factory) {
          factories.add(new Factory(factoryStringPrefix, factory));
      }
  
      /**
       * Method getAltrmiInterfaceLookup
       *
       *
       * @param factoryString
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      public AltrmiInterfaceLookup getAltrmiInterfaceLookup(String factoryString)
              throws AltrmiConnectionException {
  
          for (int i = 0; i < factories.size(); i++) {
              Factory factory = (Factory) factories.elementAt(i);
  
              if (factoryString.startsWith(factory.factoryStringPrefix)) {
                  return factory.altrmiInterfaceLookupFactory
                      .getAltrmiInterfaceLookup(factoryString);
              }
          }
  
          return null;
      }
  
      /**
       * Class Factory
       *
       *
       * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
       * @version $Revision: 1.1 $
       */
      private class Factory {
  
          private String factoryStringPrefix;
          private AltrmiInterfaceLookupFactory altrmiInterfaceLookupFactory;
  
          /**
           * Constructor Factory
           *
           *
           * @param factoryStringPrefix
           * @param altrmiInterfaceLookupFactory
           *
           */
          public Factory(String factoryStringPrefix,
                         AltrmiInterfaceLookupFactory altrmiInterfaceLookupFactory) {
              this.factoryStringPrefix = factoryStringPrefix;
              this.altrmiInterfaceLookupFactory = altrmiInterfaceLookupFactory;
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/DefaultInterfaceLookupFactory.java
  
  Index: DefaultInterfaceLookupFactory.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.altrmi.client.impl;
  
  
  
  import org.apache.commons.altrmi.client.impl.socket.SocketObjectStreamFactoryHelper;
  
  
  /**
   * Class DefaultInterfaceLookupFactory
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class DefaultInterfaceLookupFactory extends AbstractInterfaceLookupFactory {
  
      /**
       * Constructor DefaultInterfaceLookupFactory
       *
       *
       */
      public DefaultInterfaceLookupFactory() {
  
          addFactory("SocketObjectStream:", new SocketObjectStreamFactoryHelper());
  
          // TODO - add the rest.
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/socket/SocketObjectStreamFactoryHelper.java
  
  Index: SocketObjectStreamFactoryHelper.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.commons.altrmi.client.impl.socket;
  
  
  
  import org.apache.commons.altrmi.client.impl.AbstractFactoryHelper;
  import org.apache.commons.altrmi.client.AltrmiInterfaceLookup;
  import org.apache.commons.altrmi.client.AltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  import java.io.IOException;
  
  
  /**
   * Class SocketObjectStreamFactoryHelper
   *
   *   "SocketObjectStream:abcde.com:1234"
   *            0         :  1      : 2
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class SocketObjectStreamFactoryHelper extends AbstractFactoryHelper {
  
      /**
       * Method getFactory
       *
       *
       * @param factoryString
       *
       * @return
       *
       */
      public AltrmiInterfaceLookup getAltrmiInterfaceLookup(String factoryString)
              throws AltrmiConnectionException {
  
          // TODO maybe we should cache these.  Or the abstract parent class should.
  
          String[] terms = processFactoryString(factoryString);
          AltrmiHostContext hc = new SocketObjectStreamHostContext(terms[1],
                                                                   Integer.parseInt(terms[2]));
          AltrmiFactory af = createAltrmiFactory(terms[3], terms[4].equalsIgnoreCase("bo"));
  
          try {
              af.setHostContext(hc);
          } catch (IOException e) {
              throw new AltrmiConnectionException("IO Exception during connection: "
                                                  + e.getMessage());
          }
  
          return af;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>