/** * @param clsName Class name. * @param ctx Binary context. */ public BinaryObjectBuilderImpl(BinaryContext ctx, String clsName) { this(ctx, ctx.typeId(clsName), ctx.userTypeName(clsName)); }
/** {@inheritDoc} */ @Override public BinaryObject buildEnum(String typeName, int ord) throws BinaryObjectException { A.notNullOrEmpty(typeName, "enum type name"); int typeId = binaryCtx.typeId(typeName); typeName = binaryCtx.userTypeName(typeName); updateMetadata(typeId, typeName, null, null, true, null); return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ord); }
/** {@inheritDoc} */ @Override public BinaryType registerEnum(String typeName, Map<String, Integer> vals) throws BinaryObjectException { A.notNullOrEmpty(typeName, "enum type name"); int typeId = binaryCtx.typeId(typeName); typeName = binaryCtx.userTypeName(typeName); BinaryUtils.validateEnumValues(typeName, vals); updateMetadata(typeId, typeName, null, null, true, vals); return binaryCtx.metadata(typeId); }
String typeName = writer.context().userTypeName(clsName);
/** * @throws Exception If failed. */ @Test public void testCustomTypeRegistration() throws Exception { BinaryTypeConfiguration customType = new BinaryTypeConfiguration(Value.class.getName()); BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(customType)); BinaryContext ctx = binaryContext(marsh); int typeId = ctx.typeId(Value.class.getName()); BinaryClassDescriptor descriptor = ctx.descriptorForTypeId(true, typeId, null, false); assertEquals(Value.class, descriptor.describedClass()); assertEquals(true, descriptor.registered()); assertEquals(true, descriptor.userType()); // Custom explicit types must be registered in 'predefinedTypes' in order not to break the interoperability. Field field = ctx.getClass().getDeclaredField("predefinedTypes"); field.setAccessible(true); Map<Integer, BinaryClassDescriptor> map = (Map<Integer, BinaryClassDescriptor>)field.get(ctx); assertTrue(!map.isEmpty()); assertNotNull(map.get(typeId)); // Custom explicit types must NOT be registered in 'predefinedTypeNames'. field = ctx.getClass().getDeclaredField("predefinedTypeNames"); field.setAccessible(true); Map<String, Integer> map2 = (Map<String, Integer>)field.get(ctx); assertTrue(!map2.isEmpty()); assertNull(map2.get(ctx.userTypeName(Value.class.getName()))); }
/** {@inheritDoc} */ @Override public BinaryObject buildEnum(String typeName, String name) throws BinaryObjectException { A.notNullOrEmpty(typeName, "enum type name"); A.notNullOrEmpty(name, "enum name"); int typeId = binaryCtx.typeId(typeName); BinaryMetadata metadata = metadata0(typeId); if (metadata == null) throw new BinaryObjectException("Failed to get metadata for type [typeId=" + typeId + ", typeName='" + typeName + "']"); Integer ordinal = metadata.getEnumOrdinalByName(name); typeName = binaryCtx.userTypeName(typeName); if (ordinal == null) throw new BinaryObjectException("Failed to resolve enum ordinal by name [typeId=" + typeId + ", typeName='" + typeName + "', name='" + name + "']"); return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ordinal); }
/** * @param typeName Type name. * @return Wrapper. */ private BinaryObjectBuilderImpl newWrapper(String typeName) { CacheObjectBinaryProcessorImpl processor = (CacheObjectBinaryProcessorImpl)( (IgniteBinaryImpl)binaries()).processor(); return new BinaryObjectBuilderImpl(processor.binaryContext(), processor.typeId(typeName), processor.binaryContext().userTypeName(typeName)); }
/** * @param clsName Class name. * @param ctx Binary context. */ public BinaryObjectBuilderImpl(BinaryContext ctx, String clsName) { this(ctx, ctx.typeId(clsName), ctx.userTypeName(clsName)); }
/** {@inheritDoc} */ @Override public BinaryObject buildEnum(String typeName, int ord) throws BinaryObjectException { A.notNullOrEmpty(typeName, "enum type name"); int typeId = binaryCtx.typeId(typeName); typeName = binaryCtx.userTypeName(typeName); updateMetadata(typeId, typeName, null, null, true, null); return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ord); }
/** {@inheritDoc} */ @Override public BinaryType registerEnum(String typeName, Map<String, Integer> vals) throws BinaryObjectException { A.notNullOrEmpty(typeName, "enum type name"); int typeId = binaryCtx.typeId(typeName); typeName = binaryCtx.userTypeName(typeName); BinaryUtils.validateEnumValues(typeName, vals); updateMetadata(typeId, typeName, null, null, true, vals); return binaryCtx.metadata(typeId); }
/** {@inheritDoc} */ @Override public BinaryObject buildEnum(String typeName, String name) throws BinaryObjectException { A.notNullOrEmpty(typeName, "enum type name"); A.notNullOrEmpty(name, "enum name"); int typeId = binaryCtx.typeId(typeName); BinaryMetadata metadata = metadata0(typeId); if (metadata == null) throw new BinaryObjectException("Failed to get metadata for type [typeId=" + typeId + ", typeName='" + typeName + "']"); Integer ordinal = metadata.getEnumOrdinalByName(name); typeName = binaryCtx.userTypeName(typeName); if (ordinal == null) throw new BinaryObjectException("Failed to resolve enum ordinal by name [typeId=" + typeId + ", typeName='" + typeName + "', name='" + name + "']"); return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ordinal); }
String typeName = writer.context().userTypeName(clsName);