private void registerClassDefinitions( final Collection<ClassDefinition> classDefinitions, boolean checkClassDefErrors) { final Map<Integer, ClassDefinition> classDefMap = new HashMap<Integer, ClassDefinition>(classDefinitions.size()); for (ClassDefinition cd : classDefinitions) { if (classDefMap.containsKey(cd.getClassId())) { throw new HazelcastSerializationException( "Duplicate registration found for class-id[" + cd.getClassId() + "]!"); } classDefMap.put(cd.getClassId(), cd); } for (ClassDefinition classDefinition : classDefinitions) { registerClassDefinition(classDefinition, classDefMap, checkClassDefErrors); } }
private void registerClassDefinition( ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) { for (int i = 0; i < cd.getFieldCount(); i++) { FieldDefinition fd = cd.get(i); if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) { int classId = fd.getClassId(); ClassDefinition nestedCd = classDefMap.get(classId); if (nestedCd != null) { ((ClassDefinitionImpl) cd).addClassDef(nestedCd); registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors); serializationContext.registerClassDefinition(nestedCd); } else if (checkClassDefErrors) { throw new HazelcastSerializationException( "Could not find registered ClassDefinition for class-id: " + classId); } } } serializationContext.registerClassDefinition(cd); }