moduleprops now generally working for referredProps, too. Annotations for testing added to Customer. Added qualified field type.

This commit is contained in:
Purodha 2013-01-05 16:14:34 +00:00
parent c1f04434a0
commit 9b3192c230
2 changed files with 44 additions and 17 deletions

View File

@ -81,13 +81,14 @@ public class Customer extends AbstractEntity implements Serializable {
private Set<Contact> contacts; private Set<Contact> contacts;
@OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer") @OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
//@AnnFieldIO(referredProps = "customer") //@AnnFieldIO(referredProps = "customer")//gut
//@AnnFieldIO(referredProps = "customer.CustomersTariffl") //@AnnFieldIO(referredProps = "customer.CustomersTariff.domainDiscountUntil")//Das ist Kappes!
//@AnnFieldIO(referredProps = "customer.CustomersTariff.domainDiscountUntil") //@AnnFieldIO(referredProps = "customer.billData.domainDiscountUntil.year")//falsch!
@AnnFieldIO(referredProps = "customer.billData.domainDiscountUntil.cdate")//gut
private BankAccount bankAccount; private BankAccount bankAccount;
@OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer") @OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
//@AnnFieldIO(referredProps = "domainDiscountUntil") @AnnFieldIO(referredProps = "domainDiscountUntil")
private CustomersTariff billData; private CustomersTariff billData;
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "customer") @OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "customer")

View File

@ -51,11 +51,13 @@ public class ModulePropertiesRemote implements IRemote {
propertyProperties.put("rw", rw.name()); propertyProperties.put("rw", rw.name());
String[] referredProps = fieldIO.referredProps(); String[] referredProps = fieldIO.referredProps();
propertyProperties.put("referredProps", referredProps); propertyProperties.put("referredProps", referredProps);
Class<?> declaringClass = f.getDeclaringClass(); // Class<?> declaringClass = f.getDeclaringClass();
// declaringClass = f.getDeclaringClass();
for(String s : referredProps){ for(String s : referredProps){
String fullPropertyName = fieldName+"."+s; String fullPropertyName = fieldName+"."+s;
propertiesList.add(createReferredPropertyInfo(fullPropertyName, declaringClass, fullPropertyName)); propertiesList.add(createReferredPropertyInfo(fullPropertyName, f, s));
} }
AddCommonPropertyInfo(propertyProperties, f);
propertiesList.add(propertyProperties); propertiesList.add(propertyProperties);
} }
} }
@ -73,18 +75,42 @@ public class ModulePropertiesRemote implements IRemote {
} }
} }
private Map<String, Object> createReferredPropertyInfo(String fieldName, Class<?> declaringClass, private Map<String, Object> createReferredPropertyInfo(String propertyName, Field sourceField,
String propertyName) throws SecurityException, NoSuchFieldException { String annotated) throws SecurityException {
int indexOfDot = propertyName.indexOf('.'); Map<String, Object> result = new HashMap<String, Object>();
if (indexOfDot>=0) { result.put("property", propertyName);
String prefix = propertyName.substring(0, indexOfDot); // String trace = "" ;
String remainingPart = propertyName.substring(indexOfDot + 1); Field field = sourceField;
return createReferredPropertyInfo(fieldName, declaringClass.getDeclaredField(prefix).getDeclaringClass(), remainingPart); String remainingPart = annotated;
} else { int indexOfDot = 0;
Map<String, Object> result = new HashMap<String, Object>(); while (indexOfDot>=0) {
result.put("property", fieldName); indexOfDot = remainingPart.indexOf('.');
return result; Class<?> fieldType = field.getType();
String prefix = (indexOfDot>=0 ? remainingPart.substring(0, indexOfDot) : remainingPart);
try {
field = fieldType.getDeclaredField(prefix);
} catch (Exception NoSuchFieldException) {
Field[] flds = fieldType.getDeclaredFields();
String trace = indexOfDot
+ " SF=" + field.getName()
+" T=" + fieldType.getName()
+ " (" + flds.length +" fields):";
for (Field f : flds ){
trace = trace + " " + f.getName();
}
trace = trace + " [" + prefix + " missing]" ;
result.put("BOOM", trace);
return result;
}
// trace = trace + " TF=" + field.getName();
remainingPart = remainingPart.substring(indexOfDot + 1);
} }
AddCommonPropertyInfo(result, field);
return result;
}
private void AddCommonPropertyInfo(Map<String, Object> propertyInfo, Field sourceField) {
propertyInfo.put("type", sourceField.getType().getName());
} }
@Override @Override