1 7 8 package javax.sql.rowset.serial; 9 10 import java.sql.*; 11 import java.io.*; 12 import java.util.Map ; 13 import java.lang.reflect.*; 14 import javax.sql.rowset.RowSetWarning ; 15 16 32 public class SerialJavaObject implements Serializable, Cloneable { 33 34 37 private Object obj; 38 39 40 43 private transient Field[] fields; 44 45 53 public SerialJavaObject(Object obj) throws SerialException { 54 55 58 59 Class c = obj.getClass(); 61 62 boolean serializableImpl = false; 64 Class [] theIf = c.getInterfaces(); 65 for (int i = 0; i < theIf.length; i++) { 66 String ifName = theIf[i].getName(); 67 if (ifName == "java.io.Serializable") { 68 serializableImpl = true; 69 } 70 } 71 72 77 boolean anyStaticFields = false; 78 fields = c.getFields(); 79 81 for (int i = 0; i < fields.length; i++ ) { 82 if ( fields[i].getModifiers() == Modifier.STATIC ) { 83 anyStaticFields = true; 84 } 85 } 87 try { 88 if (!(serializableImpl)) { 89 throw new RowSetWarning ("Test"); 90 } 91 } catch (RowSetWarning w) { 92 setWarning(w); 93 } 94 95 if (anyStaticFields) { 96 throw new SerialException ("Located static fields in " + 97 "object instance. Cannot serialize"); 98 } 99 100 this.obj = obj; 101 } 102 103 111 public Object getObject() throws SerialException { 112 return this.obj; 113 } 114 115 123 public Field[] getFields() throws SerialException { 124 if (fields != null) { 125 Class c = this.obj.getClass(); 126 return sun.reflect.misc.FieldUtil.getFields(c); 127 } else { 128 throw new SerialException ("SerialJavaObject does not contain" + 129 " a serialized object instance"); 130 } 131 } 132 133 137 static final long serialVersionUID = -1465795139032831023L; 138 139 144 java.util.Vector chain; 145 146 149 private void setWarning(RowSetWarning e) { 150 if (chain == null) { 151 chain = new java.util.Vector (); 152 } 153 chain.add(e); 154 } 155 } 156 | Popular Tags |