if (test == null) {
m_testMethod = null;
} else {
m_testMethod = cf.getMethod(test, TEST_METHOD_SIGNATURES);
if (m_testMethod == null) {
throw new JiBXException("test-method " + test +
" not found in class " + cf.getName());
}
}
if (get == null) {
m_getMethod = null;
} else {
m_getMethod = cf.getMethod(get, GET_METHOD_SIGNATURES);
if (m_getMethod == null) {
throw new JiBXException("get-method " + get +
" not found in class " + cf.getName());
} else {
gtype = m_getMethod.getTypeName();
if (dtype == null) {
dtype = gtype;
}
}
}
if (set == null) {
m_setMethod = null;
} else {
// need to handle overloads, so generate possible signatures
ArrayList sigs = new ArrayList();
if (m_getMethod != null) {
String psig = ClassUtils.getSignature(gtype);
sigs.add("(" + psig +
"Lorg/jibx/runtime/IUnmarshallingContext;" + ")V");
sigs.add("(" + psig + ")V");
}
if (type != null) {
String psig = ClassUtils.getSignature(type);
sigs.add("(" + psig +
"Lorg/jibx/runtime/IUnmarshallingContext;" + ")V");
sigs.add("(" + psig + ")V");
}
if (m_fieldItem != null) {
String psig = m_fieldItem.getSignature();
sigs.add("(" + psig +
"Lorg/jibx/runtime/IUnmarshallingContext;" + ")V");
sigs.add("(" + psig + ")V");
}
sigs.add
("(Ljava/lang/Object;Lorg/jibx/runtime/IUnmarshallingContext;)V");
sigs.add("(Ljava/lang/Object;)V");
// set method needs verification of argument and return type
ClassItem setmeth = cf.getMethod(set,
(String[])sigs.toArray(new String[0]));
if (setmeth == null) {
// nothing known about signature, try anything by name
setmeth = cf.getMethod(set, "");
if (setmeth != null) {
if (!setmeth.getTypeName().equals("void") ||
setmeth.getArgumentCount() > 2) {
setmeth = null;
} else if (setmeth.getArgumentCount() == 2) {
String xtype = setmeth.getArgumentType(1);
if (!"org.jibx.runtime.IUnmarshallingContext".equals(xtype)) {
setmeth = null;
}
}
}
}
// check if method found
m_setMethod = setmeth;
if (m_setMethod == null) {
throw new JiBXException("set-method " + set +
" not found in class " + cf.getName());
} else {
stype = m_setMethod.getArgumentType(0);
if (dtype == null) {
dtype = stype;
}
}
}
if (flag == null) {
m_flagMethod = null;
} else {
m_flagMethod = cf.getMethod(flag, FLAG_METHOD_SIGNATURES);
if (m_flagMethod == null) {
throw new JiBXException("flag-method " + flag +
" not found in class " + cf.getName());
} else if (stype == null) {
stype = "java.lang.String";
if (dtype == null) {
dtype = stype;
}
}
}
if (gtype == null) {
gtype = "java.lang.Object";
}
m_getValueType = gtype;
m_setValueType = stype;
// check that enough information is supplied
BindingDefinition root = parent.getBindingRoot();
if (!isthis && m_fieldItem == null) {
if (root.isInput() && m_setMethod == null && m_flagMethod == null) {
throw new JiBXException
("Missing way to set value for input binding");
}
if (root.isOutput() && m_getMethod == null &&
(m_flagMethod == null || m_testMethod == null)) {
throw new JiBXException
("Missing way to get value for output binding");
}
}
// check that type information is consistent
if (type == null) {
m_typeName = dtype;
} else {
m_typeName = type;
boolean valid = true;
if (isthis) {
valid = ClassItem.isAssignable(dtype, type);
} else {
if (root.isInput()) {
valid = ClassItem.isAssignable(type, m_setValueType) ||
ClassItem.isAssignable(m_setValueType, type);
}
if (valid && root.isOutput()) {
valid = ClassItem.isAssignable(type, m_getValueType) ||
ClassItem.isAssignable(m_getValueType, type);
}
}
if (!valid) {
throw new JiBXException
("Incompatible types for property definition");
}
}
}