Package org.jostraca.unit

Source Code of org.jostraca.unit.DebugUnitProcessor

/*
* Name:    DebugUnitProcessor
* Author:  Richard Rodger
*  
* Copyright (c) 2002-2005 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/


// package
package org.jostraca.unit;


// import
import org.jostraca.section.SectionSet;

import org.jostraca.util.ErrorUtil;
import org.jostraca.util.TextUtil;


/** Returns a SectionSet with debugging info about Units in a UnitList.
@see org.jostraca.unit.UnitList
*/
public class DebugUnitProcessor implements UnitProcessor {

  // public static
  public static final String CN = DebugUnitProcessor.class.getName();



  // private instance
  private SectionSet iSectionSet = null;



  // interface UnitProcessor

  /** @see org.jostraca.unit.UnitProcessor */
  public SectionSet process( UnitList pUnitList ) throws UnitException {
    return process( pUnitList, new SectionSet() );
  }


  /** @see org.jostraca.unit.UnitProcessor */
  public SectionSet process( UnitList pUnitList, SectionSet pSectionSet ) throws UnitException {
    if( ErrorUtil.is_null( pSectionSet, "pSectionSet" ) ) {
      iSectionSet = new SectionSet();
    }
    else {
      iSectionSet = pSectionSet;
    }

    processImpl( pUnitList, pSectionSet );

    return iSectionSet;
  }



  // public methods

  public static final String formatUnitDebugInfo( Unit pUnit ) {
    return
      "t:"+pUnit.getType()+" s:"+pUnit.getSection()+" c:"+TextUtil.oneLine( pUnit.getContent(), 44 )
      +" o:"+pUnit.getOrigin()+" a:"+pUnit.getAttributes()+"\n";
  }



  // private methods

  private SectionSet processImpl( UnitList pUnitList, SectionSet pSectionSet ) {
   
    while( pUnitList.nextUnit() ) {
      Unit u = pUnitList.getUnit();

      pSectionSet.appendToSection( u.getSection(), formatUnitDebugInfo( u ) );
    }

    return pSectionSet;
  }
}
TOP

Related Classes of org.jostraca.unit.DebugUnitProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.