private IReflectClass EnsureClassAvailability(int id) { if (id == 0) { return(null); } IReflectClass ret = (IReflectClass)_classByID.Get(id); if (ret != null) { return(ret); } ByteArrayBuffer classreader = _stream.ReadStatefulBufferById(_trans, id); ClassMarshaller marshaller = MarshallerFamily()._class; RawClassSpec spec = marshaller.ReadSpec(_trans, classreader); string className = spec.Name(); ret = LookupByName(className); if (ret != null) { _classByID.Put(id, ret); _pendingClasses.Add(id); return(ret); } ReportMissingClass(className); ret = _builder.CreateClass(className, EnsureClassAvailability(spec.SuperClassID() ), spec.NumFields()); // step 1 only add to _classByID, keep the class out of _classByName and _classes _classByID.Put(id, ret); _pendingClasses.Add(id); return(ret); }
private void EnsureClassRead(int id) { IReflectClass clazz = LookupByID(id); ByteArrayBuffer classreader = _stream.ReadStatefulBufferById(_trans, id); ClassMarshaller classMarshaller = MarshallerFamily()._class; RawClassSpec classInfo = classMarshaller.ReadSpec(_trans, classreader); string className = classInfo.Name(); // Having the class in the _classByName Map for now indicates // that the class is fully read. This is breakable if we start // returning GenericClass'es in other methods like forName // even if a native class has not been found if (LookupByName(className) != null) { return; } // step 2 add the class to _classByName and _classes to denote reading is completed Register(className, clazz); int numFields = classInfo.NumFields(); IReflectField[] fields = _builder.FieldArray(numFields); IFieldMarshaller fieldMarshaller = MarshallerFamily()._field; for (int i = 0; i < numFields; i++) { RawFieldSpec fieldInfo = fieldMarshaller.ReadSpec(_stream, classreader); string fieldName = fieldInfo.Name(); IReflectClass fieldClass = ReflectClassForFieldSpec(fieldInfo, _stream.Reflector( )); if (null == fieldClass && (fieldInfo.IsField() && !fieldInfo.IsVirtual())) { throw new InvalidOperationException("Could not read field type for '" + className + "." + fieldName + "'"); } fields[i] = _builder.CreateField(clazz, fieldName, fieldClass, fieldInfo.IsVirtual (), fieldInfo.IsPrimitive(), fieldInfo.IsArray(), fieldInfo.IsNArray()); } _builder.InitFields(clazz, fields); _listeners.NotifyListeners(clazz); }