* @param ep the element property
* @param compositor the schema compositor (sequence or all)
*/
private void handleElementProp(ElementPropertyInfo<T,C> ep, ExplicitGroup compositor) {
QName ename = ep.getXmlName();
Occurs occurs = null;
if (ep.isValueList()) {
TypeRef<T,C> t = ep.getTypes().get(0);
LocalElement e = compositor.element();
QName tn = t.getTagName();
e.name(tn.getLocalPart());
List lst = e.simpleType().list();
writeTypeRef(lst,t, "itemType");
elementFormDefault.writeForm(e,tn);
return;
}
if (ep.isCollection()) {
if (ename != null) { // wrapped collection
LocalElement e = compositor.element();
if(ename.getNamespaceURI().length()>0) {
if (!ename.getNamespaceURI().equals(this.uri)) {
// TODO: we need to generate the corresponding element declaration for this
// table 8-25: Property/field element wrapper with ref attribute
e.ref(new QName(ename.getNamespaceURI(), ename.getLocalPart()));
return;
}
}
elementFormDefault.writeForm(e,ename);
ComplexType p = e.name(ename.getLocalPart()).complexType();
if(ep.isCollectionNillable()) {
e.nillable(true);
} else {
e.minOccurs(0);
}
if (ep.getTypes().size() == 1) {
compositor = p.sequence();
} else {
compositor = p.choice();
occurs = compositor;
}
} else { // unwrapped collection
if (ep.getTypes().size() > 1) {
compositor = compositor.choice();
occurs = compositor;
}
}
} else {
if (ep.getTypes().size() > 1) {
compositor = compositor.choice();
occurs = compositor;
}
}
// fill in the content model
for (TypeRef<T,C> t : ep.getTypes()) {
LocalElement e = compositor.element();
if (occurs == null) occurs = e;
QName tn = t.getTagName();
if(canBeDirectElementRef(t,tn) || (!tn.getNamespaceURI().equals(uri) && tn.getNamespaceURI().length()>0)) {
e.ref(tn);
} else {
e.name(tn.getLocalPart());
writeTypeRef(e,t, "type");
elementFormDefault.writeForm(e,tn);
}
if (t.isNillable()) {
e.nillable(true);
}
if(t.getDefaultValue()!=null)
e._default(t.getDefaultValue());
}
if (ep.isCollection())
occurs.maxOccurs("unbounded");
if (!ep.isRequired())
// see Spec table 8-13
occurs.minOccurs(0);
// else minOccurs defaults to 1
}