use of org.eclipse.persistence.oxm.schema.XMLSchemaReference in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method setupInheritance.
/**
* Setup inheritance for abstract superclass.
*
* NOTE: We currently only handle one level of inheritance in this case.
* For multiple levels the code will need to be modified. The logic in
* generateMappings() that determines when to copy down inherited
* methods from the parent class will need to be changed as well.
*/
private void setupInheritance(JavaClass jClass) {
TypeInfo tInfo = typeInfo.get(jClass.getName());
Descriptor descriptor = tInfo.getDescriptor();
if (descriptor == null) {
return;
}
JavaClass superClass = CompilerHelper.getNextMappedSuperClass(jClass, typeInfo, helper);
if (superClass == null) {
return;
}
TypeInfo superTypeInfo = typeInfo.get(superClass.getName());
if (superTypeInfo == null) {
return;
}
Descriptor superDescriptor = superTypeInfo.getDescriptor();
if (superDescriptor != null) {
XMLSchemaReference sRef = descriptor.getSchemaReference();
if (sRef == null || sRef.getSchemaContext() == null) {
return;
}
JavaClass rootMappedSuperClass = getRootMappedSuperClass(superClass);
TypeInfo rootTypeInfo = typeInfo.get(rootMappedSuperClass.getName());
Descriptor rootDescriptor = rootTypeInfo.getDescriptor();
if (rootDescriptor.getNamespaceResolver() == null) {
rootDescriptor.setNamespaceResolver(new org.eclipse.persistence.oxm.NamespaceResolver());
}
if (rootDescriptor.getInheritancePolicy().getClassIndicatorField() == null) {
Field classIndicatorField;
if (rootTypeInfo.isSetXmlDiscriminatorNode()) {
classIndicatorField = new XMLField(rootTypeInfo.getXmlDiscriminatorNode());
} else {
classIndicatorField = XMLConstants.DEFAULT_XML_TYPE_ATTRIBUTE;
classIndicatorField.getXPathFragment().setNamespaceURI(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
}
rootDescriptor.getInheritancePolicy().setClassIndicatorField(classIndicatorField);
}
Object sCtx = null;
// TypeInfo tInfo = typeInfo.get(jClass.getName());
if (tInfo.isSetXmlDiscriminatorValue()) {
sCtx = tInfo.getXmlDiscriminatorValue();
} else if (!tInfo.isAnonymousComplexType()) {
sCtx = sRef.getSchemaContextAsQName();
}
if (sCtx != null) {
descriptor.getInheritancePolicy().setParentClassName(superClass.getName());
rootDescriptor.getInheritancePolicy().addClassNameIndicator(jClass.getName(), sCtx);
}
Object value = rootDescriptor.getInheritancePolicy().getClassNameIndicatorMapping().get(rootDescriptor.getJavaClassName());
if (value == null) {
if (rootTypeInfo.isSetXmlDiscriminatorValue()) {
rootDescriptor.getInheritancePolicy().addClassNameIndicator(rootDescriptor.getJavaClassName(), rootTypeInfo.getXmlDiscriminatorValue());
} else {
XMLSchemaReference rootSRef = rootDescriptor.getSchemaReference();
if (rootSRef != null && rootSRef.getSchemaContext() != null) {
QName rootSCtx = rootSRef.getSchemaContextAsQName();
rootDescriptor.getInheritancePolicy().addClassNameIndicator(rootDescriptor.getJavaClassName(), rootSCtx);
}
}
}
rootDescriptor.getInheritancePolicy().setShouldReadSubclasses(true);
// Check for attributeGroups
Map<String, AttributeGroup> childGroups = ((XMLDescriptor) descriptor).getAttributeGroups();
Map<String, AttributeGroup> parentGroups = ((XMLDescriptor) rootDescriptor).getAttributeGroups();
if (childGroups != null && !(childGroups.isEmpty()) && parentGroups != null && !(parentGroups.isEmpty())) {
for (String nextKey : childGroups.keySet()) {
AttributeGroup parentGroup = parentGroups.get(nextKey);
if (parentGroup != null) {
AttributeGroup childGroup = childGroups.get(nextKey);
parentGroup.getSubClassGroups().put(descriptor.getJavaClassName(), childGroup);
}
}
}
}
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaReference in project eclipselink by eclipse-ee4j.
the class SDOType method preInitialize.
/**
* INTERNAL:
* For this Type generate classes
* @param packageName
* @param namespaceResolvers
*/
public void preInitialize(String packageName, List namespaceResolvers) {
String instanceClassName = getInstanceClassName();
if (null == instanceClassName) {
if (null == packageName) {
String uri = getURI();
if (null == uri) {
packageName = SDOUtil.getDefaultPackageName() + SDOConstants.JAVA_PACKAGE_NAME_SEPARATOR;
} else {
packageName = SDOUtil.getPackageNameFromURI(uri) + SDOConstants.JAVA_PACKAGE_NAME_SEPARATOR;
}
}
// Verify and fix any Class name that does not conform to conventions
// run the class name through the JAXB mangler
String mangledClassName = SDOUtil.className(getName(), false, true, true);
// we will not fix any type collision at this time as a result of class renaming
// write fully qualified java class name
StringBuffer fullClassName = new StringBuffer(packageName);
fullClassName.append(mangledClassName);
setInstanceClassName(fullClassName.toString());
}
//
AbstractSessionLog.getLog().log(//
AbstractSessionLog.FINER, //
"sdo_type_generation_processing_type", new Object[] { Helper.getShortClassName(getClass()), getInstanceClassName() });
initializeNamespaces(namespaceResolvers);
getXmlDescriptor().setJavaClassName(getImplClassName());
// See SDOResolvable enhancement
String schemaContext = getName();
if (getXmlDescriptor().getNamespaceResolver() != null) {
String prefix = getXmlDescriptor().getNamespaceResolver().resolveNamespaceURI(getURI());
if ((prefix != null) && !prefix.equals(SDOConstants.EMPTY_STRING)) {
schemaContext = prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + schemaContext;
}
}
String schemaContextWithSlash = SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + schemaContext;
XMLSchemaReference schemaRef = new XMLSchemaClassPathReference();
schemaRef.setSchemaContext(schemaContextWithSlash);
schemaRef.setType(XMLSchemaReference.COMPLEX_TYPE);
getXmlDescriptor().setSchemaReference(schemaRef);
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaReference in project eclipselink by eclipse-ee4j.
the class JAXBHelperContext method getType.
/**
* Return the SDO type corresponding to the wrapped class.
* <pre>
* Type customerType = jaxbHelperContext.getType(Customer.class);
* DataObject customerDO = jaxbHelperContext.getDataFactory().create(customerType);
* </pre>
*/
public Type getType(Class<?> entityClass) {
if (null == entityClass) {
return null;
}
XMLDescriptor entityDescriptor = null;
try {
entityDescriptor = (XMLDescriptor) jaxbContext.getXMLContext().getSession(entityClass).getDescriptor(entityClass);
} catch (Exception e) {
return null;
}
XMLSchemaReference schemaReference = entityDescriptor.getSchemaReference();
if (null == schemaReference) {
throw SDOException.sdoJaxbNoSchemaReference(entityClass);
}
QName qName = schemaReference.getSchemaContextAsQName(entityDescriptor.getNamespaceResolver());
if (null == qName) {
throw SDOException.sdoJaxbNoSchemaContext(entityClass);
}
Type wrapperType;
if (entityDescriptor.getSchemaReference().getType() == XMLSchemaReference.COMPLEX_TYPE) {
wrapperType = getTypeHelper().getType(qName.getNamespaceURI(), qName.getLocalPart());
} else {
Property property = getXSDHelper().getGlobalProperty(qName.getNamespaceURI(), qName.getLocalPart(), true);
wrapperType = property.getType();
}
if (null == wrapperType) {
throw SDOException.sdoJaxbNoTypeForClassBySchemaContext(entityClass, qName);
}
return wrapperType;
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaReference in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method generateSchemas.
/**
* Generates a Map of EclipseLink schema model Schema objects for a given list of XMLDescriptors.
* The descriptors are assumed to have been initialized. One Schema object will be generated
* per namespace.
*
* @param descriptorsToProcess list of XMLDescriptors which will be used to generate Schema objects
* @param properties holds a namespace to Properties map containing schema settings, such as elementFormDefault
* @return a map of namespaces to EclipseLink schema model Schema objects
* @throws DescriptorException if the reference descriptor for a composite mapping is not in the list of descriptors
* @see Schema
*/
public Map<String, Schema> generateSchemas(List<Descriptor> descriptorsToProcess, SchemaModelGeneratorProperties properties) throws DescriptorException {
HashMap<String, Schema> schemaForNamespace = new HashMap<>();
Schema workingSchema = null;
if (properties == null) {
properties = new SchemaModelGeneratorProperties();
}
// set up schemas for the descriptors
for (Descriptor desc : descriptorsToProcess) {
String namespace;
XMLSchemaReference schemaRef = desc.getSchemaReference();
if (schemaRef != null) {
namespace = schemaRef.getSchemaContextAsQName(desc.getNamespaceResolver()).getNamespaceURI();
workingSchema = getSchema(namespace, desc.getNamespaceResolver(), schemaForNamespace, properties);
addNamespacesToWorkingSchema(desc.getNamespaceResolver(), workingSchema);
} else {
// default root element set we will need to generate a global element for it
for (DatabaseTable table : (Vector<DatabaseTable>) desc.getTables()) {
namespace = getDefaultRootElementAsQName(desc, table.getName()).getNamespaceURI();
workingSchema = getSchema(namespace, desc.getNamespaceResolver(), schemaForNamespace, properties);
addNamespacesToWorkingSchema(desc.getNamespaceResolver(), workingSchema);
}
}
}
// process the descriptors
for (Descriptor xdesc : descriptorsToProcess) {
processDescriptor(xdesc, schemaForNamespace, workingSchema, properties, descriptorsToProcess);
}
// return the generated schema(s)
return schemaForNamespace;
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaReference 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);
}
}
}
}
Aggregations