return new PrototypeObjectFactory<T>(classMetadata);
}
private static <T> ClassMetadata collectClassMetadata(final Class<T> cls,
boolean validateConstructor) {
ClassMetadata classMetadata = null;
if (ProviderMetadataCollector.isProvider(cls)) {
classMetadata = ProviderMetadataCollector.collectMetadata(cls);
} else if (ResourceMetadataCollector.isResource(cls)) {
classMetadata = ResourceMetadataCollector.collectMetadata(cls);
} else {
throw new IllegalArgumentException("Cannot create factory for class " + cls);
}
// validate that there is a valid constructor if needed
if (validateConstructor && classMetadata.getConstructor().getConstructor() == null) {
throw new IllegalStateException("No valid constructor found for " + cls
.getCanonicalName());
}
return classMetadata;
}