log.trace("newChild " + namespaceURI + ":" + localName + " for " + parent);
}
Object child;
ElementBinding metadata = (ElementBinding)ctx.getMetadata();
if(metadata == null)
{
throw new JBossXBRuntimeException(
"Binding metadata is not available for element {" + namespaceURI + ":" + localName + "}"
);
}
if(Collection.class.isAssignableFrom(metadata.getJavaType()))
{
Collection col;
if(parent instanceof Immutable)
{
Immutable imm = (Immutable)parent;
col = (Collection)imm.getChild(localName);
if(col == null)
{
col = (Collection)newInstance(metadata);
imm.addChild(localName, col);
}
}
else
{
col = (Collection)getFieldValue(metadata, parent);
if(col == null)
{
col = (Collection)newInstance(metadata);
setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, col);
}
}
child = col;
}
else if(!Util.isAttributeType(metadata.getJavaType()))
{
child = newInstance(metadata);
if(!(child instanceof Immutable))
{
if(parent instanceof Collection)
{
((Collection)parent).add(child);
}
else if(parent instanceof Immutable)
{
((Immutable)parent).addChild(localName, child);
}
else if(metadata.getFieldType() != null && Collection.class.isAssignableFrom(metadata.getFieldType()))
{
Collection col = (Collection)getFieldValue(metadata, parent);
if(col == null)
{
if(Set.class.isAssignableFrom(metadata.getFieldType()))
{
col = new HashSet();
}
else
{
col = new ArrayList();
}
setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, col);
}
col.add(child);
}
else
{
setFieldValue(metadata.getName(), metadata.getField(), metadata.getSetter(), parent, child);
}
}
if(attrs != null && attrs.getLength() > 0)
{
for(int i = 0; i < attrs.getLength(); ++i)
{
QName attrName = new QName(attrs.getURI(i), attrs.getLocalName(i));
AttributeBinding attrBinding = metadata.getAttribute(attrName);
if(attrBinding != null)
{
Object unmarshalledValue = SimpleTypeBindings.unmarshal(attrs.getValue(i),
attrBinding.getJavaType()
);