{
((Collection)owner).add(o);
}
else
{
PutMethodMetaData putMethodMetaData = element.getPutMethodMetaData();
if(owner instanceof Map || putMethodMetaData != null)
{
MapEntryMetaData mapEntryMetaData = element.getMapEntryMetaData();
if(mapEntryMetaData == null)
{
throw new JBossXBRuntimeException((owner instanceof Map ?
"Parent object is an instance of java.util.Map" :
"putMethod is specified for element " + qName
) +
" but mapEntry is specified for neither element " +
qName +
" nor it's type " +
element.getType().getQName()
);
}
Class oClass = o.getClass();
String getKeyMethodName = mapEntryMetaData.getGetKeyMethod();
if(getKeyMethodName == null)
{
getKeyMethodName = "getKey";
}
Method keyMethod;
try
{
keyMethod = oClass.getMethod(getKeyMethodName, null);
}
catch(NoSuchMethodException e)
{
throw new JBossXBRuntimeException("setParent failed for " +
qName +
"=" +
o +
": getKeyMethod=" +
getKeyMethodName +
" not found in " + oClass
);
}
Object key;
try
{
key = keyMethod.invoke(o, null);
}
catch(Exception e)
{
throw new JBossXBRuntimeException("setParent failed for " +
qName +
"=" +
o +
": getKeyMethod=" +
getKeyMethodName +
" threw an exception: " + e.getMessage(), e
);
}
Class keyType = Object.class;
Class valueType = Object.class;
String putMethodName = "put";
Class ownerClass = owner.getClass();
if(putMethodMetaData != null)
{
if(putMethodMetaData.getKeyType() != null)
{
try
{
keyType =
Thread.currentThread().getContextClassLoader().loadClass(putMethodMetaData.getKeyType());
}
catch(ClassNotFoundException e)
{
throw new JBossXBRuntimeException("setParent failed for " + qName + ": " + e.getMessage(), e);
}
}
if(putMethodMetaData.getValueType() != null)
{
try
{
valueType =
Thread.currentThread().getContextClassLoader().loadClass(putMethodMetaData.getValueType());
}
catch(ClassNotFoundException e)
{
throw new JBossXBRuntimeException("setParent failed for " + qName + ": " + e.getMessage(), e);
}
}
String name = putMethodMetaData.getName();
if(name != null)
{
putMethodName = name;
}
}