1 9 10 11 package JSX.magic; 12 import java.io.*; 13 import java.lang.reflect.*; 14 15 public abstract class MagicClassI { protected static Field oscNameField; 17 protected static ObjectStreamClass osc; 18 public MagicClassI() { 19 try { 20 oscNameField = ObjectStreamClass.class.getDeclaredField( "name"); 22 oscNameField.setAccessible(true); 23 } catch (NoSuchFieldException noField) { 24 throw new InternalError (noField.toString()); 25 } 26 } 27 28 29 abstract public Object newInstance(Class currentClass) 30 throws InvocationTargetException, 31 NotSerializableException, 32 IllegalAccessException ; 33 abstract public void setObjectFieldValue(Object parent, Field f, Class type, Object value); 34 abstract public void setPrimitiveFieldValues(Object parent, Field f, Object value); 35 36 37 42 public ObjectStreamClass getOsc(String escapedName) throws ClassNotFoundException , IOException { 43 setFinal(oscNameField, osc, escapedName); return osc; 45 } 46 47 48 public void setFinal(Field f, Object parent, Object value) { 51 if (f==null) return; if (!Modifier.isFinal(f.getModifiers())) { 53 try { 54 f.set(parent, value); 55 } catch (IllegalAccessException e) { 56 throw new InternalError ("Unable to set '"+f+"'"); 57 } 58 } else { if (f.getType().isPrimitive()) 60 setPrimitiveFieldValues(parent, f, value); else 62 setObjectFieldValue(parent, f, f.getType(), value); } 64 } 65 } 66
| Popular Tags
|