m_usage = vctx.getParentElement().getDefaultStyle();
}
// handle basic lookups and checks
ContainerElementBase parent = vctx.getParentContainer();
IClass cobj = parent.getChildObjectType();
String dtype = null;
String gtype = null;
String stype = null;
boolean err = false;
m_isImplicit = true;
if (m_fieldName != null) {
// field means this is real (not implicit)
m_isImplicit = false;
if (vctx.isLookupSupported()) {
// look up the field information
m_fieldItem = cobj.getField(m_fieldName);
if (m_fieldItem == null) {
vctx.addFatal("Nonstatic field " + m_fieldName +
" not found in class " + cobj.getName());
err = true;
} else {
dtype = gtype = stype = m_fieldItem.getTypeName();
}
}
}
if (m_testName != null) {
// make sure only used with optional
if (m_usage == REQUIRED_USAGE) {
vctx.addError("test-method can only be used with optional property");
} else if (vctx.isLookupSupported()) {
// look up the method information
m_testItem = cobj.getMethod(m_testName, TEST_METHOD_SIGNATURES);
if (m_testItem == null) {
vctx.addError("Nonstatic test-method " + m_testName +
" not found in class " + cobj.getName());
}
}
}
if (m_flagName != null) {
// flag-method means this is real (not implicit)
m_isImplicit = false;
stype = "java.lang.Object";
if (m_testName != null) {
gtype = stype;
}
if (vctx.isLookupSupported()) {
// look up the method information
m_flagItem = cobj.getMethod(m_flagName, FLAG_METHOD_SIGNATURES);
if (m_flagItem == null) {
vctx.addError("Nonstatic flag-method " + m_flagName +
" not found in class " + cobj.getName());
}
}
}
if (m_getName != null) {
// get-method means this is real (not implicit)
m_isImplicit = false;
if (vctx.isLookupSupported()) {
// look up the get method by name (no overload possible)
m_getItem = cobj.getMethod(m_getName, GET_METHOD_SIGNATURES);
if (m_getItem == null) {
vctx.addFatal("Nonstatic get-method " + m_getName +
" not found in class " + cobj.getName());
err = true;
} else {
gtype = m_getItem.getTypeName();
if (dtype == null) {
dtype = gtype;
}
}
}
// check for only get-method supplied when both directions needed
if (vctx.isInBinding() && m_fieldName == null &&
m_setName == null) {
vctx.addError("Need field or set-method for input handling");
}
}
if (m_setName != null) {
// set-method means this is real (not implicit)
m_isImplicit = false;
if (vctx.isLookupSupported()) {
// need to handle overloads, so generate possible signatures
ArrayList sigs = new ArrayList();
if (m_getItem != null) {
String psig = ClassUtils.getSignature(gtype);
sigs.add("(" + psig +
"Lorg/jibx/runtime/IUnmarshallingContext;" + ")V");
sigs.add("(" + psig + ")V");
}
if (m_declaredType != null) {
String psig = ClassUtils.getSignature(m_declaredType);
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");
// match any of the possible signatures
m_setItem = cobj.getMethod(m_setName,
(String[])sigs.toArray(new String[0]));
if (m_setItem == null) {
// nothing known about signature, try anything by name
m_setItem = cobj.getMethod(m_setName, "");
if (m_setItem != null) {
if (!m_setItem.getTypeName().equals("void") ||
m_setItem.getArgumentCount() > 2) {
m_setItem = null;
} else if (m_setItem.getArgumentCount() == 2) {
String xtype = m_setItem.getArgumentType(1);
if (!"org.jibx.runtime.IUnmarshallingContext".equals(xtype)) {
m_setItem = null;
}
}
}
if (m_setItem != null) {
// make sure resulting type is compatible
String type = m_setItem.getArgumentType(0);
if (m_declaredType != null &&
!ClassUtils.isAssignable(m_declaredType, type, vctx)) {
m_setItem = null;
} else if (dtype != null &&
!ClassUtils.isAssignable(type, dtype, vctx)) {
m_setItem = null;
} else if (gtype != null &&
!ClassUtils.isAssignable(type, gtype, vctx)) {
m_setItem = null;
}
if (m_setItem != null) {
dtype = type;
}
}
}
// check set-method found
if (m_setItem == null) {
vctx.addFatal("Nonstatic set-method " + m_setName +
" with argument of appropriate type not found in class " +
cobj.getName());
err = true;
} else {
stype = m_setItem.getArgumentType(0);
if (dtype == null) {
dtype = stype;
}
}
}
// check for only set-method supplied when both directions needed
if (vctx.isOutBinding() && m_fieldName == null &&
m_getName == null) {
vctx.addError("Need field or get-method for output handling");
}
}
// set the property type information
String tname = m_declaredType;
if (tname == null) {
tname = dtype;
if (tname == null) {
tname = cobj.getName();
}
} else if (dtype == null) {
dtype = gtype = stype = tname;
}
m_type = vctx.getClassInfo(tname);