}
}
protected Set<PropertyInfo> getExpectedProperties(Class<?> clazz, BeanAccessMode mode)
{
TypeInfoFactory factory = getTypeInfoFactory();
Method[] methods = clazz.getMethods();
HashMap<String, Method> getters = new HashMap<String, Method>();
HashMap<String, List<Method>> setters = new HashMap<String, List<Method>>();
if (methods.length > 0)
{
for (Method method : methods)
{
String name = method.getName();
if (isGetter(method))
{
String upperName = getUpperPropertyName(name);
getters.put(upperName, method);
}
else if (isSetter(method))
{
String upperName = getUpperPropertyName(name);
List<Method> list = setters.get(upperName);
if (list == null)
{
list = new ArrayList<Method>();
setters.put(upperName, list);
}
list.add(method);
}
}
}
Map<String, PropertyInfo> properties = new HashMap<String, PropertyInfo>();
if (getters.isEmpty() == false)
{
for (Iterator<Map.Entry<String, Method>> i = getters.entrySet().iterator(); i.hasNext();)
{
Map.Entry<String, Method> entry = i.next();
String name = entry.getKey();
Method getter = entry.getValue();
Method setter = null;
List<Method> setterList = setters.remove(name);
if (setterList != null && setterList.size() != 0)
{
for (int j = 0; j < setterList.size(); ++j)
{
Method thisSetter = setterList.get(j);
Type pinfo = thisSetter.getGenericParameterTypes()[0];
if (getter.getGenericReturnType().equals(pinfo) == true)
{
setter = thisSetter;
break;
}
}
}
String lowerName = getLowerPropertyName(name);
// Merge the annotations between the getters and setters
Set<AnnotationValue> getterAnnotations = getExpectedAnnotations(getter.getAnnotations());
Set<AnnotationValue> setterAnnotations = null;
if (setter != null)
setterAnnotations = getExpectedAnnotations(setter.getAnnotations());
AnnotationValue[] annotations = getterAnnotations.toArray(new AnnotationValue[getterAnnotations.size()]);
if (annotations == null || annotations.length == 0)
{
if (setterAnnotations != null)
annotations = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
}
else if (setterAnnotations != null && setterAnnotations.size() > 0)
{
HashSet<AnnotationValue> merged = new HashSet<AnnotationValue>();
merged.addAll(getterAnnotations);
merged.addAll(setterAnnotations);
annotations = merged.toArray(new AnnotationValue[merged.size()]);
}
TypeInfo type = factory.getTypeInfo(getter.getGenericReturnType());
ClassInfo declaringType = (ClassInfo) factory.getTypeInfo(getter.getDeclaringClass());
MethodInfo getterInfo = new MethodInfoImpl(null, getter.getName(), type, new TypeInfo[0], null, null, getter.getModifiers(), declaringType);
MethodInfo setterInfo = null;
if (setter != null)
{
declaringType = (ClassInfo) factory.getTypeInfo(setter.getDeclaringClass());
AnnotationValue[][] paramAnnotations = new AnnotationValue[1][];
setterAnnotations = getExpectedAnnotations(setter.getParameterAnnotations()[0]);
paramAnnotations[0] = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
setterInfo = new MethodInfoImpl(null, setter.getName(), PrimitiveInfo.VOID, new TypeInfo[] { type }, paramAnnotations, null, setter.getModifiers(), declaringType);
}
properties.put(lowerName, new DefaultPropertyInfo(lowerName, name, type, getterInfo, setterInfo, annotations));
}
}
if (setters.isEmpty() == false)
{
for (Iterator<Map.Entry<String, List<Method>>> i = setters.entrySet().iterator(); i.hasNext();)
{
Map.Entry<String, List<Method>> entry = i.next();
String name = entry.getKey();
List<Method> setterList = entry.getValue();
// TODO JBMICROCONT-125 Maybe should just create duplicate propertyInfo and let the configurator guess?
if (setterList.size() == 1)
{
Method setter = setterList.get(0);
Type pinfo = setter.getGenericParameterTypes()[0];
TypeInfo type = factory.getTypeInfo(pinfo);
String lowerName = getLowerPropertyName(name);
Set<AnnotationValue> setterAnnotations = getExpectedAnnotations(setter.getAnnotations());
AnnotationValue[] annotations = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
ClassInfo declaringType = (ClassInfo) factory.getTypeInfo(setter.getDeclaringClass());
AnnotationValue[][] paramAnnotations = new AnnotationValue[1][];
setterAnnotations = getExpectedAnnotations(setter.getParameterAnnotations()[0]);
paramAnnotations[0] = setterAnnotations.toArray(new AnnotationValue[setterAnnotations.size()]);
MethodInfo setterInfo = new MethodInfoImpl(null, setter.getName(), PrimitiveInfo.VOID, new TypeInfo[] { type }, paramAnnotations, null, setter.getModifiers(), declaringType);
properties.put(lowerName, new DefaultPropertyInfo(lowerName, name, type, null, setterInfo, annotations));
}
}
}
if (mode != BeanAccessMode.STANDARD)
{
ClassInfo classInfo = (ClassInfo)factory.getTypeInfo(clazz);
Set<FieldInfo> fields = getFields(classInfo, mode);
for(FieldInfo field : fields)
{
String name = field.getName();
PropertyInfo pi = properties.get(name);