From 573a993fec1c4b8c659830e2cebb6e7362a86f77 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Tue, 22 Dec 2009 00:03:04 +0000 Subject: [PATCH] Removed unused Model, ModelFactory. ModelFactoryListener etc. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@893041 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/eventmodel/ModelFactory.java | 113 ------------- .../hssf/eventmodel/ModelFactoryListener.java | 36 ----- src/java/org/apache/poi/hssf/model/Model.java | 29 ---- src/java/org/apache/poi/hssf/model/Sheet.java | 2 +- .../org/apache/poi/hssf/model/Workbook.java | 2 +- .../org/apache/poi/hssf/HSSFTests.java | 6 +- .../poi/hssf/eventmodel/TestModelFactory.java | 151 ------------------ 7 files changed, 3 insertions(+), 336 deletions(-) delete mode 100644 src/java/org/apache/poi/hssf/eventmodel/ModelFactory.java delete mode 100644 src/java/org/apache/poi/hssf/eventmodel/ModelFactoryListener.java delete mode 100644 src/java/org/apache/poi/hssf/model/Model.java delete mode 100644 src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java diff --git a/src/java/org/apache/poi/hssf/eventmodel/ModelFactory.java b/src/java/org/apache/poi/hssf/eventmodel/ModelFactory.java deleted file mode 100644 index f1465b389f..0000000000 --- a/src/java/org/apache/poi/hssf/eventmodel/ModelFactory.java +++ /dev/null @@ -1,113 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.eventmodel; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.poi.hssf.model.Model; -import org.apache.poi.hssf.model.Sheet; -import org.apache.poi.hssf.model.Workbook; -import org.apache.poi.hssf.record.BOFRecord; -import org.apache.poi.hssf.record.EOFRecord; -import org.apache.poi.hssf.record.Record; - - -/** - * 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 - */ -public class ModelFactory implements ERFListener -{ - - List listeners; - Model currentmodel; - boolean lastEOF; - - /** - * Constructor for ModelFactory. Does practically nothing. - */ - public ModelFactory() - { - super(); - listeners = new ArrayList(1); - } - - /** - * register a ModelFactoryListener so that it can receive - * Models as they are created. - */ - public void registerListener(ModelFactoryListener listener) { - listeners.add(listener); - } - - /** - * Start processing the Workbook stream into Model events. - */ - public void run(InputStream stream) { - EventRecordFactory factory = new EventRecordFactory(this,null); - lastEOF = true; - factory.processRecords(stream); - } - - //ERFListener - public boolean processRecord(Record rec) { - if (rec.getSid() == BOFRecord.sid) { - if (lastEOF != true) { - throw new RuntimeException("Not yet handled embedded models"); - } - BOFRecord bof = (BOFRecord)rec; - switch (bof.getType()) { - case BOFRecord.TYPE_WORKBOOK: - currentmodel = new Workbook(); - break; - case BOFRecord.TYPE_WORKSHEET: - currentmodel = Sheet.createSheet(); - break; - default: - throw new RuntimeException("Unsupported model type "+bof.getType()); - } - } - - if (rec.getSid() == EOFRecord.sid) { - lastEOF = true; - throwEvent(currentmodel); - } else { - lastEOF = false; - } - return true; - } - - /** - * Throws the model as an event to the listeners - * @param model to be thrown - */ - private void throwEvent(Model model) - { - Iterator i = listeners.iterator(); - while (i.hasNext()) { - ModelFactoryListener mfl = (ModelFactoryListener) i.next(); - mfl.process(model); - } - } -} diff --git a/src/java/org/apache/poi/hssf/eventmodel/ModelFactoryListener.java b/src/java/org/apache/poi/hssf/eventmodel/ModelFactoryListener.java deleted file mode 100644 index 53a654acfb..0000000000 --- a/src/java/org/apache/poi/hssf/eventmodel/ModelFactoryListener.java +++ /dev/null @@ -1,36 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.eventmodel; - -import org.apache.poi.hssf.model.Model; - -/** - * ModelFactoryListener is registered with the - * ModelFactory. It receives Models. - * - * @author Andrew C. Oliver acoliver@apache.org - */ -public interface ModelFactoryListener -{ - /** - * Process a model. Called by the ModelFactory - * @param model to be processed - * @return abortable - currently ignored (may be implemented in the future) - */ - public boolean process(Model model); -} diff --git a/src/java/org/apache/poi/hssf/model/Model.java b/src/java/org/apache/poi/hssf/model/Model.java deleted file mode 100644 index 180bbb8603..0000000000 --- a/src/java/org/apache/poi/hssf/model/Model.java +++ /dev/null @@ -1,29 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - - -package org.apache.poi.hssf.model; - -/** - * enclosing_type describe the purpose here - * - * @author Andrew C. Oliver androliv@cisco.com - */ -public interface Model -{ - -} diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index cc19ae1cd2..9bb93a603e 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -94,7 +94,7 @@ import org.apache.poi.util.POILogger; * @see org.apache.poi.hssf.model.Workbook * @see org.apache.poi.hssf.usermodel.HSSFSheet */ -public final class Sheet implements Model { +public final class Sheet { public static final short LeftMargin = 0; public static final short RightMargin = 1; public static final short TopMargin = 2; diff --git a/src/java/org/apache/poi/hssf/model/Workbook.java b/src/java/org/apache/poi/hssf/model/Workbook.java index 812f719e8d..e03e689cb4 100644 --- a/src/java/org/apache/poi/hssf/model/Workbook.java +++ b/src/java/org/apache/poi/hssf/model/Workbook.java @@ -108,7 +108,7 @@ import org.apache.poi.util.POILogger; * @author Glen Stampoultzis (glens at apache.org) * @see org.apache.poi.hssf.usermodel.HSSFWorkbook */ -public final class Workbook implements Model { +public final class Workbook { /** * Excel silently truncates long sheet names to 31 chars. * This constant is used to ensure uniqueness in the first 31 chars diff --git a/src/testcases/org/apache/poi/hssf/HSSFTests.java b/src/testcases/org/apache/poi/hssf/HSSFTests.java index 856e31cb42..7e58985ebb 100644 --- a/src/testcases/org/apache/poi/hssf/HSSFTests.java +++ b/src/testcases/org/apache/poi/hssf/HSSFTests.java @@ -21,7 +21,6 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.apache.poi.hssf.eventmodel.TestEventRecordFactory; -import org.apache.poi.hssf.eventmodel.TestModelFactory; import org.apache.poi.hssf.eventusermodel.AllEventUserModelTests; import org.apache.poi.hssf.extractor.TestExcelExtractor; import org.apache.poi.hssf.model.AllModelTests; @@ -33,9 +32,7 @@ import org.apache.poi.ss.util.AllSSUtilTests; /** * Test Suite for all sub-packages of org.apache.poi.hssf
- * - * Mostly this is for my convenience. - * + * * @author Andrew C. Oliver acoliver@apache.org */ public final class HSSFTests { @@ -50,7 +47,6 @@ public final class HSSFTests { suite.addTest(AllHSSFUtilTests.suite()); suite.addTest(new TestSuite(TestExcelExtractor.class)); suite.addTest(new TestSuite(TestEventRecordFactory.class)); - suite.addTest(new TestSuite(TestModelFactory.class)); suite.addTest(AllSSFormulaTests.suite()); suite.addTest(AllSSUtilTests.suite()); return suite; diff --git a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java b/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java deleted file mode 100644 index 7cb7f11644..0000000000 --- a/src/testcases/org/apache/poi/hssf/eventmodel/TestModelFactory.java +++ /dev/null @@ -1,151 +0,0 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ - -package org.apache.poi.hssf.eventmodel; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.poi.hssf.model.Model; -import org.apache.poi.hssf.model.Sheet; -import org.apache.poi.hssf.model.Workbook; -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFRow; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; - -import junit.framework.TestCase; - -/** - * Tests the ModelFactory. - * - * @author Andrew C. Oliver acoliver@apache.org - */ -public class TestModelFactory extends TestCase { - private ModelFactory factory; - private HSSFWorkbook book; - private InputStream in; - private List models; - - protected void setUp() throws Exception - { - ModelFactory mf = new ModelFactory(); - assertTrue("listeners member cannot be null", mf.listeners != null); - models = new ArrayList(3); - factory = new ModelFactory(); - book = new HSSFWorkbook(); - ByteArrayOutputStream stream = setupRunFile(book); - POIFSFileSystem fs = new POIFSFileSystem( - new ByteArrayInputStream(stream.toByteArray()) - ); - in = fs.createDocumentInputStream("Workbook"); - } - - protected void tearDown() throws Exception - { - super.tearDown(); - factory = null; - book = null; - in = null; - } - - /** - * tests that listeners can be registered - */ - public void testRegisterListener() - { - if (factory.listeners.size() != 0) { - factory = new ModelFactory(); - } - - factory.registerListener(new MFListener(null)); - factory.registerListener(new MFListener(null)); - assertTrue("Factory listeners should be two, was="+ - factory.listeners.size(), - factory.listeners.size() == 2); - } - - /** - * tests that given a simple input stream with one workbook and sheet - * that those models are processed and returned. - */ - public void testRun() - { - Model temp = null; - Iterator mi = null; - - if (factory.listeners.size() != 0) { - factory = new ModelFactory(); - } - - factory.registerListener(new MFListener(models)); - factory.run(in); - - assertTrue("Models size must be 2 was = "+models.size(), - models.size() == 2); - mi = models.iterator(); - temp = (Model)mi.next(); - - assertTrue("First model is Workbook was " + temp.getClass().getName(), - temp instanceof Workbook); - - temp = (Model)mi.next(); - - assertTrue("Second model is Sheet was " + temp.getClass().getName(), - temp instanceof Sheet); - - } - - /** - * Sets up a test file - */ - private ByteArrayOutputStream setupRunFile(HSSFWorkbook book) throws Exception { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - HSSFSheet sheet = book.createSheet("Test"); - HSSFRow row = sheet.createRow(0); - HSSFCell cell = row.createCell(0); - cell.setCellValue(10.5); - book.write(stream); - return stream; - } - -} - -/** - * listener for use in the test - */ -class MFListener implements ModelFactoryListener { - private List mlist; - public MFListener(List mlist) { - this.mlist = mlist; - } - - public boolean process(Model model) - { - mlist.add(model); - return true; - } - - public Iterator models() { - return mlist.iterator(); - } -} -- 2.39.5