コード例 #1
0
 private Object read(DataContainer container) throws IOException {
   int sw = container.readInt();
   switch (sw) {
     case DataKind.OBJECT_REF:
       {
         int id = container.readInt();
         Object o1 = idToObject.get(id);
         if (o1 == null) {
           throw new AssertionError();
         }
         return o1;
       }
     case DataKind.OBJECT:
       {
         int id = container.readInt();
         Class<?> clazz = (Class) container.readObject();
         ClassTypeModel<?> typeModel =
             (ClassTypeModel<?>) context.getTypeDomain().getTypeModel(clazz);
         return instantiate(id, container, typeModel);
       }
     case DataKind.CONVERTED_OBJECT:
       {
         Class<?> tclazz = (Class<?>) container.readObject();
         ConvertedTypeModel<?, ?> ctm =
             (ConvertedTypeModel<?, ?>) context.getTypeDomain().getTypeModel(tclazz);
         return convertObject(container, ctm);
       }
     case DataKind.SERIALIZED_OBJECT:
       return container.readObject();
     default:
       throw new StreamCorruptedException("Unrecognized data " + sw);
   }
 }
コード例 #2
0
  private <O> O instantiate(ClassTypeModel<O> typeModel, Map<FieldModel<? super O, ?>, ?> state)
      throws InvalidClassException {
    try {
      ObjectFactory<? super O> factory = context.getFactory(typeModel.getJavaType());

      //
      return factory.create(typeModel.getJavaType(), state);
    } catch (Exception e) {
      InvalidClassException ice =
          new InvalidClassException(
              "Cannot instantiate object from class " + typeModel.getJavaType().getName());
      ice.initCause(e);
      throw ice;
    }
  }