[jboss-svn-commits] JBL Code SVN: r18734 - labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Mar 6 11:47:35 EST 2008
Author: mingjin
Date: 2008-03-06 11:47:35 -0500 (Thu, 06 Mar 2008)
New Revision: 18734
Modified:
labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
Log:
fine tuning.
Modified: labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java
===================================================================
--- labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2008-03-06 15:57:03 UTC (rev 18733)
+++ labs/jbossrules/branches/ming-serialization/drools-core/src/main/java/org/drools/common/DroolsObjectInputStream.java 2008-03-06 16:47:35 UTC (rev 18734)
@@ -53,90 +53,73 @@
void.class );
}
- private static class DroolsInternalInputStream
+ private ClassLoader classLoader;
+ private InternalRuleBase ruleBase;
+ private InternalWorkingMemory workingMemory;
+ private Package pkg;
+ private DialectDatas dialectDatas;
+ private ClassFieldExtractorCache extractorFactory;
+
+ private class DroolsInternalInputStream
extends ObjectInputStream
implements DroolsObjectInput {
- private ClassLoader classLoader;
- private InternalRuleBase ruleBase;
- private InternalWorkingMemory workingMemory;
- private Package pkg;
- private DialectDatas dialectDatas;
- private ClassFieldExtractorCache extractorFactory;
private DroolsInternalInputStream(InputStream in, ClassLoader classLoader) throws IOException {
super(in);
setClassLoader(classLoader);
- extractorFactory = ClassFieldExtractorCache.getInstance();
}
public ClassLoader getClassLoader() {
- return classLoader;
+ return DroolsObjectInputStream.this.getClassLoader();
}
public void setClassLoader(ClassLoader classLoader) {
- if (classLoader == null) {
- classLoader = Thread.currentThread().getContextClassLoader();
- if ( classLoader == null ) {
- classLoader = getClass().getClassLoader();
- }
- }
- this.classLoader = classLoader;
+ DroolsObjectInputStream.this.setClassLoader(classLoader);
}
public InternalRuleBase getRuleBase() {
- return ruleBase;
+ return DroolsObjectInputStream.this.getRuleBase();
}
-
public void setRuleBase(InternalRuleBase ruleBase) {
- this.ruleBase = ruleBase;
+ DroolsObjectInputStream.this.setRuleBase(ruleBase);
}
+ public InternalWorkingMemory getWorkingMemory() {
+ return DroolsObjectInputStream.this.getWorkingMemory();
+ }
public void setWorkingMemory(InternalWorkingMemory workingMemory) {
- this.workingMemory = workingMemory;
+ DroolsObjectInputStream.this.setWorkingMemory(workingMemory);
}
- public InternalWorkingMemory getWorkingMemory() {
- return workingMemory;
- }
-
public Package getPackage() {
- return pkg;
+ return DroolsObjectInputStream.this.getPackage();
}
-
public void setPackage(Package pkg) {
- this.pkg = pkg;
+ DroolsObjectInputStream.this.setPackage(pkg);
}
+
public DialectDatas getDialectDatas() {
- return dialectDatas;
+ return DroolsObjectInputStream.this.getDialectDatas();
}
-
public void setDialectDatas(DialectDatas dialectDatas) {
- this.dialectDatas = dialectDatas;
+ DroolsObjectInputStream.this.setDialectDatas(dialectDatas);
}
public ClassFieldExtractorCache getExtractorFactory() {
- return extractorFactory;
+ return DroolsObjectInputStream.this.getExtractorFactory();
}
public void setExtractorFactory(ClassFieldExtractorCache extractorFactory) {
- this.extractorFactory = extractorFactory;
+ DroolsObjectInputStream.this.setExtractorFactory(extractorFactory);
}
- protected Class resolveClass(String name) throws ClassNotFoundException {
- Class clazz = primClasses.get( name );
- if ( clazz == null ) {
- clazz = getClassLoader().loadClass( name );
- }
- return clazz;
- }
-
protected Class resolveClass(ObjectStreamClass desc) throws IOException,
ClassNotFoundException {
if ( getClassLoader() == null ) {
return super.resolveClass( desc );
} else {
try {
- return resolveClass(desc.getName());
+ return DroolsObjectInputStream.this.resolveClass(desc.getName());
}
catch (ClassNotFoundException cnf) {
return super.resolveClass( desc );
@@ -152,55 +135,67 @@
public DroolsObjectInputStream(InputStream inputStream, ClassLoader classLoader) throws IOException {
dataInput = new DroolsInternalInputStream(inputStream, classLoader);
setClassLoader(classLoader);
+ extractorFactory = ClassFieldExtractorCache.getInstance();
}
- public DroolsObjectInputStream(ObjectInput objectInput) throws IOException {
- this(objectInput, null);
+ public DroolsObjectInputStream(ObjectInput inputStream) throws IOException {
+ this(inputStream, null);
}
- public DroolsObjectInputStream(ObjectInput objectInput, ClassLoader classLoader) throws IOException {
- this((InputStream)objectInput, classLoader);
+ public DroolsObjectInputStream(ObjectInput inputStream, ClassLoader classLoader) throws IOException {
+ this((InputStream)inputStream, classLoader);
}
public InternalRuleBase getRuleBase() {
- return dataInput.getRuleBase();
+ return ruleBase;
}
-
public void setRuleBase(InternalRuleBase ruleBase) {
- dataInput.setRuleBase(ruleBase);
+ this.ruleBase = ruleBase;
}
+ public InternalWorkingMemory getWorkingMemory() {
+ return workingMemory;
+ }
public void setWorkingMemory(InternalWorkingMemory workingMemory) {
- dataInput.setWorkingMemory(workingMemory);
+ this.workingMemory = workingMemory;
}
- public InternalWorkingMemory getWorkingMemory() {
- return dataInput.getWorkingMemory();
- }
-
public Package getPackage() {
- return dataInput.getPackage();
+ return pkg;
}
-
public void setPackage(Package pkg) {
- dataInput.setPackage(pkg);
+ this.pkg = pkg;
}
+
public DialectDatas getDialectDatas() {
- return dataInput.getDialectDatas();
+ return dialectDatas;
}
-
public void setDialectDatas(DialectDatas dialectDatas) {
- dataInput.setDialectDatas(dialectDatas);
+ this.dialectDatas = dialectDatas;
}
public ClassFieldExtractorCache getExtractorFactory() {
- return dataInput.getExtractorFactory();
+ return extractorFactory;
}
public void setExtractorFactory(ClassFieldExtractorCache extractorFactory) {
- dataInput.setExtractorFactory(extractorFactory);
+ this.extractorFactory = extractorFactory;
}
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ if (classLoader == null) {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ if ( classLoader == null ) {
+ classLoader = getClass().getClassLoader();
+ }
+ }
+ this.classLoader = classLoader;
+ }
+
protected void readStreamHeader() throws IOException {
int magic = readInt();
short version = readShort();
@@ -272,7 +267,7 @@
private Object readArray(int handle) throws IOException, ClassNotFoundException {
Class clazz = (Class) readObject();
- int length = readInt();
+ int length = dataInput.readInt();
Class componentType = clazz.getComponentType();
Object array = Array.newInstance(componentType, length);
registerObject(handle, array);
@@ -308,47 +303,47 @@
private void readIntArray(int[] ints, int length) throws IOException {
for (int i = 0; i < length; ++i) {
- ints[i] = readInt();
+ ints[i] = dataInput.readInt();
}
}
private void readByteArray(byte[] bytes, int length) throws IOException {
- readFully(bytes, 0, length);
+ dataInput.readFully(bytes, 0, length);
}
private void readLongArray(long[] longs, int length) throws IOException {
for (int i = 0; i < length; ++i) {
- longs[i] = readLong();
+ longs[i] = dataInput.readLong();
}
}
private void readFloatArray(float[] floats, int length) throws IOException {
for (int i = 0; i < length; ++i) {
- floats[i] = readFloat();
+ floats[i] = dataInput.readFloat();
}
}
private void readDoubleArray(double[] doubles, int length) throws IOException {
for (int i = 0; i < length; ++i) {
- doubles[i] = readDouble();
+ doubles[i] = dataInput.readDouble();
}
}
private void readShortArray(short[] shorts, int length) throws IOException {
for (int i = 0; i < length; ++i) {
- shorts[i] = readShort();
+ shorts[i] = dataInput.readShort();
}
}
private void readCharArray(char[] chars, int length) throws IOException {
for (int i = 0; i < length; ++i) {
- chars[i] = readChar();
+ chars[i] = dataInput.readChar();
}
}
private void readBooleanArray(boolean[] booleans, int length) throws IOException {
for (int i = 0; i < length; ++i) {
- booleans[i] = readBoolean();
+ booleans[i] = dataInput.readBoolean();
}
}
@@ -394,14 +389,14 @@
}
private String readString(int handle) throws IOException {
- String string = readUTF();
+ String string = dataInput.readUTF();
registerObject(handle, string);
return string;
}
private Map readMap(int handle) throws IOException, ClassNotFoundException {
Class clazz = (Class) readObject();
- int size = readInt();
+ int size = dataInput.readInt();
Map<Object, Object> map = (Map<Object, Object>) newCollection(handle, clazz, size);
for (int i = 0; i < size; ++i) {
Object key = readObject();
@@ -413,7 +408,7 @@
private Collection readCollection(int handle) throws IOException, ClassNotFoundException {
Class clazz = (Class) readObject();
- int size = readInt();
+ int size = dataInput.readInt();
Collection<Object> collection = (Collection<Object>) newCollection(handle, clazz, size);
for (int i = 0; i < size; ++i) {
collection.add(readObject());
@@ -421,7 +416,7 @@
return collection;
}
- private Object newCollection(int handle, Class clazz, int size) throws ClassNotFoundException, IOException {
+ private Object newCollection(int handle, Class clazz, int size) throws IOException {
Object collection;
try {
Constructor constructor = clazz.getConstructor(Integer.TYPE);
@@ -440,7 +435,7 @@
}
private int readHandle() throws IOException {
- return readInt();
+ return dataInput.readInt();
}
private Class readClass(int handle) throws IOException, ClassNotFoundException {
@@ -451,7 +446,7 @@
}
private byte readRecordType() throws IOException {
- return readByte();
+ return dataInput.readByte();
}
private Object readReference(int handle) {
@@ -468,14 +463,6 @@
return exception;
}
- public void setClassLoader(ClassLoader classLoader) {
- dataInput.setClassLoader(classLoader);
- }
-
- public ClassLoader getClassLoader() {
- return dataInput.getClassLoader();
- }
-
/**
* Using the ClassLoader from the top of the stack to load the class specified by the given class name.
* @param className
@@ -484,7 +471,11 @@
*/
protected Class resolveClass(String className) throws ClassNotFoundException{
try {
- return dataInput.resolveClass(className);
+ Class clazz = primClasses.get( className );
+ if ( clazz == null ) {
+ clazz = getClassLoader().loadClass( className );
+ }
+ return clazz;
}
catch (ClassNotFoundException e) {
return getClass().getClassLoader().loadClass(className);
@@ -597,8 +588,6 @@
* updated with data from the input stream.
*
* @param b the buffer into which the data is read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public void readFully(byte b[]) throws IOException {
@@ -645,8 +634,6 @@
* @param b the buffer into which the data is read.
* @param off an int specifying the offset into the data.
* @param len an int specifying the number of bytes to read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public void readFully(byte b[], int off, int len) throws IOException {
@@ -687,8 +674,6 @@
* method of interface <code>DataOutput</code>.
*
* @return the <code>boolean</code> value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public boolean readBoolean() throws IOException {
@@ -705,8 +690,6 @@
* method of interface <code>DataOutput</code>.
*
* @return the 8-bit value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public byte readByte() throws IOException {
@@ -727,8 +710,6 @@
* <code>0</code> through <code>255</code>.
*
* @return the unsigned 8-bit value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public int readUnsignedByte() throws IOException {
@@ -750,8 +731,6 @@
* interface <code>DataOutput</code>.
*
* @return the 16-bit value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public short readShort() throws IOException {
@@ -775,8 +754,6 @@
* <code>0</code> through <code>65535</code>.
*
* @return the unsigned 16-bit value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public int readUnsignedShort() throws IOException {
@@ -798,8 +775,6 @@
* <code>DataOutput</code>.
*
* @return the Unicode <code>char</code> read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public char readChar() throws IOException {
@@ -824,8 +799,6 @@
* method of interface <code>DataOutput</code>.
*
* @return the <code>int</code> value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public int readInt() throws IOException {
@@ -860,8 +833,6 @@
* method of interface <code>DataOutput</code>.
*
* @return the <code>long</code> value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public long readLong() throws IOException {
@@ -882,8 +853,6 @@
* method of interface <code>DataOutput</code>.
*
* @return the <code>float</code> value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public float readFloat() throws IOException {
@@ -904,8 +873,6 @@
* method of interface <code>DataOutput</code>.
*
* @return the <code>double</code> value read.
- * @exception java.io.EOFException if this stream reaches the end before reading
- * all the bytes.
* @exception IOException if an I/O error occurs.
*/
public double readDouble() throws IOException {
@@ -1034,11 +1001,7 @@
* may be used to write data that is suitable
* for reading by this method.
* @return a Unicode string.
- * @exception java.io.EOFException if this stream reaches the end
- * before reading all the bytes.
* @exception IOException if an I/O error occurs.
- * @exception java.io.UTFDataFormatException if the bytes do not represent a
- * valid modified UTF-8 encoding of a string.
*/
public String readUTF() throws IOException {
return dataInput.readUTF();
More information about the jboss-svn-commits
mailing list