in scim-spec/scim-spec-schema/src/main/java/org/apache/directory/scim/spec/schema/Schemas.java [69:111]
private static Schema generateSchema(Class<?> clazz, List<Field> fieldList) throws ScimResourceInvalidException {
Schema schema = new Schema();
ScimResourceType srt = clazz.getAnnotation(ScimResourceType.class);
ScimExtensionType set = clazz.getAnnotation(ScimExtensionType.class);
if (srt == null && set == null) {
// TODO - throw?
log.error("Neither a ScimResourceType or ScimExtensionType annotation found");
}
log.debug("calling set attributes with " + fieldList.size() + " fields");
String urn = set != null ? set.id() : srt.schema();
Set<String> invalidAttributes = new HashSet<>();
List<Schema.Attribute> createAttributes = createAttributes(urn, fieldList, invalidAttributes, clazz.getSimpleName());
schema.setAttributes(createAttributes);
if (!invalidAttributes.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("Scim attributes cannot be primitive types unless they are required. The following values were found that are primitive and not required\n\n");
for (String s : invalidAttributes) {
sb.append(s);
sb.append("\n");
}
throw new ScimResourceInvalidException(sb.toString());
}
if (srt != null) {
schema.setId(srt.schema());
schema.setDescription(srt.description());
schema.setName(srt.name());
} else {
schema.setId(set.id());
schema.setDescription(set.description());
schema.setName(set.name());
}
return schema;
}