storing of generated class files in slots implemented BLD200410171800
authordprusa@netbeans.org
Fri, 15 Oct 2004 11:45:41 +0000
changeset 16035dd8668e5e0c
parent 1602 62e0989f7bb4
child 1604 a818f68d8338
storing of generated class files in slots implemented
mdr/src/org/netbeans/mdr/handlers/gen/HandlerGenerator.java
mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java
mdr/src/org/netbeans/mdr/util/IOUtils.java
     1.1 --- a/mdr/src/org/netbeans/mdr/handlers/gen/HandlerGenerator.java	Thu Oct 14 09:07:07 2004 +0000
     1.2 +++ b/mdr/src/org/netbeans/mdr/handlers/gen/HandlerGenerator.java	Fri Oct 15 11:45:41 2004 +0000
     1.3 @@ -61,15 +61,30 @@
     1.4       */
     1.5      public static byte[] generateHandler(final String name, Class ifc, StorableBaseObject storable) {
     1.6          HandlerGenerator gen;
     1.7 +        byte[] result = null;
     1.8          try {
     1.9 +            StorableObject metaObject = storable.getMetaObject();
    1.10              if (storable instanceof StorableAssociation) {
    1.11 +                result = metaObject.getClassFile();
    1.12 +                if (result != null)
    1.13 +                    return result;
    1.14                  gen = new AssociationGenerator(name, ifc, ((StorableAssociation)storable).getAssociationSuperclass(), (StorableAssociation)storable, ((StorableAssociation)storable).getAssociationCustomImpl());
    1.15              } else if (storable instanceof StorableClass) {
    1.16 +                result = metaObject.getClassFile();
    1.17 +                if (result != null)
    1.18 +                    return result;
    1.19                  gen = new ClassGenerator(name, ifc, ((StorableClass) storable).getClassSuperclass(), (StorableClass)storable, ((StorableClass) storable).getClassCustomImpl());
    1.20              } else if (storable instanceof StorablePackage) {
    1.21 +                result = metaObject.getClassFile();
    1.22 +                if (result != null)
    1.23 +                    return result;
    1.24                  gen = new PackageGenerator(name, ifc, ((StorablePackage) storable).getPackageSuperclass(), (StorablePackage)storable, ((StorablePackage) storable).getPackageCustomImpl());
    1.25              } else if (storable instanceof StorableObject) {
    1.26 -                gen = new InstanceGenerator(name, ifc, ((StorableObject) storable).getClassProxy().getInstanceSuperclass(), (StorableObject)storable, ((StorableObject) storable).getClassProxy().getInstanceCustomImpl());
    1.27 +                result = metaObject.getInstanceClassFile();
    1.28 +                if (result != null)
    1.29 +                    return result;
    1.30 +                StorableClass proxy = ((StorableObject) storable).getClassProxy();
    1.31 +                gen = new InstanceGenerator(name, ifc, proxy.getInstanceSuperclass(), (StorableObject)storable, proxy.getInstanceCustomImpl());
    1.32              } else {
    1.33                  throw new InternalError("Unknow dispatcher type."); //NOI18N
    1.34              }
    1.35 @@ -79,7 +94,18 @@
    1.36          
    1.37          ByteArrayOutputStream bout = new ByteArrayOutputStream();
    1.38          gen.generateClassFile(bout);
    1.39 -        return bout.toByteArray();
    1.40 +        result = bout.toByteArray();
    1.41 +        try {
    1.42 +            StorableObject metaObject = storable.getMetaObject();
    1.43 +            if (storable instanceof StorableObject) {
    1.44 +                metaObject.setInstanceClassFile(result);
    1.45 +            } else {
    1.46 +                metaObject.setClassFile(result);
    1.47 +            }
    1.48 +        } catch (Exception e) {
    1.49 +            throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
    1.50 +        }
    1.51 +        return result;
    1.52      }
    1.53      
    1.54      public static boolean customImplContainsMethod(Class customImpl, String name, String descriptor) {
     2.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java	Thu Oct 14 09:07:07 2004 +0000
     2.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java	Fri Oct 15 11:45:41 2004 +0000
     2.3 @@ -653,4 +653,20 @@
     2.4          return objectToString (value, fields[0].isOrdered());
     2.5      }
     2.6      
     2.7 +    public byte[] getClassFile() {
     2.8 +        return (byte[]) getSlot1();
     2.9 +    }
    2.10 +    
    2.11 +    public void setClassFile(byte[] bytecode) {
    2.12 +        setSlot1(bytecode);
    2.13 +    }
    2.14 +    
    2.15 +    public byte[] getInstanceClassFile() {
    2.16 +        return (byte[]) getSlot2();
    2.17 +    }
    2.18 +    
    2.19 +    public void setInstanceClassFile(byte[] bytecode) {
    2.20 +        setSlot2(bytecode);
    2.21 +    }
    2.22 +    
    2.23  }
     3.1 --- a/mdr/src/org/netbeans/mdr/util/IOUtils.java	Thu Oct 14 09:07:07 2004 +0000
     3.2 +++ b/mdr/src/org/netbeans/mdr/util/IOUtils.java	Fri Oct 15 11:45:41 2004 +0000
     3.3 @@ -61,6 +61,7 @@
     3.4      public static final int T_SHORT = 22;
     3.5      public static final int T_MOFID = 23;
     3.6      public static final int T_ARRAY = 24;
     3.7 +    public static final int T_BYTE = 25;
     3.8      
     3.9      /** Creates new IOUtils */
    3.10      public IOUtils() {
    3.11 @@ -94,6 +95,10 @@
    3.12          }
    3.13      }
    3.14      
    3.15 +    public static void writeByte(OutputStream outputStream, byte val) throws IOException {
    3.16 +        outputStream.write(val);
    3.17 +    }
    3.18 +    
    3.19      public static void writeLong(OutputStream outputStream, long val) throws IOException {
    3.20          if ((int) ((byte) val & 0x7F) == val) {
    3.21              outputStream.write((byte)val);
    3.22 @@ -165,9 +170,8 @@
    3.23              outputStream.write(T_STRING);
    3.24              writeString(outputStream, (String)object);
    3.25          } else if (object instanceof Integer) {
    3.26 -            int val = ((Integer)object).intValue();
    3.27              outputStream.write(T_INTEGER);
    3.28 -            writeInt(outputStream, val);
    3.29 +            writeInt(outputStream, ((Integer)object).intValue());
    3.30          } else if (object instanceof Boolean) {
    3.31              outputStream.write(T_BOOLEAN);
    3.32              writeBoolean(outputStream, ((Boolean) object).booleanValue());
    3.33 @@ -180,6 +184,9 @@
    3.34          } else if (object instanceof Long) {
    3.35              outputStream.write(T_LONG);
    3.36              writeLong(outputStream, ((Long) object).longValue());
    3.37 +        } else if (object instanceof Byte) {
    3.38 +            outputStream.write(T_BYTE);
    3.39 +            writeByte(outputStream, ((Byte)object).byteValue());
    3.40          } else if (object instanceof Map) {
    3.41              outputStream.write(T_MAP);
    3.42              Map temp = (Map) object;
    3.43 @@ -200,6 +207,12 @@
    3.44                  for (int i = 0; i < length; i++) {
    3.45                      writeInt(outputStream, a[i]);
    3.46                  }
    3.47 +            } else if (object instanceof byte[]) {
    3.48 +                outputStream.write(T_BYTE);
    3.49 +                byte[] a = (byte[]) object;
    3.50 +                for (int i = 0; i < length; i++) {
    3.51 +                    writeByte(outputStream, a[i]);
    3.52 +                }
    3.53              }
    3.54              
    3.55          } else if (object instanceof AttrCollection) {
    3.56 @@ -300,6 +313,10 @@
    3.57          return (is.read() == 1);
    3.58      }
    3.59      
    3.60 +    public static byte readByte(InputStream is) throws IOException {
    3.61 +        return (byte)is.read();
    3.62 +    }
    3.63 +    
    3.64      public static int readInt(InputStream is) throws IOException {
    3.65          return readInt(is, is.read());
    3.66      }
    3.67 @@ -415,6 +432,8 @@
    3.68                  return new Float(Float.intBitsToFloat(readInt(inputStream)));
    3.69              case T_DOUBLE:
    3.70                  return new Double(Double.longBitsToDouble(readLong(inputStream)));
    3.71 +            case T_BYTE:
    3.72 +                return new Byte(readByte(inputStream));
    3.73              case T_BOOLEAN: {
    3.74                  return readBoolean(inputStream) ? Boolean.TRUE : Boolean.FALSE;
    3.75              } case T_ARRAY: {
    3.76 @@ -427,6 +446,12 @@
    3.77                              result[i] = readInt(inputStream);
    3.78                          }
    3.79                          return result;
    3.80 +                    case T_BYTE:
    3.81 +                        byte[] res = new byte[length];
    3.82 +                        for (int i = 0; i < length; i++) {
    3.83 +                            res[i] = readByte(inputStream);
    3.84 +                        }
    3.85 +                        return res;
    3.86                      default:
    3.87                          throw new DebugException();
    3.88                  }