use of org.eclipse.persistence.internal.oxm.schema.model.Attribute 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.Attribute in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method buildAttribute.
/**
* Build and return an Attribute for a given XPathFragment.
*/
protected Attribute buildAttribute(XPathFragment frag, String schemaType) {
Attribute attr = new Attribute();
attr.setName(frag.getShortName());
attr.setType(schemaType);
return attr;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method buildComplexTypeWithSimpleContent.
/**
* Create and return a ComplexType containing simple content for a given XMLDescriptor. Assumes
* that the descriptor has a schema context set.
*/
private ComplexType buildComplexTypeWithSimpleContent(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
ComplexType ct = new ComplexType();
SimpleContent sc = new SimpleContent();
Extension extension = new Extension();
sc.setExtension(extension);
ct.setSimpleContent(sc);
for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
Field xFld = (Field) mapping.getField();
if (xFld.getXPath().equals(TEXT)) {
extension.setBaseType(getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema));
} else if (xFld.getXPathFragment().isAttribute()) {
String schemaTypeString = getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema);
Attribute attr = buildAttribute((DirectMapping) mapping, schemaTypeString);
extension.getOrderedAttributes().add(attr);
}
}
return ct;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method buildAttribute.
/**
* Build and return an Attribute for a given XMLDirectMapping.
*/
protected Attribute buildAttribute(DirectMapping mapping, String schemaType) {
XPathFragment frag = ((Field) mapping.getField()).getXPathFragment();
Attribute attr = new Attribute();
attr.setName(frag.getShortName());
attr.setType(schemaType);
return attr;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Attribute in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method processEnumeration.
/**
* Process information contained within an EnumTypeConverter. This will generate a simple
* type containing enumeration info.
*/
protected void processEnumeration(String schemaTypeString, XPathFragment frag, DirectMapping mapping, Sequence seq, ComplexType ct, Schema workingSchema, CoreConverter converter) {
Element elem = null;
Attribute attr = null;
if (frag.isAttribute()) {
attr = buildAttribute(mapping, schemaTypeString);
} else {
elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
}
Collection<String> fieldValues = ((EnumTypeConverter) converter).getAttributeToFieldValues().values();
List<String> facets = new ArrayList<>(fieldValues);
Restriction restriction = new Restriction();
restriction.setEnumerationFacets(facets);
SimpleType st = new SimpleType();
st.setRestriction(restriction);
if (frag.isAttribute()) {
attr.setSimpleType(st);
ct.getOrderedAttributes().add(attr);
} else {
elem.setSimpleType(st);
seq.addElement(elem);
}
}
Aggregations