List<Property> props = getSortedCollectionProperties(entity);
Iterator<Property> iter = props.iterator();
Set<String> seen = new HashSet<String>();
while (iter.hasNext()) {
Property prop = iter.next();
String name = collectionNameForProperty(prop);
if (!seen.contains(name)) {
seen.add(name);
}
else {
iter.remove();
}
}
return props;
}
else if ("validations".equals(propertyName)) {
Map<String, List<String>> map = new HashMap<String, List<String>>();
for (Property p : entity.getProperties()) {
List<String> validations = new ArrayList<String>();
List<Annotation> docAnnotations = p.getDocAnnotations();
if (docAnnotations != null) {
for (Annotation a : docAnnotations) {
String name = a.annotationType().getName();
String validation = validationMap.get(name);
if (validation != null) {
validation = "new " + validation + "(";
validation += getValidationParameters(a);
validation += ")";
validations.add(validation);
}
}
}
if (!validations.isEmpty()) {
map.put(p.getName(), validations);
}
}
return map;
}
else if ("validationRequires".equals(propertyName)) {
Set<String> requires = new HashSet<String>();
for (Property p : entity.getProperties()) {
List<Annotation> docAnnotations = p.getDocAnnotations();
if (docAnnotations != null) {
for (Annotation a : docAnnotations) {
String name = a.annotationType().getName();
String require = validationMap.get(name);
if (require != null) {
requires.add(require);
}
}
}
}
return requires;
}
return super.getProperty(interp, self, o, property, propertyName);
}
});
group.registerModelAdaptor(Property.class, new ObjectModelAdaptor() {
@Override
public Object getProperty(Interpreter interp, ST self, Object o,
Object property, String propertyName)
throws STNoSuchPropertyException {
Property p = (Property) o;
if ("docString".equals(propertyName)) {
String docString = jsDocString(p.getDocString());
List<String> enumValues = p.getType().getEnumValues();
if (enumValues == null && p.getType().getListElement() != null &&
p.getType().getListElement().getEnumValues() != null) {
enumValues = p.getType().getListElement().getEnumValues();
}
if (enumValues != null) {
docString = docString == null ? "" : docString;
docString += "\n\nPossible values: ";
for (int i = 0; i < enumValues.size(); i++) {
docString += enumValues.get(i);
if (i < enumValues.size() - 1) docString += ", ";
}
}
return docString;
}
else if ("jsType".equals(propertyName)) {
return jsTypeForType(p.getType());
}
else if ("listElementEnum".equals(propertyName)) {
if (p.getType() != null && p.getType().getListElement() != null &&
p.getType().getListElement().getEnumValues() != null) {
String enumVals = "";
int idx = 0;
for (String val : p.getType().getListElement().getEnumValues()) {
if (idx != 0) {
enumVals += ", ";
}
enumVals += val;
idx++;
}
return enumVals;
}
}
else if ("listElementKind".equals(propertyName)) {
if (p.getType().getListElement() != null &&
p.getType().getListElement().getName() != null) {
return (packageName + "." + upcase(p.getType().getListElement().toString()));
}
}
else if ("collectionName".equals(propertyName)) {
return collectionNameForProperty(p);
}
else if ("canonicalListElementKind".equals(propertyName)) {
if (p.getType().getListElement() != null) {
String collectionModelType = jsTypeForType(p.getType().getListElement());
Property implied = p.getImpliedProperty();
if (implied != null) {
return "function(attrs, options) {\n" +
" return new " + collectionModelType + "(\n" +
" _(attrs).extend({ " + implied.getName()
+ " : self }), options);\n" +
" }";
}
else {
return collectionModelType;