poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r777270 - in /poi/trunk/src/java/org/apache/poi/hssf/record: RecordFactory.java UnknownRecord.java
Date Thu, 21 May 2009 21:32:55 GMT
Author: josh
Date: Thu May 21 21:32:54 2009
New Revision: 777270

URL: http://svn.apache.org/viewvc?rev=777270&view=rev
Log:
Added debug methods to decode BIFF record types from record IDs

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
    poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java?rev=777270&r1=777269&r2=777270&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java Thu May 21 21:32:54 2009
@@ -17,7 +17,6 @@
 
 package org.apache.poi.hssf.record;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -33,7 +32,6 @@
 
 import org.apache.poi.hssf.record.chart.*;
 import org.apache.poi.hssf.record.pivottable.*;
-import org.apache.poi.util.HexDump;
 
 /**
  * Title:  Record Factory<P>
@@ -51,7 +49,7 @@
 	private interface I_RecordCreator {
 		Record create(RecordInputStream in);
 
-		String getRecordClassName();
+		Class<? extends Record> getRecordClass();
 	}
 	private static final class ReflectionRecordCreator implements I_RecordCreator {
 
@@ -73,8 +71,8 @@
 				throw new RecordFormatException("Unable to construct record instance" , e.getTargetException());
 			}
 		}
-		public String getRecordClassName() {
-			return _c.getDeclaringClass().getName();
+		public Class<? extends Record> getRecordClass() {
+			return _c.getDeclaringClass();
 		}
 	}
 
@@ -222,11 +220,26 @@
 	/**
 	 * cache of the recordsToMap();
 	 */
-	private static Map<Short, I_RecordCreator> recordsMap  = recordsToMap(recordClasses);
+	private static final Map<Integer, I_RecordCreator> _recordCreatorsById  = recordsToMap(recordClasses);
 
 	private static short[] _allKnownRecordSIDs;
 	
 	/**
+	 * Debug / diagnosis method<br/>
+	 * Gets the POI implementation class for a given <tt>sid</tt>.  Only a subset
of the any BIFF
+	 * records are actually interpreted by POI.  A few others are known but not interpreted

+	 * (see {@link UnknownRecord#getBiffName(int)}). 
+	 * @return the POI implementation class for the specified record <tt>sid</tt>.
+	 * <code>null</code> if the specified record is not interpreted by POI.
+	 */
+	public static Class<? extends Record> getRecordClass(int sid) {
+		I_RecordCreator rc = _recordCreatorsById.get(new Integer(sid));
+		if (rc == null) {
+			return null;
+		}
+		return rc.getRecordClass();
+	}
+	/**
 	 * create a record, if there are MUL records than multiple records
 	 * are returned digested into the non-mul form.
 	 */
@@ -247,7 +260,7 @@
 	}
 	
 	static Record createSingleRecord(RecordInputStream in) {
-		I_RecordCreator constructor = recordsMap.get(new Short(in.getSid()));
+		I_RecordCreator constructor = _recordCreatorsById.get(new Integer(in.getSid()));
 
 		if (constructor == null) {
 			return new UnknownRecord(in);
@@ -293,11 +306,11 @@
 	 */
 	public static short[] getAllKnownRecordSIDs() {
 		if (_allKnownRecordSIDs == null) {
-			short[] results = new short[ recordsMap.size() ];
+			short[] results = new short[ _recordCreatorsById.size() ];
 			int i = 0;
 
-			for (Iterator<Short> iterator = recordsMap.keySet().iterator(); iterator.hasNext();
) {
-				Short sid = iterator.next();
+			for (Iterator<Integer> iterator = _recordCreatorsById.keySet().iterator(); iterator.hasNext();
) {
+				Integer sid = iterator.next();
 
 				results[i++] = sid.shortValue();
 			}
@@ -313,8 +326,8 @@
 	 * @return map of SIDs to short,short,byte[] constructors for Record classes
 	 * most of org.apache.poi.hssf.record.*
 	 */
-	private static Map<Short, I_RecordCreator> recordsToMap(Class<? extends Record>
[] records) {
-		Map<Short, I_RecordCreator> result = new HashMap<Short, I_RecordCreator>();
+	private static Map<Integer, I_RecordCreator> recordsToMap(Class<? extends Record>
[] records) {
+		Map<Integer, I_RecordCreator> result = new HashMap<Integer, I_RecordCreator>();
 		Set<Class<?>> uniqueRecClasses = new HashSet<Class<?>>(records.length
* 3 / 2);
 
 		for (int i = 0; i < records.length; i++) {
@@ -339,33 +352,17 @@
 				throw new RecordFormatException(
 					"Unable to determine record types");
 			}
-			Short key = new Short(sid);
+			Integer key = new Integer(sid);
 			if (result.containsKey(key)) {
-				String prevClassName = result.get(key).getRecordClassName();
+				Class<?> prevClass = result.get(key).getRecordClass();
 				throw new RuntimeException("duplicate record sid 0x" + Integer.toHexString(sid).toUpperCase()
-						+ " for classes (" + recClass.getName() + ") and (" + prevClassName + ")");
+						+ " for classes (" + recClass.getName() + ") and (" + prevClass.getName() + ")");
 			}
 			result.put(key, new ReflectionRecordCreator(constructor));
 		}
 		return result;
 	}
 
-	private static void checkZeros(InputStream in, int avail) throws IOException {
-		int count=0;
-		while(true) {
-			int b = in.read();
-			if (b < 0) {
-				break;
-			}
-			if (b!=0) {
-				System.err.print(HexDump.byteToHex(b));
-			}
-			count++;
-		}
-		if (avail != count) {
-			System.err.println("avail!=count (" + avail + "!=" + count + ").");
-		}
-	}
 	/**
 	 * Create an array of records from an input stream
 	 *

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java?rev=777270&r1=777269&r2=777270&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/UnknownRecord.java Thu May 21 21:32:54 2009
@@ -123,9 +123,9 @@
 	/**
 	 * These BIFF record types are known but still uninterpreted by POI
 	 * 
-	 * @return the documented name of this BIFF record type
+	 * @return the documented name of this BIFF record type, <code>null</code> if
unknown to POI
 	 */
-	private static String getBiffName(int sid) {
+	public static String getBiffName(int sid) {
 		// Note to POI developers:
 		// Make sure you delete the corresponding entry from 
 		// this method any time a new Record subclass is created.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message