geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject cvs commit: incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/io AbstractReplacerResolverTest.java
Date Thu, 27 May 2004 14:18:13 GMT
gdamour     2004/05/27 07:18:13

  Modified:    sandbox/messaging/src/java/org/apache/geronimo/messaging/io
                        ReplacerResolver.java AbstractReplacerResolver.java
  Added:       sandbox/messaging/src/test/org/apache/geronimo/messaging/io
                        AbstractReplacerResolverTest.java
  Log:
  Adds operations to define a ReplacerResolver as online or offline.
  This can be used to discard a ReplacerResolver from its chain.
  
  Revision  Changes    Path
  1.2       +23 -2     incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/io/ReplacerResolver.java
  
  Index: ReplacerResolver.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/io/ReplacerResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReplacerResolver.java	11 May 2004 12:06:41 -0000	1.1
  +++ ReplacerResolver.java	27 May 2004 14:18:13 -0000	1.2
  @@ -58,10 +58,31 @@
       public ReplacerResolver append(ReplacerResolver aNext);
       
       /**
  -     * Gets the next element of the chain.
  +     * Gets the next online element of the chain.
        * 
        * @return Next element.
        */
       public ReplacerResolver getNext();
  +
  +    /**
  +     * Sets this instance online.
  +     * <BR>
  +     * This instance can be added to a chain.
  +     */
  +    public void online();
  +    
  +    /**
  +     * Sets this instance offline.
  +     * <BR>
  +     * This instance does no more belong to the chain.
  +     */
  +    public void offline();
  +
  +    /**
  +     * Indicates if this instance if online.
  +     * 
  +     * @return true if online - it belongs to a chain.
  +     */
  +    public boolean isOffline();
       
   }
  
  
  
  1.2       +30 -8     incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/io/AbstractReplacerResolver.java
  
  Index: AbstractReplacerResolver.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/io/AbstractReplacerResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractReplacerResolver.java	11 May 2004 12:06:41 -0000	1.1
  +++ AbstractReplacerResolver.java	27 May 2004 14:18:13 -0000	1.2
  @@ -26,18 +26,40 @@
    */
   public abstract class AbstractReplacerResolver implements ReplacerResolver {
   
  +    private volatile boolean isOffline;
       private volatile ReplacerResolver next;
  +
  +    public void online() {
  +        isOffline = false;
  +    }
  +    
  +    public void offline() {
  +        isOffline = true;
  +    }
  +    
  +    public boolean isOffline() {
  +        return isOffline;
  +    }
       
       public ReplacerResolver append(ReplacerResolver anHandler) {
  -        if ( null != anHandler ) {
  -            anHandler.append(next);
  +        ReplacerResolver onlineNext = getNext();
  +        if ( null != onlineNext ) {
  +            onlineNext.append(anHandler);
  +        } else {
  +            next = anHandler;
           }
  -        next = anHandler;
  -        return next;
  +        return anHandler;
       }
   
       public ReplacerResolver getNext() {
  -        return next;
  +        ReplacerResolver onlineNext = next;
  +        while ( null != onlineNext && onlineNext.isOffline() ) {
  +            onlineNext = onlineNext.getNext();
  +        }
  +        if ( next != onlineNext ) {
  +            next = onlineNext;
  +        }
  +        return onlineNext;
       }
       
       public Object replaceObject(Object obj) throws IOException {
  @@ -48,7 +70,7 @@
           if ( null == next ) {
               return obj;
           }
  -        replaced = next.replaceObject(obj);
  +        replaced =  getNext().replaceObject(obj);
           if ( null != replaced ) {
               return replaced;
           }
  @@ -66,7 +88,7 @@
           if ( null == next ) {
               return obj;
           }
  -        resolved = next.resolveObject(obj);
  +        resolved = getNext().resolveObject(obj);
           if ( null != resolved ) {
               return resolved;
           }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/io/AbstractReplacerResolverTest.java
  
  Index: AbstractReplacerResolverTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.io;
  
  import java.io.IOException;
  
  import junit.framework.TestCase;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/27 14:18:13 $
   */
  public class AbstractReplacerResolverTest
      extends TestCase
  {
  
      public void testAppend() throws Exception {
          MockReplacerResolver mock1 = new MockReplacerResolver();
          MockReplacerResolver mock2 = new MockReplacerResolver();
          MockReplacerResolver mock3 = new MockReplacerResolver();
          
          mock1.append(mock2);
          mock1.append(mock3);
          
          ReplacerResolver result = mock1.getNext();
          assertEquals(mock2, result);
          result = result.getNext();
          assertEquals(mock3, result);
      }
  
      public void testOffline() throws Exception {
          MockReplacerResolver mock1 = new MockReplacerResolver();
          MockReplacerResolver mock2 = new MockReplacerResolver();
          MockReplacerResolver mock3 = new MockReplacerResolver();
          
          mock1.append(mock2);
          mock1.append(mock3);
          
          mock2.offline();
          
          ReplacerResolver result = mock1.getNext();
          assertEquals(mock3, result);
          assertTrue(mock2.isOffline());
      }
  
      public void testReplaceObject() throws Exception {
          MockReplacerResolver mock1 = new MockReplacerResolver();
          MockReplacerResolver mock2 = new MockReplacerResolver();
          MockReplacerResolver mock3 = new MockReplacerResolver();
          mock3.inputReplace = "input";
          mock3.outputReplace = "output";
          
          mock1.append(mock2);
          mock1.append(mock3);
          
          String entry = "";
          Object result = mock1.replaceObject(entry);
          assertEquals(entry, result);
  
          result = mock1.replaceObject(mock3.inputReplace);
          assertEquals(mock3.outputReplace, result);
      }
      
      public void testResolveObject() throws Exception {
          MockReplacerResolver mock1 = new MockReplacerResolver();
          MockReplacerResolver mock2 = new MockReplacerResolver();
          MockReplacerResolver mock3 = new MockReplacerResolver();
          mock3.inputResolve = "input";
          mock3.outputResolve= "output";
          
          mock1.append(mock2);
          mock1.append(mock3);
          
          String entry = "";
          Object result = mock1.resolveObject(entry);
          assertEquals(entry, result);
  
          result = mock1.resolveObject(mock3.inputResolve);
          assertEquals(mock3.outputResolve, result);
      }
      
      private static class MockReplacerResolver extends AbstractReplacerResolver {
  
          private String inputReplace;
          private String outputReplace;
          private String inputResolve;
          private String outputResolve;
          
          protected Object customReplaceObject(Object obj) throws IOException {
              if ( obj.equals(inputReplace) ) {
                  return outputReplace;
              }
              return null;
          }
  
          protected Object customResolveObject(Object obj) throws IOException {
              if ( obj.equals(inputResolve) ) {
                  return outputResolve;
              }
              return null;
          }
          
      }
      
  }
  
  
  

Mime
View raw message