themeinstaller/source/src/com/nokia/tools/themeinstaller/odtconverter/ParserComposite.java
branchRCL_3
changeset 32 fe49e33862e2
parent 31 b685c59de105
child 33 04b7640f6fb5
equal deleted inserted replaced
31:b685c59de105 32:fe49e33862e2
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class stores parser components
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.tools.themeinstaller.odtconverter;
       
    20 
       
    21 import java.io.IOException;
       
    22 import java.util.Vector;
       
    23 
       
    24 /**
       
    25  * This class stores parser components and calls components parse method.
       
    26  */
       
    27 public class ParserComposite extends ParseOperation
       
    28                                 implements IParseOperationListener
       
    29     {
       
    30 
       
    31     /** Vector for parsing operations */
       
    32     Vector iParseOperations = new Vector();
       
    33 
       
    34     /** Vector element index */
       
    35     private int iIndex = 0;
       
    36 
       
    37     /**
       
    38      * Instantiates a new ParserComposite.
       
    39      */
       
    40     public ParserComposite()
       
    41         {
       
    42         }
       
    43 
       
    44     /**
       
    45      * Adds parsers to ParserComposite.
       
    46      *
       
    47      * @param ParseOperation
       
    48      */
       
    49     public void addOperation( ParseOperation aParseOperation )
       
    50         {
       
    51         iParseOperations.addElement( aParseOperation );
       
    52         aParseOperation.addListener( this );
       
    53         }
       
    54 
       
    55     /**
       
    56      * If parse operation was successful, calls next until all available files
       
    57      * are parsed
       
    58      */
       
    59     public void parseOperationCompleted( int aErr, String aReason )
       
    60         {
       
    61         ParseOperation oper;
       
    62         if( aErr == OPERATION_SUCCESSFUL )
       
    63             {
       
    64             // get DOM document from previous parse operation
       
    65             oper = ( ParseOperation )iParseOperations.elementAt( iIndex++ );
       
    66             iDOMDocument = oper.getDOMDocument();
       
    67 
       
    68             if( iIndex < iParseOperations.size() )
       
    69                 {
       
    70                 oper =
       
    71                      ( ParseOperation )iParseOperations.elementAt( iIndex );
       
    72                 try
       
    73                     {
       
    74                     oper.iDOMDocument = iDOMDocument;
       
    75                     oper.parse( );
       
    76                     }
       
    77                 catch ( IOException e )
       
    78                     {
       
    79                     operationCompleted( SYNTAX_ERROR, e.getMessage() );
       
    80                     }
       
    81                 catch ( ODTException e )
       
    82                     {
       
    83                     operationCompleted( SYNTAX_ERROR, e.getMessage() );
       
    84                     }
       
    85                 }
       
    86             else
       
    87                 {
       
    88                 operationCompleted( OPERATION_SUCCESSFUL, null );
       
    89                 }
       
    90             }
       
    91         else
       
    92             {
       
    93             operationCompleted( aErr, aReason );
       
    94             }
       
    95         }
       
    96 
       
    97     /* (non-Javadoc)
       
    98      * @see com.nokia.tools.themeinstaller.odtconverter.ParseOperation#parse()
       
    99      */
       
   100     public void parse( )
       
   101             throws IOException, ODTException
       
   102         {
       
   103         iIndex = 0;
       
   104 
       
   105         if( !iParseOperations.isEmpty() )
       
   106             {
       
   107             ParseOperation oper =
       
   108                        ( ParseOperation )iParseOperations.elementAt( iIndex );
       
   109             oper.parse( );
       
   110             }
       
   111         else
       
   112             {
       
   113             return;
       
   114             }
       
   115         }
       
   116     }