/** * @param cls type to examine. * @return true if typeId equals for passed type and current * binary enum. */ public boolean isTypeEquals(final Class<?> cls) { return ctx.descriptorForClass(cls, false, false).typeId() == typeId(); } }
/** * Resolve the class. * * @param ctx Binary context. * @param typeId Type ID. * @param clsName Class name. * @param ldr Class loaded. * @return Resovled class. */ public static Class resolveClass(BinaryContext ctx, int typeId, @Nullable String clsName, @Nullable ClassLoader ldr, boolean deserialize) { Class cls; if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID) cls = ctx.descriptorForTypeId(true, typeId, ldr, deserialize).describedClass(); else { try { cls = U.forName(clsName, ldr); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } // forces registering of class by type id, at least locally ctx.descriptorForClass(cls, true, false); } return cls; }
/** * @param val Array. */ void doWriteEnumArray(@Nullable Object[] val) { assert val == null || val.getClass().getComponentType().isEnum(); if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass( val.getClass().getComponentType(), false, failIfUnregistered); out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.ENUM_ARR); if (desc.registered()) out.unsafeWriteInt(desc.typeId()); else { out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(val.getClass().getComponentType().getName()); } out.writeInt(val.length); // TODO: Denis: Redundant data for each element of the array. for (Object o : val) doWriteEnum((Enum<?>)o); } }
/** * @param val Value. */ void doWriteEnum(@Nullable Enum<?> val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(val.getDeclaringClass(), false, failIfUnregistered); out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.ENUM); if (desc.registered()) out.unsafeWriteInt(desc.typeId()); else { out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(val.getDeclaringClass().getName()); } out.writeInt(val.ordinal()); } }
/** * @param val Array of objects. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ void doWriteObjectArray(@Nullable Object[] val) throws BinaryObjectException { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { if (tryWriteAsHandle(val)) return; BinaryClassDescriptor desc = ctx.descriptorForClass( val.getClass().getComponentType(), false, failIfUnregistered); out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.OBJ_ARR); if (desc.registered()) out.unsafeWriteInt(desc.typeId()); else { out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(val.getClass().getComponentType().getName()); } out.writeInt(val.length); for (Object obj : val) doWriteObject(obj); } }
/** * @param val Class. */ void doWriteClass(@Nullable Class val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(val, false, failIfUnregistered); out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.CLASS); if (desc.registered()) out.unsafeWriteInt(desc.typeId()); else { out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(val.getName()); } } }
/** * @param proxy Proxy. */ public void doWriteProxy(Proxy proxy, Class<?>[] intfs) { if (proxy == null) out.writeByte(GridBinaryMarshaller.NULL); else { out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.PROXY); out.unsafeWriteInt(intfs.length); for (Class<?> intf : intfs) { BinaryClassDescriptor desc = ctx.descriptorForClass(intf, false, failIfUnregistered); if (desc.registered()) out.writeInt(desc.typeId()); else { out.writeInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(intf.getName()); } } InvocationHandler ih = Proxy.getInvocationHandler(proxy); assert ih != null; doWriteObject(ih); } }
/** * @param in Binary input stream. * @param ctx Binary context. * @param ldr Class loader. * @param typeId Type id. * @return Class object specified at the input stream. * @throws BinaryObjectException If failed. */ public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, int typeId) throws BinaryObjectException { Class cls; if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID) cls = ctx.descriptorForTypeId(true, typeId, ldr, true).describedClass(); else { String clsName = doReadClassName(in); try { cls = U.forName(clsName, ldr); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } // forces registering of class by type id, at least locally ctx.descriptorForClass(cls, true, false); } return cls; }
writer.context().descriptorForClass(((Enum)val).getDeclaringClass(), false, false);
/** * @param reader BinaryBuilderReader. */ public BinaryBuilderEnum(BinaryBuilderReader reader) { int typeId = reader.readInt(); if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { clsName = reader.readString(); Class cls; try { cls = U.forName(reader.readString(), reader.binaryContext().configuration().getClassLoader()); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } this.typeId = reader.binaryContext().descriptorForClass(cls, false, false).typeId(); } else { this.typeId = typeId; this.clsName = null; } ordinal = reader.readInt(); }
BinaryClassDescriptor desc = ctx.descriptorForClass(cls, false, failIfUnregistered);
/** * @param reader Reader. */ protected BinaryObjectArrayLazyValue(BinaryBuilderReader reader) { super(reader, reader.position() - 1); int typeId = reader.readInt(); if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { clsName = reader.readString(); Class cls; try { cls = U.forName(reader.readString(), reader.binaryContext().configuration().getClassLoader()); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } compTypeId = reader.binaryContext().descriptorForClass(cls, true, false).typeId(); } else { compTypeId = typeId; clsName = null; } int size = reader.readInt(); lazyValsArr = new Object[size]; for (int i = 0; i < size; i++) lazyValsArr[i] = reader.parseValue(); }
/** * @param reader Reader. */ protected BinaryEnumArrayLazyValue(BinaryBuilderReader reader) { super(reader, reader.position() - 1); int typeId = reader.readInt(); if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) { clsName = reader.readString(); Class cls; try { cls = U.forName(reader.readString(), reader.binaryContext().configuration().getClassLoader()); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } compTypeId = reader.binaryContext().descriptorForClass(cls, true, false).typeId(); } else { compTypeId = typeId; clsName = null; } int size = reader.readInt(); for (int i = 0; i < size; i++) reader.skipValue(); len = reader.position() - valOff; }
this.typeId = ctx.descriptorForClass(cls, false, false).typeId();
desc = ctx.descriptorForClass(BinaryUtils.doReadClass(in, ctx, ldr, typeId0), false, false);
.binaryContext().descriptorForClass(ex.cls(), false, false);
/** * @param cls type to examine. * @return true if typeId equals for passed type and current * binary enum. */ public boolean isTypeEquals(final Class<?> cls) { return ctx.descriptorForClass(cls, false, false).typeId() == typeId(); } }
/** * Resolve the class. * * @param ctx Binary context. * @param typeId Type ID. * @param clsName Class name. * @param ldr Class loaded. * @return Resovled class. */ public static Class resolveClass(BinaryContext ctx, int typeId, @Nullable String clsName, @Nullable ClassLoader ldr, boolean deserialize) { Class cls; if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID) cls = ctx.descriptorForTypeId(true, typeId, ldr, deserialize).describedClass(); else { try { cls = U.forName(clsName, ldr); } catch (ClassNotFoundException e) { throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e); } // forces registering of class by type id, at least locally ctx.descriptorForClass(cls, true, false); } return cls; }
/** * @param val Value. */ void doWriteEnum(@Nullable Enum<?> val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(val.getDeclaringClass(), false, failIfUnregistered); out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.ENUM); if (desc.registered()) out.unsafeWriteInt(desc.typeId()); else { out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(val.getDeclaringClass().getName()); } out.writeInt(val.ordinal()); } }
/** * @param val Class. */ void doWriteClass(@Nullable Class val) { if (val == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryClassDescriptor desc = ctx.descriptorForClass(val, false, failIfUnregistered); out.unsafeEnsure(1 + 4); out.unsafeWriteByte(GridBinaryMarshaller.CLASS); if (desc.registered()) out.unsafeWriteInt(desc.typeId()); else { out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID); doWriteString(val.getName()); } } }