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();
PropertyInfo propInfo = t.getSource();
TypeInfo parentInfo = (propInfo == null) ? null : propInfo.parent();
if (canBeDirectElementRef(t, tn, parentInfo)) {
if ((!t.getTarget().isSimpleType()) && (t.getTarget() instanceof ClassInfo) && collisionChecker.findDuplicate((ClassInfo<T, C>) t.getTarget())) {
e.ref(new QName(uri, tn.getLocalPart()));
} else {
QName elemName = null;
if (t.getTarget() instanceof Element) {
Element te = (Element) t.getTarget();
elemName = te.getElementName();
}
Collection<TypeInfo> refs = propInfo.ref();
TypeInfo ti;
if ((refs != null) && (!refs.isEmpty()) && (elemName != null)
&& ((ti = refs.iterator().next()) == null || ti instanceof ClassInfoImpl)) {
ClassInfoImpl cImpl = (ClassInfoImpl)ti;
if ((cImpl != null) && (cImpl.getElementName() != null)) {
e.ref(new QName(cImpl.getElementName().getNamespaceURI(), tn.getLocalPart()));
} else {
e.ref(new QName("", tn.getLocalPart()));
}
} else {
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;