private Tree handleElementProp(final ElementPropertyInfo<T,C> ep) {
if (ep.isValueList()) {
return new Tree.Term() {
protected void write(ContentModelContainer parent, boolean isOptional, boolean repeated) {
TypeRef<T,C> t = ep.getTypes().get(0);
LocalElement e = parent.element();
e.block(); // we will write occurs later
QName tn = t.getTagName();
e.name(tn.getLocalPart());
List lst = e.simpleType().list();
writeTypeRef(lst,t, "itemType");
elementFormDefault.writeForm(e,tn);
writeOccurs(e,isOptional||!ep.isRequired(),repeated);
}
};
}
ArrayList<Tree> children = new ArrayList<Tree>();
for (final TypeRef<T,C> t : ep.getTypes()) {
children.add(new Tree.Term() {
protected void write(ContentModelContainer parent, boolean isOptional, boolean repeated) {
LocalElement e = parent.element();
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());
writeOccurs(e,isOptional,repeated);
}
});
}
final Tree choice = Tree.makeGroup(GroupKind.CHOICE, children)
.makeOptional(!ep.isRequired())
.makeRepeated(ep.isCollection()); // see Spec table 8-13
final QName ename = ep.getXmlName();
if (ename != null) { // wrapped collection
return new Tree.Term() {
protected void write(ContentModelContainer parent, boolean isOptional, boolean repeated) {
LocalElement e = parent.element();
if(ename.getNamespaceURI().length()>0) {
if (!ename.getNamespaceURI().equals(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;
}
}
e.name(ename.getLocalPart());
elementFormDefault.writeForm(e,ename);
if(ep.isCollectionNillable()) {
e.nillable(true);
}
writeOccurs(e,!ep.isCollectionRequired(),repeated);
ComplexType p = e.complexType();
choice.write(p);
}
};
} else {// non-wrapped
return choice;