Clover coverage report - ATP library for Java - 3.6.4-stable-060214
Coverage timestamp: Вт фев 14 2006 13:45:22 MSK
file stats: LOC: 260   Methods: 11
NCLOC: 136   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Tool.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Copyright (c) 2001-2005,
 3    * RedVerst Group, ISP RAS http://www.ispras.ru
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    *
 9    * 1. Redistributions of source code must retain the above copyright notice, this
 10    * list of conditions and the following disclaimer.
 11    *
 12    * 2. Redistributions in binary form must reproduce the above copyright notice,
 13    * this list of conditions and the following disclaimer in the documentation
 14    * and/or other materials provided with the distribution.
 15    *
 16    * 3. The names "ATP", "TreeDL", "RedVerst", "ISP RAS"
 17    * may not be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 21    * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 22    * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 23    * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 24    * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 25    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 26    * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 27    * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 28    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 29    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30    */
 31   
 32    package com.unitesk.atp.tree.tool;
 33   
 34    import java.io.File;
 35    import java.util.ArrayList;
 36    import java.util.List;
 37   
 38    import com.unitesk.atp.tree.Node;
 39    import com.unitesk.atp.messages.*;
 40   
 41    /**
 42    * The framework of an application that processes Attributed Tree (AT).
 43    * The inheritor must implement abstract methods {@link #parse(File)},
 44    * {@link #initName()}
 45    * and define method
 46    *
 47    * <pre>public static void main( String[] args )
 48    * {
 49    * new MyTool().run( args );
 50    * }</pre>
 51    *
 52    * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
 53    * @version $Id: Tool.java,v 1.6 2005/06/01 06:40:22 all-x Exp $
 54    */
 55    public abstract class Tool extends com.unitesk.atp.tool.Tool
 56    implements PluginManager
 57    {
 58    /**
 59    * Parses the input file and sets tree root node.
 60    *
 61    * @see #setTree(Tree) setTree( Tree )
 62    * @see #getTree()
 63    */
 64    protected abstract void parse( File inputFile );
 65   
 66    /**
 67    * Processes command line arguments.
 68    *
 69    * @param args The array of command line parameters from main() method.
 70    */
 71  0 protected int run( String[] args )
 72    {
 73  0 try
 74    {
 75  0 onToolStart();
 76  0 if( args.length < 1 )
 77    {
 78  0 usage();
 79  0 return 1;
 80    }
 81   
 82  0 String inputFileName = args[0];
 83   
 84  0 if( inputFileName.equals( "-" ) )
 85    {
 86  0 if( args.length == 1 )
 87    {
 88  0 help( null );
 89    } else {
 90  0 List/*String*/ l = new ArrayList/*String*/();
 91   
 92  0 for( int i = 1; i < args.length; i++ )
 93    {
 94  0 l.add( args[i] );
 95    }
 96  0 help( l );
 97    }
 98  0 return 1;
 99    } else {
 100  0 mbox.info( "" );
 101  0 onParserStart( inputFileName );
 102  0 parse( new File( inputFileName ) );
 103  0 mbox.status();
 104  0 onParserFinish( inputFileName );
 105  0 for ( int i = 1; i < args.length; i++ )
 106    {
 107  0 process( args[i], null );
 108    }
 109  0 onToolFinish();
 110  0 return 0;
 111    }
 112    }
 113    catch( FatalErrorException e )
 114    {
 115  0 return e.getCode();
 116    }
 117    }
 118   
 119    //---- interface PluginManager ---------------------------------------------
 120   
 121    protected Tree tree;
 122   
 123    /**
 124    * {@inheritDoc}
 125    */
 126  0 public Tree getTree() { return tree; }
 127   
 128    /**
 129    * {@inheritDoc}
 130    */
 131  0 public void setTree( Tree tree ) { this.tree = tree; }
 132   
 133    /**
 134    * {@inheritDoc}
 135    */
 136  0 public void process( String name, Tree tree )
 137    {
 138  0 Object plugin = getPlugin( name );
 139   
 140  0 if( plugin != null && plugin instanceof Action )
 141    {
 142  0 Action action = (Action)plugin;
 143  0 onActionStart( name, action );
 144  0 action.process( tree != null ? tree : this.tree );
 145  0 mbox.status();
 146  0 onActionFinish( name, action );
 147    } else {
 148  0 mbox.fatal( new NameNotFoundMessage( null
 149    , null
 150    , mbox
 151    .getStringManager()
 152    .getString( Action.class
 153    , "message.action"
 154    )
 155    , name
 156    )
 157    );
 158    }
 159    }
 160   
 161    /**
 162    * {@inheritDoc}
 163    */
 164  0 public Object get( String name, Tree tree, Node node )
 165    {
 166  0 Object plugin = getPlugin( name );
 167   
 168  0 if( plugin != null && plugin instanceof Attribute )
 169    {
 170  0 return ((Attribute)plugin).get( tree != null ? tree : this.tree
 171    , node
 172    );
 173    } else {
 174  0 mbox.fatal( new NameNotFoundMessage( null
 175    , null
 176    , mbox
 177    .getStringManager()
 178    .getString( Attribute.class
 179    , "message.attribute"
 180    )
 181    , name
 182    )
 183    );
 184  0 return null;
 185    }
 186    }
 187   
 188    /**
 189    * Invoked at start of the tool.
 190    * Prints out a name and a version of the tool.
 191    */
 192  0 protected void onToolStart()
 193    {
 194  0 mbox.info( new ToolInfoMessage( this ) );
 195  0 mbox.info( new FileStatusMessage( properties_file_status
 196    , properties_file_name
 197    )
 198    );
 199  0 mbox.info( new FileStatusMessage( plugins_file_status
 200    , plugins_file_name
 201    )
 202    );
 203    }
 204   
 205    /**
 206    * Invoked at finish of the tool.
 207    * Prints out statistics.
 208    */
 209  0 protected void onToolFinish()
 210    {
 211  0 mbox.statistics();
 212    }
 213   
 214    /**
 215    * Invoked before start of parsing.
 216    * Prints out a name of the input file.
 217    *
 218    * @param inputFileName The name of the input file.
 219    */
 220  0 protected void onParserStart( String inputFileName )
 221    {
 222  0 mbox.info( new FileStatusMessage( InputFileStatus.status
 223    , inputFileName
 224    )
 225    );
 226    }
 227   
 228    /**
 229    * Invoked before start of parsing.
 230    * Does nothing.
 231    *
 232    * @param inputFileName The name of the input file.
 233    */
 234  0 protected void onParserFinish( String inputFileName )
 235    {
 236    }
 237   
 238    /**
 239    * Invoked before start of the action.
 240    * Prints out a name and a version of the action.
 241    *
 242    * @param name The name of the action.
 243    * @param action The action.
 244    */
 245  0 protected void onActionStart( String name, Action action )
 246    {
 247  0 mbox.info( new PluginInfoMessage( name, action) );
 248    }
 249   
 250    /**
 251    * Invoked before start of the action.
 252    * Does nothing.
 253    *
 254    * @param name The name of the action.
 255    * @param action The action.
 256    */
 257  0 protected void onActionFinish( String name, Action action )
 258    {
 259    }
 260    }