pnever      2003/10/10 04:31:28

  Modified:    src/share/org/apache/slide/structure ObjectNode.java
  Added:       src/share/org/apache/slide/common UriPath.java
  Log:
  Extracted inner class UriPath from ObjectNode
  
  Revision  Changes    Path
  1.1                  jakarta-slide/src/share/org/apache/slide/common/UriPath.java
  
  Index: UriPath.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/UriPath.java,v 
1.1 2003/10/10 11:31:28 pnever Exp $
   * $Revision: 1.1 $
   * $Date: 2003/10/10 11:31:28 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Slide", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.slide.common;
  
  import java.util.StringTokenizer;
  
  /**
   * An URI path.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Nevermann</a>
   * @version $Revision: 1.1 $
   */
  public final class UriPath {
      
      private String[] tokens;
      
      private UriPath() {
      }
      
      private UriPath(String[] tokens) {
          this.tokens = tokens;
      }
      
      public UriPath(String uri) {
          StringTokenizer t = new StringTokenizer( uri, "/" );
          this.tokens = new String[t.countTokens()];
          for (int i = 0; t.hasMoreTokens(); i++) {
              tokens[i] = t.nextToken();
          }
      }
      
      public String[] tokens() {
          return tokens;
      }
      
      public String lastSegment() {
          return tokens.length > 0
              ? tokens[ tokens.length - 1 ]
              : null;
      }
      
      public UriPath parent() {
          if (this.tokens.length == 0) {
              return null;
          }
          UriPath result = new UriPath();
          result.tokens = new String[this.tokens.length - 1];
          for (int i = 0; i < result.tokens.length; i++) {
              result.tokens[i] = this.tokens[i];
          }
          return result;
      }
      
      public UriPath child( String segment ) {
          String[] ctokens = new String[tokens.length + 1];
          for (int i = 0; i < tokens.length; i++) {
              ctokens[i] = tokens[i];
          }
          ctokens[tokens.length] = segment;
          return new UriPath(ctokens);
      }
      
      public boolean equals(Object o) {
          boolean result = false;
          if (o instanceof UriPath) {
              UriPath other = (UriPath)o;
              if (other.tokens.length == this.tokens.length) {
                  result = true;
                  for (int i = 0; i < this.tokens.length; i++) {
                      if (!other.tokens[i].equals(this.tokens[i])) {
                          result = false;
                          break;
                      }
                  }
              }
          }
          return result;
      }
      
      public String toString() {
          if (tokens.length > 0) {
              StringBuffer b = new StringBuffer();
              for (int i = 0; i < tokens.length; i++) {
                  b.append("/").append(tokens[i]);
              }
              return b.toString();
          }
          else {
              return "/";
          }
      }
  }
  
  
  
  1.16      +22 -57    
jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java
  
  Index: ObjectNode.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ObjectNode.java   16 Sep 2003 19:04:22 -0000      1.15
  +++ ObjectNode.java   10 Oct 2003 11:31:28 -0000      1.16
  @@ -65,9 +65,9 @@
   
   import java.io.Serializable;
   import java.util.Enumeration;
  -import java.util.StringTokenizer;
   import java.util.Vector;
   import org.apache.slide.common.ObjectValidationFailedException;
  +import org.apache.slide.common.UriPath;
   import org.apache.slide.util.Messages;
   
   /**
  @@ -124,6 +124,8 @@
       
       private Vector childrenCache = null;
       
  +    private UriPath path = null;
  +    
       /**
        * Default constructor.
        */
  @@ -459,7 +461,7 @@
        * @param    child               an ObjectNode
        */
       public void addChild( ObjectNode child ) {
  -        addBinding( child.lastUriSegment(), child );
  +        addBinding( child.getPath().lastSegment(), child );
       }
       
       /**
  @@ -507,6 +509,18 @@
       }
       
       /**
  +     * Get the path of this object node.
  +     *
  +     * @return   an UriPath
  +     */
  +    public UriPath getPath() {
  +        if (path == null) {
  +            path = new UriPath(getUri());
  +        }
  +        return path;
  +    }
  +    
  +    /**
        * Get the last segment of the specified uri.
        *
        * @param    uri                 a  String
  @@ -514,11 +528,7 @@
        * @return   a String
        *
        */
  -    String lastUriSegment() {
  -        return lastUriSegment(this.uri);
  -    }
  -    
  -    String lastUriSegment( String uri ) {
  +    private String lastUriSegment( String uri ) {
           return new UriPath(uri).lastSegment();
       }
   
  @@ -557,7 +567,7 @@
               p = new SubjectNode( pUri );
               p.setUuri( p.getUri() );
           }
  -        addParentBinding( lastUriSegment(), p );
  +        addParentBinding( getPath().lastSegment(), p );
       }
       
       public void addParentBinding( String bindingName, ObjectNode parent ) {
  @@ -747,50 +757,5 @@
               return container.size();
           }
       }
  -    
  -    public static class UriPath {
  -        private String[] tokens;
  -        
  -        private UriPath() {
  -        }
  -        
  -        public UriPath(String uri) {
  -            StringTokenizer t = new StringTokenizer( uri, "/" );
  -            this.tokens = new String[t.countTokens()];
  -            for (int i = 0; t.hasMoreTokens(); i++) {
  -                tokens[i] = t.nextToken();
  -            }
           }
           
  -        public String lastSegment() {
  -            return tokens.length > 0
  -                ? tokens[ tokens.length - 1 ]
  -                : null;
  -        }
  -        
  -        public UriPath parent() {
  -            if (this.tokens.length == 0) {
  -                return null;
  -            }
  -            UriPath result = new UriPath();
  -            result.tokens = new String[this.tokens.length - 1];
  -            for (int i = 0; i < result.tokens.length; i++) {
  -                result.tokens[i] = this.tokens[i];
  -            }
  -            return result;
  -        }
  -        
  -        public String toString() {
  -            if (tokens.length > 0) {
  -                StringBuffer b = new StringBuffer();
  -                for (int i = 0; i < tokens.length; i++) {
  -                    b.append("/").append(tokens[i]);
  -                }
  -                return b.toString();
  -            }
  -            else {
  -                return "/";
  -            }
  -        }
  -    }
  -}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to