use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class TableAccessor method setupColumns.
private void setupColumns(List<Column> columns, List<Column> pkColumns, PrimaryKey pk) {
int i = 0;
for (Column current : columns) {
boolean inPk = pkColumns.contains(current);
PropertyAccessor nestedPropertyAccessor;
if (javaClassAccessor == null) {
nestedPropertyAccessor = null;
} else {
String propertyName = current.getActualPropertyName();
try {
nestedPropertyAccessor = javaClassAccessor.getProperty(propertyName);
} catch (NoSuchFieldException e) {
nestedPropertyAccessor = null;
logger.error("Could not access nested property: " + propertyName, e);
}
}
boolean autoGenerated = inPk && (pk.getPrimaryKeyColumns().get(0).getGenerator() != null);
ColumnAccessor columnAccessor = new ColumnAccessor(current, inPk, autoGenerated, nestedPropertyAccessor);
columnAccessors[i] = columnAccessor;
i++;
}
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class PkHelper method getPrimaryKey.
// **************************************************************************
// Methods
// **************************************************************************
public Serializable getPrimaryKey(String... params) {
int i = 0;
Serializable result = (Serializable) classAccessor.newInstance();
if (params.length != classAccessor.getKeyProperties().length) {
throw new RuntimeException("Wrong number of parameters for primary key: expected " + classAccessor.getKeyProperties().length + ", got " + params.length);
}
for (PropertyAccessor property : classAccessor.getKeyProperties()) {
String stringValue = params[i];
Object value = OgnlUtils.convertValue(stringValue, property.getType());
property.set(result, value);
i++;
}
return result;
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class ShortNameUtils method getName.
public static String getName(ClassAccessor classAccessor, Object object) {
ShortName annotation = classAccessor.getAnnotation(ShortName.class);
String formatString;
if (annotation == null) {
StringBuilder sb = new StringBuilder();
boolean first = true;
// sintetizziamo una stringa a partire dalla chiave primaria
for (PropertyAccessor propertyAccessor : classAccessor.getKeyProperties()) {
if (first) {
first = false;
} else {
sb.append(PK_ELEMENT_SEPARATOR);
}
sb.append(String.format("%%{%s}", propertyAccessor.getName()));
}
formatString = sb.toString();
} else {
formatString = annotation.value();
}
OgnlTextFormat ognlTextFormat = OgnlTextFormat.create(formatString);
return ognlTextFormat.format(object);
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class FormBuilder method configFields.
public FormBuilder configFields(String[]... groupedFieldNames) {
logger.debug("configFields", groupedFieldNames);
groupedPropertyAccessors = new ArrayList<ArrayList<PropertyAccessor>>();
for (String[] currentNameGroup : groupedFieldNames) {
ArrayList<PropertyAccessor> currentPropertyGroup = new ArrayList<PropertyAccessor>();
groupedPropertyAccessors.add(currentPropertyGroup);
for (String currentField : currentNameGroup) {
try {
PropertyAccessor accessor = classAccessor.getProperty(currentField);
currentPropertyGroup.add(accessor);
} catch (NoSuchFieldException e) {
logger.warn("Field not found: {}" + currentField, e);
}
}
}
return this;
}
use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.
the class FormBuilder method buildFieldGroup.
protected void buildFieldGroup(Form form, int i, Map<String, Field> fieldMap) {
ArrayList<PropertyAccessor> group = groupedPropertyAccessors.get(i);
String fieldSetName;
if (fieldSetNames == null) {
fieldSetName = null;
} else {
fieldSetName = fieldSetNames.get(i);
}
com.manydesigns.elements.forms.FieldSet fieldSet = new com.manydesigns.elements.forms.FieldSet(fieldSetName, nColumns, mode);
form.add(fieldSet);
for (PropertyAccessor propertyAccessor : group) {
buildField(fieldSet, propertyAccessor, fieldMap);
}
}
Aggregations