public static JSONObject convert(TypeDefinition type) {
if (type == null) {
return null;
}
JSONObject result = new JSONObject();
result.put(JSON_TYPE_ID, type.getId());
result.put(JSON_TYPE_LOCALNAME, type.getLocalName());
result.put(JSON_TYPE_LOCALNAMESPACE, type.getLocalNamespace());
result.put(JSON_TYPE_DISPLAYNAME, type.getDisplayName());
result.put(JSON_TYPE_QUERYNAME, type.getQueryName());
result.put(JSON_TYPE_DESCRIPTION, type.getDescription());
result.put(JSON_TYPE_BASE_ID, type.getBaseTypeId().value());
result.put(JSON_TYPE_PARENT_ID, type.getParentTypeId());
result.put(JSON_TYPE_CREATABLE, type.isCreatable());
result.put(JSON_TYPE_FILEABLE, type.isFileable());
result.put(JSON_TYPE_QUERYABLE, type.isQueryable());
result.put(JSON_TYPE_FULLTEXT_INDEXED, type.isFulltextIndexed());
result.put(JSON_TYPE_INCLUDE_IN_SUPERTYPE_QUERY, type.isIncludedInSupertypeQuery());
result.put(JSON_TYPE_CONTROLABLE_POLICY, type.isControllablePolicy());
result.put(JSON_TYPE_CONTROLABLE_ACL, type.isControllableAcl());
if (type instanceof DocumentTypeDefinition) {
result.put(JSON_TYPE_VERSIONABLE, ((DocumentTypeDefinition) type).isVersionable());
result.put(JSON_TYPE_CONTENTSTREAM_ALLOWED, ((DocumentTypeDefinition) type).getContentStreamAllowed()
.value());
}
if (type instanceof RelationshipTypeDefinition) {
result.put(JSON_TYPE_ALLOWED_SOURCE_TYPES,
getJSONArrayFromList(((RelationshipTypeDefinition) type).getAllowedSourceTypeIds()));
result.put(JSON_TYPE_ALLOWED_TARGET_TYPES,
getJSONArrayFromList(((RelationshipTypeDefinition) type).getAllowedTargetTypeIds()));
}
if ((type.getPropertyDefinitions() != null) && (!type.getPropertyDefinitions().isEmpty())) {
JSONObject propertyDefs = new JSONObject();
for (PropertyDefinition<?> pd : type.getPropertyDefinitions().values()) {
propertyDefs.put(pd.getId(), convert(pd));
}
result.put(JSON_TYPE_PROPERTY_DEFINITIONS, propertyDefs);
}