/*
* Although metadata is only needed for a complex type, call
* getClassMetadata for all types to support checks for illegal
* metadata on other types.
*/
ClassMetadata metadata = model.getClassMetadata(className);
/* Create format of the appropriate type. */
String proxyClassName = null;
if (proxyClassMap != null) {
proxyClassName = proxyClassMap.get(className);
}
if (proxyClassName != null) {
format = new ProxiedFormat(this, type, proxyClassName);
} else if (type.isArray()) {
format = type.getComponentType().isPrimitive() ?
(new PrimitiveArrayFormat(this, type)) :
(new ObjectArrayFormat(this, type));
} else if (type.isEnum()) {
format = new EnumFormat(this, type);
} else if (type.getEnclosingClass() != null &&
type.getEnclosingClass().isEnum()) {
/*
* If the type is an anonymous class of an enum class, the format
* which represents the enum class will be created. [#18357]
*/
format = new EnumFormat(this, type.getEnclosingClass());
} else if (type == Object.class || type.isInterface()) {
format = new NonPersistentFormat(this, type);
} else {
if (metadata == null) {
throw new IllegalArgumentException
("Class could not be loaded or is not persistent: " +
className);
}
if (metadata.getCompositeKeyFields() != null &&
(metadata.getPrimaryKey() != null ||
metadata.getSecondaryKeys() != null)) {
throw new IllegalArgumentException
("A composite key class may not have primary or" +
" secondary key fields: " + type.getName());
}
/*
* Check for inner class before default constructor, to give a
* specific error message for each.
*/
if (type.getEnclosingClass() != null &&
!Modifier.isStatic(type.getModifiers())) {
throw new IllegalArgumentException
("Inner classes not allowed: " + type.getName());
}
try {
type.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException
("No default constructor: " + type.getName(), e);
}
if (metadata.getCompositeKeyFields() != null) {
format = new CompositeKeyFormat
(this, type, metadata,
metadata.getCompositeKeyFields());
} else {
EntityMetadata entityMetadata =
model.getEntityMetadata(className);
format =
new ComplexFormat(this, type, metadata, entityMetadata);