public Object readObject(final ObjectDataInput in) { try { final boolean isNull = in.readBoolean(); if (isNull) { return null; } final int typeId = in.readInt(); final SerializerAdapter serializer = serializerFor(typeId); if (serializer == null) { if (active) { throw new HazelcastSerializationException( "There is no suitable de-serializer for type " + typeId); } throw new HazelcastInstanceNotActiveException(); } if (typeId == SerializationConstants.CONSTANT_TYPE_PORTABLE && in instanceof PortableContextAwareInputStream) { ClassDefinition classDefinition = new ClassDefinitionImpl(); classDefinition.readData(in); classDefinition = serializationContext.registerClassDefinition(classDefinition); PortableContextAwareInputStream ctxIn = (PortableContextAwareInputStream) in; ctxIn.setClassDefinition(classDefinition); } Object obj = serializer.read(in); if (managedContext != null) { obj = managedContext.initialize(obj); } return obj; } catch (Throwable e) { handleException(e); } return null; }
public void writeObject(final ObjectDataOutput out, final Object obj) { final boolean isNull = obj == null; try { out.writeBoolean(isNull); if (isNull) { return; } final SerializerAdapter serializer = serializerFor(obj.getClass()); if (serializer == null) { if (active) { throw new HazelcastSerializationException( "There is no suitable serializer for " + obj.getClass()); } throw new HazelcastInstanceNotActiveException(); } out.writeInt(serializer.getTypeId()); if (obj instanceof Portable) { final Portable portable = (Portable) obj; ClassDefinition classDefinition = serializationContext.lookupOrRegisterClassDefinition(portable); classDefinition.writeData(out); } serializer.write(out, obj); } catch (Throwable e) { handleException(e); } }
public boolean hasClassDefinition(String name) { for (ClassDefinition classDefinition : classDefinitions) { if (classDefinition.getName().equals(name)) { return true; } } return false; }
private HazelcastSerializationException throwUnknownFieldException(String fieldName) { return new HazelcastSerializationException( "Unknown field name: '" + fieldName + "' for ClassDefinition {id: " + cd.getClassId() + ", version: " + cd.getVersion() + "}"); }
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); } }
public Portable[] readPortableArray(String fieldName) throws IOException { FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != FieldType.PORTABLE_ARRAY) { throw new HazelcastSerializationException("Not a Portable array field: " + fieldName); } final int currentPos = in.position(); try { int pos = readPosition(fd); in.position(pos); final int len = in.readInt(); final Portable[] portables = new Portable[len]; if (len > 0) { final int offset = in.position(); for (int i = 0; i < len; i++) { final int start = in.readInt(offset + i * 4); in.position(start); portables[i] = serializer.readAndInitialize(in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } } return portables; } finally { in.position(currentPos); } }
public ObjectDataInput getRawDataInput() throws IOException { if (!raw) { int pos = in.readInt(offset + cd.getFieldCount() * 4); in.position(pos); } raw = true; return in; }
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); }
/** get the n-th constant from the constant pool */ public Object getConstant(int n, Environment env) { int constant_type = getConstantType(n); switch (constant_type) { case CONSTANT_INTEGER: case CONSTANT_FLOAT: case CONSTANT_LONG: case CONSTANT_DOUBLE: return getValue(n); case CONSTANT_CLASS: return getDeclaration(env, n); case CONSTANT_STRING: return getString(getInteger(n)); case CONSTANT_FIELD: case CONSTANT_METHOD: case CONSTANT_INTERFACEMETHOD: try { int key = getInteger(n); ClassDefinition clazz = getDeclaration(env, key >> 16).getClassDefinition(env); int name_and_type = getInteger(key & 0xFFFF); Identifier id = getIdentifier(name_and_type >> 16); Type type = getType(name_and_type & 0xFFFF); for (MemberDefinition field = clazz.getFirstMatch(id); field != null; field = field.getNextMatch()) { Type field_type = field.getType(); if ((constant_type == CONSTANT_FIELD) ? (field_type == type) : (field_type.equalArguments(type))) return field; } } catch (ClassNotFound e) { } return null; default: throw new ClassFormatError("invalid constant type: " + constant_type); } }
private String createClassJcovElement(Environment env, ClassDefinition c) { String SourceClass = (Type.mangleInnerType((c.getClassDeclaration()).getName())).toString(); String ConvSourceClass; String classJcovLine; SourceClassList.addElement(SourceClass); ConvSourceClass = SourceClass.replace('.', '/'); classJcovLine = JcovClassLine + ConvSourceClass; classJcovLine = classJcovLine + " ["; String blank = ""; for (int i = 0; i < arrayModifiers.length; i++) { if ((c.getModifiers() & arrayModifiers[i]) != 0) { classJcovLine = classJcovLine + blank + opNames[arrayModifiersOpc[i]]; blank = " "; } } classJcovLine = classJcovLine + "]"; return classJcovLine; }
@Override public Void visitClass(ClassDefinition classDefinition) { // print annotations first for (AnnotationDefinition annotationDefinition : classDefinition.getAnnotations()) { visitAnnotation(classDefinition, annotationDefinition); } // print class declaration Line classDeclaration = line() .addAll(classDefinition.getAccess()) .add("class") .add(classDefinition.getType().getJavaClassName()); if (!classDefinition.getSuperClass().equals(type(Object.class))) { classDeclaration.add("extends").add(classDefinition.getSuperClass().getJavaClassName()); } if (!classDefinition.getInterfaces().isEmpty()) { classDeclaration.add("implements"); for (ParameterizedType interfaceType : classDefinition.getInterfaces()) { classDeclaration.add(interfaceType.getJavaClassName()); } } classDeclaration.print(); // print class body printLine("{"); indentLevel++; // print fields for (FieldDefinition fieldDefinition : classDefinition.getFields()) { visitField(classDefinition, fieldDefinition); } // print methods for (MethodDefinition methodDefinition : classDefinition.getMethods()) { visitMethod(classDefinition, methodDefinition); } indentLevel--; printLine("}"); printLine(); return null; }
boolean storeClassLiteralsGuess(ObjVector parmSig, boolean isActual) { ExpressionType exprType0; if (isActual) { exprType0 = terms[0].actualExprType(); int s0 = exprType0.objectSize(); if (s0 < Type.CLASSINTERFACE) return false; if (s0 == Type.CLASSINTERFACE) { ClassDefinition cd = exprType0.receiverClass(); exprType0 = cd.name().equals(Names.JAVAX_SWING_PLAF_COLORUIRESOURCE) ? cd.superClass() : cd.mapToPrimType(); } } else { exprType0 = terms[0].classLiteralValGuess(); if (exprType0 == null) return false; if (exprType0.signatureDimensions() == 0) { exprType0 = exprType0.receiverClass(); } } parmSig.addElement(exprType0); return true; }
private int readPosition(String fieldName, FieldType type) throws IOException { if (raw) { throw new HazelcastSerializationException( "Cannot read Portable fields after getRawDataInput() is called!"); } FieldDefinition fd = cd.getField(fieldName); if (fd == null) { return readNestedPosition(fieldName, type); } if (fd.getType() != type) { throw new HazelcastSerializationException("Not a '" + type + "' field: " + fieldName); } return readPosition(fd); }
public Portable readPortable(String fieldName) throws IOException { FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != FieldType.PORTABLE) { throw new HazelcastSerializationException("Not a Portable field: " + fieldName); } final int currentPos = in.position(); try { int pos = readPosition(fd); in.position(pos); final boolean isNull = in.readBoolean(); if (!isNull) { return serializer.readAndInitialize( in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } return null; } finally { in.position(currentPos); } }
void processPass1(Context c) { if (classLiteralValue == null) { terms[0].processPass1(c); ExpressionType exprType0 = terms[0].exprType(); ClassDefinition cd = exprType0.signatureClass(); cd.predefineClass(c.forClass); cd.markUsed(); classLiteralValue = exprType0.signatureDimensions() > 0 ? exprType0 : cd.asExactClassType(); if (exprType0.objectSize() == Type.OBJECTARRAY) { cd = Main.dict.get(Names.JAVA_LANG_VMCLASS); cd.predefineClass(c.forClass); MethodDefinition md = cd.getMethod(Names.SIGN_ARRAYCLASSOF0X); if (md != null && md.isClassMethod()) { md.markUsed(null); this.md = md; } } classLiteralValue.signatureClass().setVTableUsed(false); } }
public int getFieldClassId(String fieldName) { return cd.getFieldClassId(fieldName); }
public FieldType getFieldType(String fieldName) { return cd.getFieldType(fieldName); }
public Set<String> getFieldNames() { return cd.getFieldNames(); }
public boolean hasField(String fieldName) { return cd.hasField(fieldName); }
public int getVersion() { return cd.getVersion(); }