use of org.eclipse.persistence.internal.oxm.schema.model.Choice in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addReferenceToSchema.
/**
* Convenience method for processing a reference property. Required
* schema components will be generated and set accordingly.
*
* @param property the choice property to be processed
* @param compositor the sequence/choice/all to modify
* @param schema the schema being built
*/
private void addReferenceToSchema(Property property, Schema schema, TypeDefParticle compositor) {
java.util.List<ElementDeclaration> referencedElements = property.getReferencedElements();
if (referencedElements.size() == 1 && !property.isAny()) {
// if only a single reference, just add the element.
Element element = new Element();
ElementDeclaration decl = referencedElements.get(0);
String localName = decl.getElementName().getLocalPart();
String prefix = getPrefixForNamespace(schema, decl.getElementName().getNamespaceURI());
if (decl.getScopeClass() == GLOBAL.class) {
if (prefix == null || prefix.equals(EMPTY_STRING)) {
element.setRef(localName);
} else {
element.setRef(prefix + COLON + localName);
}
} else {
element.setType(getTypeName(property, decl.getJavaType(), schema));
element.setName(localName);
}
if (property.getGenericType() != null) {
element.setMinOccurs(Occurs.ZERO);
element.setMaxOccurs(Occurs.UNBOUNDED);
} else if (!property.isRequired()) {
element.setMinOccurs(Occurs.ZERO);
}
compositor.addElement(element);
} else {
// otherwise, add a choice of referenced elements.
Choice choice = new Choice();
if (property.getGenericType() != null) {
choice.setMaxOccurs(Occurs.UNBOUNDED);
}
if (!property.isRequired()) {
choice.setMinOccurs(Occurs.ZERO);
}
for (ElementDeclaration elementDecl : referencedElements) {
Element element = new Element();
String localName = elementDecl.getElementName().getLocalPart();
String prefix = getPrefixForNamespace(schema, elementDecl.getElementName().getNamespaceURI());
if (elementDecl.getScopeClass() == GLOBAL.class) {
if (prefix == null || prefix.equals(EMPTY_STRING)) {
element.setRef(localName);
} else {
element.setRef(prefix + COLON + localName);
}
} else {
Schema referencedSchema = getSchemaForNamespace(elementDecl.getElementName().getNamespaceURI());
element.setType(getTypeName(property, elementDecl.getJavaType(), referencedSchema));
element.setName(localName);
}
choice.addElement(element);
}
// handle XmlAnyElement case
if (property.isAny()) {
addAnyToSchema(property, choice, false);
}
if (compositor instanceof Sequence) {
((Sequence) compositor).addChoice(choice);
} else if (compositor instanceof Choice) {
((Choice) compositor).addChoice(choice);
}
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Choice in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addChoiceToSchema.
/**
* Convenience method for processing a choice property. Required
* schema components will be generated and set accordingly.
*
* @param property the choice property to be processed
* @param typeInfo the TypeInfo that the given property belongs to
* @param type the ComplexType which compositor(s) should be added to
* @param compositor the sequence/choice/all to modify
* @param schema the schema being built
*/
private void addChoiceToSchema(Property property, TypeInfo typeInfo, ComplexType type, TypeDefParticle compositor, Schema schema) {
Choice choice = new Choice();
if (property.getGenericType() != null) {
choice.setMaxOccurs(Occurs.UNBOUNDED);
}
ArrayList<Property> choiceProperties = (ArrayList<Property>) property.getChoiceProperties();
addToSchemaType(typeInfo, choiceProperties, choice, type, schema);
if (compositor instanceof Sequence) {
((Sequence) compositor).addChoice(choice);
} else if (compositor instanceof Choice) {
((Choice) compositor).addChoice(choice);
}
}
Aggregations