/** * Validates if the given factoryId and classId match the ones from the fieldDefinition * * @param fd given fieldDefinition to validate against * @param factoryId given factoryId to validate * @param classId given factoryId to validate * @param fullPath full path - just for output */ static void validateFactoryAndClass(FieldDefinition fd, int factoryId, int classId, String fullPath) { if (factoryId != fd.getFactoryId()) { throw new IllegalArgumentException("Invalid factoryId! Expected: " + fd.getFactoryId() + ", Current: " + factoryId + " in path " + fullPath); } if (classId != fd.getClassId()) { throw new IllegalArgumentException("Invalid classId! Expected: " + fd.getClassId() + ", Current: " + classId + " in path " + fullPath); } } }
@Override public FieldDefinition getField(int fieldIndex) { if (fieldIndex < 0 || fieldIndex >= fieldDefinitionsMap.size()) { throw new IndexOutOfBoundsException("Index: " + fieldIndex + ", Size: " + fieldDefinitionsMap.size()); } for (FieldDefinition fieldDefinition : fieldDefinitionsMap.values()) { if (fieldIndex == fieldDefinition.getIndex()) { return fieldDefinition; } } throw new IndexOutOfBoundsException("Index: " + fieldIndex + ", Size: " + fieldDefinitionsMap.size()); }
@Override public FieldType getType() { if (fd != null) { return fd.getType(); } return null; } }
throw new IllegalArgumentException("Unknown field: " + name); currentClassDef = lookupClassDefinition(fd.getFactoryId(), fd.getClassId(), fd.getVersion()); if (currentClassDef == null) { throw new IllegalArgumentException("Not a registered Portable field: " + fd);
protected void registerClassDefinition(ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) { final Set<String> fieldNames = cd.getFieldNames(); for (String fieldName : fieldNames) { FieldDefinition fd = cd.getField(fieldName); if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) { int classId = fd.getClassId(); ClassDefinition nestedCd = classDefMap.get(classId); if (nestedCd != null) { registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors); portableContext.registerClassDefinition(nestedCd); } else if (checkClassDefErrors) { throw new HazelcastSerializationException( "Could not find registered ClassDefinition for class-id: " + classId); } } } portableContext.registerClassDefinition(cd); }
@Override public int getFieldClassId(String fieldName) { final FieldDefinition fd = getField(fieldName); if (fd != null) { return fd.getClassId(); } throw new IllegalArgumentException("Unknown field: " + fieldName); }
@Override public FieldType getType() { if (fd != null) { return fd.getType(); } return null; } }
throw new IllegalArgumentException("Unknown field: " + name); currentClassDef = lookupClassDefinition(fd.getFactoryId(), fd.getClassId(), fd.getVersion()); if (currentClassDef == null) { throw new IllegalArgumentException("Not a registered Portable field: " + fd);
protected void registerClassDefinition(ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) { final Set<String> fieldNames = cd.getFieldNames(); for (String fieldName : fieldNames) { FieldDefinition fd = cd.getField(fieldName); if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) { int classId = fd.getClassId(); ClassDefinition nestedCd = classDefMap.get(classId); if (nestedCd != null) { registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors); portableContext.registerClassDefinition(nestedCd); } else if (checkClassDefErrors) { throw new HazelcastSerializationException( "Could not find registered ClassDefinition for class-id: " + classId); } } } portableContext.registerClassDefinition(cd); }
@Override public int getFieldClassId(String fieldName) { final FieldDefinition fd = getField(fieldName); if (fd != null) { return fd.getClassId(); } throw new IllegalArgumentException("Unknown field: " + fieldName); }
/** * Validates if the given factoryId and classId match the ones from the fieldDefinition * * @param fd given fieldDefinition to validate against * @param factoryId given factoryId to validate * @param classId given factoryId to validate * @param fullPath full path - just for output */ static void validateFactoryAndClass(FieldDefinition fd, int factoryId, int classId, String fullPath) { if (factoryId != fd.getFactoryId()) { throw new IllegalArgumentException("Invalid factoryId! Expected: " + fd.getFactoryId() + ", Current: " + factoryId + " in path " + fullPath); } if (classId != fd.getClassId()) { throw new IllegalArgumentException("Invalid classId! Expected: " + fd.getClassId() + ", Current: " + classId + " in path " + fullPath); } } }
boolean isCurrentFieldOfType(FieldType type) { return fd.getType() == type; }
@Override public FieldDefinition getField(int fieldIndex) { if (fieldIndex < 0 || fieldIndex >= fieldDefinitionsMap.size()) { throw new IndexOutOfBoundsException("Index: " + fieldIndex + ", Size: " + fieldDefinitionsMap.size()); } for (FieldDefinition fieldDefinition : fieldDefinitionsMap.values()) { if (fieldIndex == fieldDefinition.getIndex()) { return fieldDefinition; } } throw new IndexOutOfBoundsException("Index: " + fieldIndex + ", Size: " + fieldDefinitionsMap.size()); }
private void checkPortableAttributes(FieldDefinition fd, Portable portable) { if (fd.getFactoryId() != portable.getFactoryId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + " Expected factory-id: " + fd.getFactoryId() + ", Actual factory-id: " + portable.getFactoryId()); } if (fd.getClassId() != portable.getClassId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + "Expected class-id: " + fd.getClassId() + ", Actual class-id: " + portable.getClassId()); } }
FieldType getCurrentFieldType() { return fd.getType(); }
/** * Calculates the position of the given field in the portable byte stream * * @param fd given field definition * @param in data input stream * @param offset offset to use while stream reading * @return position of the given field * @throws IOException on any stream errors */ static int getStreamPositionOfTheField(FieldDefinition fd, BufferObjectDataInput in, int offset) throws IOException { int pos = in.readInt(offset + fd.getIndex() * Bits.INT_SIZE_IN_BYTES); short len = in.readShort(pos); // name + len + type return pos + Bits.SHORT_SIZE_IN_BYTES + len + 1; }
private void checkPortableAttributes(FieldDefinition fd, Portable portable) { if (fd.getFactoryId() != portable.getFactoryId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + " Expected factory-id: " + fd.getFactoryId() + ", Actual factory-id: " + portable.getFactoryId()); } if (fd.getClassId() != portable.getClassId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + "Expected class-id: " + fd.getClassId() + ", Actual class-id: " + portable.getClassId()); } }
boolean isCurrentFieldOfType(FieldType type) { return fd.getType() == type; }