public String generateAnnTypeAnnotation(final POJOClass pojoClass, final Property property) {
final Type type = property.getType();
if (type instanceof CustomType) {
StringBuilder annotationStringBuilder = new StringBuilder();
annotationStringBuilder.append(" @").append(pojoClass.importType("org.hibernate.annotations.Type"))
.append("(type=\"").append(type.getName()).append("\"");
Properties typeProperties = null;
Value val = property.getValue();
if (val instanceof SimpleValue)
typeProperties = ((SimpleValue) val).getTypeParameters();
else if (val instanceof Collection)
typeProperties = ((Collection) val).getTypeParameters();
if (typeProperties != null && !typeProperties.isEmpty()) {
annotationStringBuilder.append(", parameters = { ");
for (Iterator<Entry<Object, Object>> iterator = typeProperties.entrySet().iterator(); iterator.hasNext();) {
Entry<Object, Object> param = iterator.next();
annotationStringBuilder.append("@").append(pojoClass.importType("org.hibernate.annotations.Parameter"))
.append("(name = \"").append(param.getKey().toString()).append("\", value = \"")
.append(param.getValue()).append("\")");
if (iterator.hasNext())
annotationStringBuilder.append(", ");
}
annotationStringBuilder.append(" }");
}
annotationStringBuilder.append(")");
return annotationStringBuilder.toString();
}
else {
return "";
}
}