static Format checkRawType(Catalog catalog, Object o, Format declaredFormat) { assert declaredFormat != null; Format format; if (o instanceof RawObject) { format = (Format) ((RawObject) o).getType(); } else { format = catalog.getFormat(o.getClass()); if (!format.isSimple() || format.isEnum()) { throw new IllegalArgumentException( "Not a RawObject or a non-enum simple type: " + format.getClassName()); } } if (!format.isAssignableTo(declaredFormat)) { throw new IllegalArgumentException( "Not a subtype of the field's declared class " + declaredFormat.getClassName() + ": " + format.getClassName()); } if (!format.isCurrentVersion()) { throw new IllegalArgumentException( "Raw type version is not current. Class: " + format.getClassName() + " Version: " + format.getVersion()); } Format proxiedFormat = format.getProxiedFormat(); if (proxiedFormat != null) { format = proxiedFormat; } return format; }
Object checkAndConvert(Object o, Format declaredFormat) { if (o == null) { if (declaredFormat.isPrimitive()) { throw new IllegalArgumentException( "A primitive type may not be null or missing: " + declaredFormat.getClassName()); } } else if (declaredFormat.isSimple()) { if (declaredFormat.isPrimitive()) { if (o.getClass() != declaredFormat.getWrapperFormat().getType()) { throw new IllegalArgumentException( "Raw value class: " + o.getClass().getName() + " must be the wrapper class for a primitive type: " + declaredFormat.getClassName()); } } else { if (o.getClass() != declaredFormat.getType()) { throw new IllegalArgumentException( "Raw value class: " + o.getClass().getName() + " must be the declared class for a simple type: " + declaredFormat.getClassName()); } } } else { if (o instanceof RawObject) { Object o2 = null; if (!rawAccess) { if (converted != null) { o2 = converted.get(o); } else { converted = new IdentityHashMap(); } } if (o2 != null) { o = o2; } else { if (!rawAccess) { o = catalog.convertRawObject((RawObject) o, converted); } } } else { if (!SimpleCatalog.isSimpleType(o.getClass())) { throw new IllegalArgumentException( "Raw value class: " + o.getClass().getName() + " must be RawObject a simple type"); } } if (rawAccess) { checkRawType(catalog, o, declaredFormat); } else { if (!declaredFormat.getType().isAssignableFrom(o.getClass())) { throw new IllegalArgumentException( "Raw value class: " + o.getClass().getName() + " is not assignable to type: " + declaredFormat.getClassName()); } } } return o; }