/* Copyright (c) 2005 Ricebridge. All Rights Reserved.
 *
 * This file is available under the terms and conditions of the
 * Ricebridge "Open Source API" policy; Ricebridge grants use of this
 * copyrighted work under the terms of a BSD-style license only. See
 * http://www.opensource.org/licenses/bsd-license.php for more
 * information.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *  - Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 *  - 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.
 *
 *  - Neither the name of the Ricebridge nor the names of its
 *  contributors may be used to endorse or promote products derived
 *  from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS 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
 * COPYRIGHT OWNER OR 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.  
 */

package com.ricebridge.xmlman.in.test;

import com.ricebridge.xmlman.in.OutPath;
import com.ricebridge.xmlman.in.OutData;

import org.jostraca.util.ListUtil;

import java.util.*;


/** A subclass of {@link OutPath} used for testing.
 *    <p>The <b><a href="TestOutPath.java.html">Source Code</a></b> of this Java class 
 *    is available under a <a href="http://www.opensource.org/licenses/bsd-license.php">BSD-style license</a>.</p>
 */
public class TestOutPath extends OutPath {

  // private instance
  private List    iPartList   = null;
  private int     iPartIndex  = 0;
  private Part    iPart       = null;
  private boolean iIsRecord   = false;
  private boolean iIsAbsolute = false;
  private OutData iOutData    = null;



  // constructors

  public TestOutPath( OutData pOutData, boolean pIsAbsolute ) {
    this( pOutData, pIsAbsolute, ListUtil.make() );
  }

  public TestOutPath( OutData pOutData, boolean pIsAbsolute, String pName0, int pType0 ) {
    this( pOutData, pIsAbsolute, ListUtil.make( new Part(pName0,pType0,1) ) );
  }

  public TestOutPath( OutData pOutData, boolean pIsAbsolute, 
                      String pName0, int pType0,
                      String pName1, int pType1 ) {
    this( pOutData, pIsAbsolute, ListUtil.make( new Part(pName0,pType0,1),
                                                new Part(pName1,pType1,1) ) );
  }

  public TestOutPath( OutData pOutData, boolean pIsAbsolute, 
                      String pName0, int pType0,
                      String pName1, int pType1,
                      String pName2, int pType2 ) {
    this( pOutData, pIsAbsolute, ListUtil.make( new Part(pName0,pType0,1),
                                                new Part(pName1,pType1,1),
                                                new Part(pName2,pType2,1) ) );
  }

  public TestOutPath( OutData pOutData, boolean pIsAbsolute, 
                      String pName0, int pType0,
                      String pName1, int pType1,
                      String pName2, int pType2,
                      String pName3, int pType3 ) {
    this( pOutData, pIsAbsolute, ListUtil.make( new Part(pName0,pType0,1),
                                                new Part(pName1,pType1,1),
                                                new Part(pName2,pType2,1),
                                                new Part(pName3,pType3,1) ) );
  }



  public TestOutPath( OutData pOutData, boolean pIsAbsolute, List pPartList ) {
    iOutData    = pOutData;
    iIsAbsolute = pIsAbsolute;
    iPartList   = pPartList;
  }


  // public methods

  public boolean nextPart() {
    if( iPartIndex >= iPartList.size() ) {
      iPartIndex = 0;
      return false;
    }
    else {
      iPart = (Part) iPartList.get( iPartIndex );
      iPartIndex++;
      return true;
    }
  }

  public String getPartName() {
    return iPart.iName;
  }

  public int getPartType() {
    return iPart.iType;
  }

  public int getPartPosition() {
    return iPart.iPostion;
  }

  public String getPartName(int pPartIndex) {
    return ((Part)iPartList.get(pPartIndex)).iName;
  }

  public int getPartType(int pPartIndex) {
    return ((Part)iPartList.get(pPartIndex)).iType;
  }

  public int getPartPosition(int pPartIndex) {
    return ((Part)iPartList.get(pPartIndex)).iPostion;
  }


  public int getNumParts() {
    return iPartList.size();
  }

  public boolean isRecord() {
    return iIsRecord;
  }

  public boolean isAbsolute() {
    return iIsAbsolute;
  }

  public OutData getOutData() {
    return iOutData;
  }


  public void setIsRecord( boolean pIsRecord ) {
    iIsRecord = pIsRecord;
  }

  public void setIsAbsolute( boolean pIsAbsolute ) {
    iIsAbsolute = pIsAbsolute;
  }

  
  public String toString() {
    StringBuffer sb = new StringBuffer();
    if( !iIsAbsolute ) {
      sb.append(".");
    }
    for( Iterator pI = iPartList.iterator(); pI.hasNext(); ) {
      Part p = (Part) pI.next();
      sb.append( p );
    }
    sb.append( iOutData );
    return sb.toString();
  }


  public static class Part {
    String iName;
    int    iType;
    int    iPostion;
    public Part( String pName, int pType, int pPosition ) {
      iName = pName;
      iType = pType;
      iPostion = pPosition;
    }
    public String toString() {
      return (OutPath.CHILD == iType ? "/" : "//" ) + iName;
    }
  }

}
Syntax Highlighting created using the com.Ostermiller.Syntax package.
Thursday, February 23 2006 at 16:47