use of org.eclipse.persistence.oxm.mappings.XMLMapping in project eclipselink by eclipse-ee4j.
the class XmlBindingsGenerator method generateJavaType.
/**
* Process a given XMLDescriptor and return a JavaType instance.
*/
protected static JavaType generateJavaType(XMLDescriptor xdesc) {
String defaultNamespace = null;
if (xdesc.getNamespaceResolver() != null) {
defaultNamespace = xdesc.getNamespaceResolver().getDefaultNamespaceURI();
}
String schemaContext = null;
if (xdesc.getSchemaReference() != null) {
schemaContext = xdesc.getSchemaReference().getSchemaContext();
}
JavaType jType = new JavaType();
jType.setName(getClassName(xdesc.getJavaClassName()));
jType.setXmlAccessorType(XmlAccessType.FIELD);
// handle XmlType
if (schemaContext != null) {
XmlType xType = new XmlType();
xType.setName(schemaContext.substring(1, schemaContext.length()));
if (defaultNamespace != null) {
xType.setNamespace(defaultNamespace);
}
jType.setXmlType(xType);
}
// handle XmlRootElement
XmlRootElement xmlRootElt = new XmlRootElement();
xmlRootElt.setName(xdesc.getDefaultRootElement());
if (defaultNamespace != null) {
xmlRootElt.setNamespace(defaultNamespace);
}
jType.setXmlRootElement(xmlRootElt);
jType.setJavaAttributes(new JavaAttributes());
// generate an XmlAttribute or XmlElement for each mapping
for (Iterator<DatabaseMapping> xmapIt = xdesc.getMappings().iterator(); xmapIt.hasNext(); ) {
XMLMapping xMap = (XMLMapping) xmapIt.next();
if (((XMLField) xMap.getField()).getXPathFragment().isAttribute()) {
JAXBElement<XmlAttribute> jAtt = generateXmlAttribute(xMap);
if (jAtt != null) {
jType.getJavaAttributes().getJavaAttribute().add(jAtt);
}
} else {
JAXBElement<XmlElement> jElt = generateXmlElement(xMap);
if (jElt != null) {
jType.getJavaAttributes().getJavaAttribute().add(jElt);
}
}
}
return jType;
}
Aggregations