if (trace)
log.trace("SequenceBinding for type=" + beanInfo.getName());
model = new SequenceBinding(schemaBinding);
}
model.setHandler(BuilderParticleHandler.INSTANCE);
ParticleBinding typeParticle = new ParticleBinding(model);
typeParticle.setMinOccurs(1);
typeParticle.setMaxOccurs(1);
typeBinding.setParticle(typeParticle);
if (typeInfo.isCollection())
{
TypeInfo memberBaseType = ((ClassInfo)typeInfo).getComponentType();
JBossXmlModelGroup xmlModelGroup = ((ClassInfo) memberBaseType)
.getUnderlyingAnnotation(JBossXmlModelGroup.class);
if (xmlModelGroup != null && xmlModelGroup.particles().length > 0)
{
if (trace)
log.trace("Item base type for " + typeInfo.getName() + " is " + memberBaseType.getName()
+ " and bound to repeatable choice");
// it's choice by default based on the idea that the
// type parameter is a base class for items
ModelGroupBinding choiceGroup = null;
QName choiceName = null;
if(!JBossXmlConstants.DEFAULT.equals(xmlModelGroup.name()))
{
choiceName = new QName(defaultNamespace, xmlModelGroup.name());
choiceGroup = schemaBinding.getGroup(choiceName);
}
if(choiceGroup == null)
{
choiceGroup = new ChoiceBinding(schemaBinding);
choiceGroup.setHandler(BuilderParticleHandler.INSTANCE);
if (choiceName != null)
{
choiceGroup.setQName(choiceName);
schemaBinding.addGroup(choiceGroup.getQName(), choiceGroup);
}
ParticleBinding choiceParticle = new ParticleBinding(choiceGroup, 0, 1, true);
model.addParticle(choiceParticle);
for (JBossXmlModelGroup.Particle member : xmlModelGroup.particles())
{
XmlElement element = member.element();
QName memberQName = generateXmlName(element.name(), XmlNsForm.QUALIFIED, element.namespace(), null);
TypeInfo memberTypeInfo = typeInfo.getTypeInfoFactory().getTypeInfo(member.type());
boolean isCol = false;
if (memberTypeInfo.isCollection())
{
memberTypeInfo = ((ClassInfo) memberTypeInfo).getComponentType();
isCol = true;
}
TypeBinding memberTypeBinding = resolveTypeBinding(memberTypeInfo);
ElementBinding memberElement = createElementBinding(memberTypeInfo, memberTypeBinding, memberQName, false);
memberElement.setNillable(true);
ParticleBinding memberParticle = new ParticleBinding(memberElement, 0, 1, isCol);
choiceGroup.addParticle(memberParticle);
typeBinding.pushInterceptor(memberQName, ChildCollectionInterceptor.SINGLETON);
}
}
else
{
ParticleBinding choiceParticle = new ParticleBinding(choiceGroup, 0, 1, true);
model.addParticle(choiceParticle);
}
if (trace)
log.trace("choices for " + typeBinding.getQName() + ": " + choiceGroup.getParticles());
}
}
// Determine the wildcard handler
AbstractPropertyHandler wildcardHandler = null;
if (wildcardProperty != null)
{
TypeInfo wildcardType = wildcardProperty.getType();
if (wildcardType.isCollection())
wildcardHandler = new CollectionPropertyWildcardHandler(wildcardProperty, wildcardType);
else
wildcardHandler = new PropertyWildcardHandler(wildcardProperty, wildcardType);
}
// Look through the properties
for (String name : propertyOrder)
{
// Setup the error stack
push(typeInfo, name);
// Get the property
PropertyInfo property = beanInfo.getProperty(name);
bindProperty(property, typeBinding, model, beanAdapterFactory, propertyOrder);
pop();
}
// Bind the children
JBossXmlChild[] children = null;
JBossXmlChildren jbossXmlChildren = typeInfo.getUnderlyingAnnotation(JBossXmlChildren.class);
if (jbossXmlChildren != null)
children = jbossXmlChildren.value();
else
{
JBossXmlChild jbossXmlChild = typeInfo.getUnderlyingAnnotation(JBossXmlChild.class);
if (jbossXmlChild != null)
children = new JBossXmlChild[] { jbossXmlChild };
}
if (children != null && children.length > 0)
{
for (JBossXmlChild child : children)
{
QName qName = generateXmlName(child.name(), elementForm, child.namespace(), child.name());
TypeInfo childType = JBossXBBuilder.configuration.getTypeInfo(child.type());
TypeBinding elementTypeBinding = resolveTypeBinding(childType);
ElementBinding elementBinding = createElementBinding(childType, elementTypeBinding, qName, false);
// Bind it to the model
ParticleBinding particle = new ParticleBinding(elementBinding, child.minOccurs(), child.maxOccurs(), child.unbounded());
model.addParticle(particle);
if(childType.isMap())
bindMapProperty(null, (ClassInfo) childType, elementTypeBinding.getQName(), (ModelGroupBinding) elementTypeBinding.getParticle().getTerm());
DefaultElementInterceptor interceptor = null;
if (typeInfo.isCollection())
interceptor = ChildCollectionInterceptor.SINGLETON;
else
{
// Expect a type with a value property to accept the child value
PropertyInfo property = beanInfo.getProperty("value");
if (property == null)
throw new UnsupportedOperationException("Expected a value property for non-collection type with JBossXmlChildren");
TypeInfo propertyType = property.getType();
interceptor = new PropertyInterceptor(property, propertyType);
}
typeBinding.pushInterceptor(qName, interceptor);
if (trace)
log.trace("Added interceptor " + qName + " for type=" + childType + " interceptor=" + interceptor);
}
}
// Bind the wildcard
if (wildcardProperty != null)
{
if (trace)
log.trace("Processing WildcardProperty for type=" + beanInfo.getName() + " property=" + wildcardProperty.getName());
ModelGroupBinding localModel = model;
TypeInfo wildcardType = wildcardProperty.getType();
TypeInfo type = wildcardType;
// Setup any new model and determine the wildcard type
if (wildcardType.isArray())
{
localModel = createArray(localModel);
type = ((ArrayInfo) wildcardType).getComponentType();
if (trace)
log.trace("Wildcard " + wildcardProperty.getName() + " is an array of type " + type.getName());
}
else if (wildcardType.isCollection())
{
localModel = createCollection(localModel);
type = ((ClassInfo)wildcardProperty.getType()).getComponentType();
if (trace)
log.trace("Wildcard " + wildcardProperty.getName() + " is a collection of type " + type.getName());
}
XmlAnyElement xmlAnyElement = wildcardProperty.getUnderlyingAnnotation(XmlAnyElement.class);
boolean isLax = xmlAnyElement == null ? true : xmlAnyElement.lax();
WildcardBinding wildcard = new WildcardBinding(schemaBinding);
if (isLax)
wildcard.setProcessContents((short) 3); // Lax
else
wildcard.setProcessContents((short) 1); // Strict
// Dom element?
if (Element.class.getName().equals(type.getName()))
{
wildcard.setUnresolvedElementHandler(DOMHandler.INSTANCE);
wildcard.setUnresolvedCharactersHandler(DOMHandler.INSTANCE);
}
// Bind the particle to the model
ParticleBinding particleBinding = new ParticleBinding(wildcard);
particleBinding.setMinOccurs(0);
particleBinding.setMaxOccurs(1);
localModel.addParticle(particleBinding);
typeBinding.getWildcard().setWildcardHandler((ParticleHandler) wildcardHandler);
beanAdapterFactory.setWildcardHandler(wildcardHandler);
}
JBossXmlChildWildcard childWildcard = typeInfo.getUnderlyingAnnotation(JBossXmlChildWildcard.class);
if (childWildcard != null)
{
if (beanAdapterFactory.getWildcardHandler() != null)
throw new RuntimeException("Cannot have both @JBossXmlChildWildcard and @XmlAnyElement");
ParticleHandler childWildcardHandler = null;
if (typeInfo.isCollection())
{
if (childWildcard.wrapper() != Object.class)
{
BeanInfo wrapperInfo = JBossXBBuilder.configuration.getBeanInfo(childWildcard.wrapper());
childWildcardHandler = new ChildCollectionWildcardHandler(wrapperInfo, childWildcard.property());
}
else
childWildcardHandler = ChildCollectionWildcardHandler.SINGLETON;
}
else
throw new UnsupportedOperationException("TODO");
WildcardBinding wildcard = new WildcardBinding(schemaBinding);
if (childWildcard.lax())
wildcard.setProcessContents((short) 3); // Lax
else
wildcard.setProcessContents((short) 1); // Strict
ParticleBinding particleBinding = new ParticleBinding(wildcard);
particleBinding.setMinOccurs(0);
particleBinding.setMaxOccurs(1);
model.addParticle(particleBinding);
typeBinding.getWildcard().setWildcardHandler(childWildcardHandler);
}