FileDocCategorySizeDatePackage
ModelFactory.javaAPI DocApache Poi 3.0.13779Mon Jan 01 12:39:36 GMT 2007org.apache.poi.hssf.eventmodel

ModelFactory

public class ModelFactory extends Object implements ERFListener
ModelFactory creates workbook and sheet models based upon events thrown by them there events from the EventRecordFactory.
see
org.apache.poi.hssf.eventmodel.EventRecordFactory
author
Andrew C. Oliver acoliver@apache.org

Fields Summary
List
listeners
org.apache.poi.hssf.model.Model
currentmodel
boolean
lastEOF
Constructors Summary
public ModelFactory()
Constructor for ModelFactory. Does practically nothing.

        super();
        listeners = new ArrayList(1);
    
Methods Summary
public booleanprocessRecord(org.apache.poi.hssf.record.Record rec)

       if (rec.getSid() == BOFRecord.sid) {
             if (lastEOF != true) {
              throw new RuntimeException("Not yet handled embedded models");  
             } else {
              BOFRecord bof = (BOFRecord)rec;
              switch (bof.getType()) {
               case BOFRecord.TYPE_WORKBOOK:
                 currentmodel = new Workbook();                 
               break;
               case BOFRecord.TYPE_WORKSHEET:
                 currentmodel = new Sheet();                                  
               break;
              default:
                   throw new RuntimeException("Unsupported model type "+bof.getType());
              }                
               
             }        
        }
        
        if (rec.getSid() == EOFRecord.sid) {
            lastEOF = true;
            throwEvent(currentmodel);
        } else {
            lastEOF = false;   
        }
        
 
        return true;
    
public voidregisterListener(ModelFactoryListener listener)
register a ModelFactoryListener so that it can receive Models as they are created.

        listeners.add(listener);
    
public voidrun(java.io.InputStream stream)
Start processing the Workbook stream into Model events.

        EventRecordFactory factory = new EventRecordFactory(true);
        factory.registerListener(this,null);
        lastEOF = true;
        factory.processRecords(stream);
    
private voidthrowEvent(org.apache.poi.hssf.model.Model model)
Throws the model as an event to the listeners

param
model to be thrown

        Iterator i = listeners.iterator();
        while (i.hasNext()) {
          ModelFactoryListener mfl = (ModelFactoryListener) i.next();
          mfl.process(model);
        }