{
if (trace)
log.trace("Property " + property.getName() + " is a collection");
localModel = createCollection(localModel);
JBossXmlCollection xmlCol = property.getUnderlyingAnnotation(JBossXmlCollection.class);
if (xmlCol != null)
{
// this is the type that should be analyzed
propertyType = propertyType.getTypeInfoFactory().getTypeInfo(xmlCol.type());
}
}
// Is this property bound to a model group
else if (!property.getType().isPrimitive())
{
ClassInfo propClassInfo = (ClassInfo) property.getType();
// TODO XmlElement on this property?..
XmlElement propXmlElement = property.getUnderlyingAnnotation(XmlElement.class);
if (propXmlElement != null)
{
propClassInfo = (ClassInfo) propClassInfo.getTypeInfoFactory().getTypeInfo(propXmlElement.type());
}
JBossXmlModelGroup xmlModelGroup = propClassInfo.getUnderlyingAnnotation(JBossXmlModelGroup.class);
if (xmlModelGroup != null && xmlModelGroup.particles().length == 0)
{
if (trace)
log.trace("Property " + property.getName() + " is bound to " + xmlModelGroup.kind());
ModelGroupBinding propertyGroup = null;
QName groupName = null;
if (!JBossXmlConstants.DEFAULT.equals(xmlModelGroup.name()))
groupName = new QName(xmlModelGroup.name());
if (groupName != null)
propertyGroup = schemaBinding.getGroup(groupName);
if (propertyGroup == null)
{
if (xmlModelGroup.kind().equals(JBossXmlConstants.MODEL_GROUP_SEQUENCE))
{
propertyGroup = new SequenceBinding(schemaBinding);
}
else if (xmlModelGroup.kind().equals(JBossXmlConstants.MODEL_GROUP_CHOICE))
{
propertyGroup = new ChoiceBinding(schemaBinding);
}
else if (xmlModelGroup.kind().equals(JBossXmlConstants.MODEL_GROUP_ALL))
{
propertyGroup = new AllBinding(schemaBinding);
}
else
{
throw new IllegalStateException("Unexpected JBossXmlModelGroup.kind=" + xmlModelGroup.kind());
}
if (groupName != null)
{
// TODO what if it doesn't have a name? should an artificial one be created?
propertyGroup.setQName(groupName);
schemaBinding.addGroup(propertyGroup.getQName(), propertyGroup);
}
propertyGroup.setSkip(Boolean.FALSE);
// handler for the model group members
BeanInfo propBeanInfo = JBossXBBuilder.configuration.getBeanInfo(propClassInfo);
BeanAdapterFactory propBeanAdapterFactory = null;
try
{
// TODO this has to use its own adapter class and the factory method
BeanInfo propBeanAdapterBuilderInfo = JBossXBBuilder.configuration
.getBeanInfo(DefaultBeanAdapterBuilder.class);
BeanAdapterBuilder propBeanAdapterBuilder = (BeanAdapterBuilder) propBeanAdapterBuilderInfo
.newInstance();
propBeanAdapterFactory = propBeanAdapterBuilder.newFactory(propBeanInfo, null);
}
catch (Throwable t)
{
throw new RuntimeException("Error creating BeanAdapterFactory for "
+ DefaultBeanAdapterBuilder.class.getName(), t);
}
BeanHandler propHandler = new BeanHandler(propBeanInfo.getName(), propBeanAdapterFactory);
propertyGroup.setHandler(propHandler);
String[] memberOrder = xmlModelGroup.propOrder();
if (memberOrder.length == 0 || memberOrder[0].length() == 0)
{
List<String> propNames = new ArrayList<String>();
for (PropertyInfo prop : propBeanInfo.getProperties())
{
propNames.add(prop.getName());
}
memberOrder = propNames.toArray(new String[propNames.size()]);
}
if (trace)
log.trace("Property order for " + xmlModelGroup.kind() + " property " + property.getName() + ": "
+ Arrays.asList(memberOrder));
// bind model group members
for (String memberPropName : memberOrder)
{
if ("class".equals(memberPropName))
{
continue;
}
PropertyInfo memberProp = propBeanInfo.getProperty(memberPropName);
TypeInfo memberTypeInfo = memberProp.getType();
String memberNamespace = null;
JBossXmlNsPrefix nsPrefix = memberProp.getUnderlyingAnnotation(JBossXmlNsPrefix.class);
if (nsPrefix != null)
{
memberNamespace = schemaBinding.getNamespace(nsPrefix.prefix());
if (memberNamespace == null && nsPrefix.schemaTargetIfNotMapped())
{
throw new IllegalStateException("Prefix '" + nsPrefix.prefix()
+ "' is not mapped to any namespace!");
}
}
String memberName = null;
XmlElement memberXmlElement = memberProp.getUnderlyingAnnotation(XmlElement.class);
if (memberXmlElement != null)
{
if (!XmlElement.DEFAULT.class.equals(memberXmlElement.type()))
{
memberTypeInfo = memberTypeInfo.getTypeInfoFactory().getTypeInfo(memberXmlElement.type());
}
if (memberNamespace == null)
memberNamespace = memberXmlElement.namespace();
memberName = memberXmlElement.name();
}
if (memberNamespace == null)
{
memberNamespace = defaultNamespace;
}
boolean isCol = false;
AbstractPropertyHandler memberPropertyHandler = null;
if (memberProp.getType().isCollection())
{
memberPropertyHandler = new CollectionPropertyHandler(memberProp, memberProp.getType());
isCol = true;
// if memberXmlElement is present then the collection item type is set explicitly
if (memberXmlElement == null || XmlElement.DEFAULT.class.equals(memberXmlElement.type()))
{
JBossXmlCollection jbossXmlCollection = memberProp
.getUnderlyingAnnotation(JBossXmlCollection.class);
if (jbossXmlCollection != null)
{
memberTypeInfo = memberTypeInfo.getTypeInfoFactory().getTypeInfo(jbossXmlCollection.type());
}
memberTypeInfo = findComponentType((ClassInfo) memberTypeInfo);
}
}
// if it is bound with XmlElement.type to a collection