use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method buildElement.
/**
* Build and return an Element for a given XPathFragment.
*/
protected Element buildElement(XPathFragment frag, String schemaType, String minOccurs, String maxOccurs) {
Element element = new Element();
element.setName(frag.getLocalName());
element.setMinOccurs(minOccurs);
element.setMaxOccurs(frag.containsIndex() ? Occurs.UNBOUNDED : maxOccurs);
if (schemaType != null) {
element.setType(schemaType);
}
return element;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processDescriptor.
/**
* Process a given descriptor. Global complex types will be generated for based on
* schema context, and global elements based on default root element.
*/
protected void processDescriptor(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
// determine if a simple type (or complex type with simple content) or complex type is required
boolean simple = isSimple(desc);
XMLSchemaReference schemaRef = desc.getSchemaReference();
if (schemaRef != null) {
if (schemaRef.getType() == org.eclipse.persistence.platform.xml.XMLSchemaReference.COMPLEX_TYPE) {
workingSchema.addTopLevelComplexTypes(buildComplexType(false, desc, schemaForNamespace, workingSchema, properties, descriptors));
} else if (schemaRef.getType() == org.eclipse.persistence.platform.xml.XMLSchemaReference.SIMPLE_TYPE) {
workingSchema.addTopLevelSimpleTypes(buildSimpleType(desc, workingSchema, true));
} else if (schemaRef.getType() == org.eclipse.persistence.platform.xml.XMLSchemaReference.ELEMENT) {
workingSchema.addTopLevelElement(buildElement(desc, schemaForNamespace, workingSchema, properties, descriptors, simple));
}
for (DatabaseTable table : (Vector<DatabaseTable>) desc.getTables()) {
String localName = getDefaultRootElementAsQName(desc, table.getName()).getLocalPart();
// don't overwrite existing top level elements
if (workingSchema.getTopLevelElements().get(localName) != null) {
continue;
}
Element topLevelElement = new Element();
topLevelElement.setName(localName);
QName qname = schemaRef.getSchemaContextAsQName(workingSchema.getNamespaceResolver());
String elementType = qname.getLocalPart();
String elementTypeUri = qname.getNamespaceURI();
String elementTypePrefix = workingSchema.getNamespaceResolver().resolveNamespaceURI(elementTypeUri);
if (elementTypePrefix != null) {
elementType = elementTypePrefix + Constants.COLON + elementType;
}
topLevelElement.setType(elementType);
workingSchema.addTopLevelElement(topLevelElement);
}
} else {
// there is a default root element set we need to generate a global element
for (DatabaseTable table : (Vector<DatabaseTable>) desc.getTables()) {
String localName = getDefaultRootElementAsQName(desc, table.getName()).getLocalPart();
// a global element may have been created while generating an element ref
if (workingSchema.getTopLevelElements().get(localName) == null) {
Element topLevelElement = new Element();
topLevelElement.setName(localName);
if (simple) {
if (isComplexTypeWithSimpleContentRequired(desc)) {
topLevelElement.setComplexType(buildComplexTypeWithSimpleContent(desc, schemaForNamespace, workingSchema, properties, descriptors));
} else {
topLevelElement.setSimpleType(buildSimpleType(desc, workingSchema, false));
}
} else {
topLevelElement.setComplexType(buildComplexType(true, desc, schemaForNamespace, workingSchema, properties, descriptors));
}
workingSchema.addTopLevelElement(topLevelElement);
}
}
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processXMLObjectReferenceMapping.
/**
* Process a given XMLObjectReferenceMapping. In the case of an XMLCollectionReferenceMapping,
* i.e. the isCollection flag is set to true, maxOccurs will be set to 'unbounded' on any
* source elements
*/
protected void processXMLObjectReferenceMapping(ObjectReferenceMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) {
String tgtClassName = mapping.getReferenceClassName();
Descriptor tgtDesc = getDescriptorByName(tgtClassName, descriptors);
if (tgtDesc == null) {
throw DescriptorException.descriptorIsMissing(tgtClassName, (DatabaseMapping) mapping);
}
// get the target mapping(s) to determine the appropriate type(s)
String schemaTypeString = null;
Map<Field, Field> associations = mapping.getSourceToTargetKeyFieldAssociations();
for (Entry<Field, Field> entry : associations.entrySet()) {
Field tgtField = entry.getValue();
Vector mappings = tgtDesc.getMappings();
// schemaTypeString = Constants.SCHEMA_PREFIX + COLON + IDREF;
for (Enumeration mappingsNum = mappings.elements(); mappingsNum.hasMoreElements(); ) {
Mapping nextMapping = (Mapping) mappingsNum.nextElement();
if (nextMapping.getField() != null && nextMapping.getField() instanceof Field) {
Field xFld = (Field) nextMapping.getField();
if (xFld == tgtField) {
schemaTypeString = getSchemaTypeForElement(tgtField, nextMapping.getAttributeClassification(), workingSchema);
}
}
}
if (schemaTypeString == null) {
schemaTypeString = getSchemaTypeString(Constants.STRING_QNAME, workingSchema);
}
XPathFragment frag = entry.getKey().getXPathFragment();
if (frag.isAttribute()) {
Attribute attr = buildAttribute(frag, schemaTypeString);
ct.getOrderedAttributes().add(attr);
} else {
Element elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
if (isCollection) {
elem.setMaxOccurs(Occurs.UNBOUNDED);
}
seq.addElement(elem);
}
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method buildElement.
/**
* Create and return an Element for a given XMLDescriptor.
*/
protected Element buildElement(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean simple) {
Element element = new Element();
element.setName(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
if (simple) {
if (isComplexTypeWithSimpleContentRequired(desc)) {
element.setComplexType(buildComplexTypeWithSimpleContent(desc, schemaForNamespace, workingSchema, properties, descriptors));
} else {
element.setSimpleType(buildSimpleType(desc, workingSchema, false));
}
} else {
element.setComplexType(buildComplexType(true, desc, schemaForNamespace, workingSchema, properties, descriptors));
}
return element;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Element in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processReferenceDescriptor.
/**
*/
protected Element processReferenceDescriptor(Element element, Descriptor refDesc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, Field field, boolean isCollection) {
ComplexType ctype = null;
if (refDesc.getSchemaReference() == null) {
ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors);
} else {
element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
}
XPathFragment frag = field.getXPathFragment();
String fragUri = frag.getNamespaceURI();
if (fragUri != null) {
// may need to add a global element
Schema s = getSchema(fragUri, null, schemaForNamespace, properties);
String targetNS = workingSchema.getTargetNamespace();
if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) {
if (s.getTopLevelElements().get(frag.getShortName()) == null) {
Element globalElement = new Element();
globalElement.setName(frag.getLocalName());
if (ctype != null) {
globalElement.setComplexType(ctype);
} else {
globalElement.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
}
s.getTopLevelElements().put(frag.getShortName(), globalElement);
}
element = new Element();
element.setMinOccurs(Occurs.ZERO);
if (isCollection) {
element.setMaxOccurs(Occurs.UNBOUNDED);
}
element.setRef(frag.getShortName());
} else {
element.setComplexType(ctype);
}
} else if (ctype != null) {
element.setComplexType(ctype);
}
return element;
}
Aggregations