use of org.eclipse.persistence.internal.oxm.schema.model.Restriction in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method processFacet.
private void processFacet(Element element, Facet facet) {
if (element.getSimpleType() == null)
element.setSimpleType(new SimpleType());
Restriction restriction = element.getSimpleType().getRestriction();
if (restriction == null) {
restriction = new Restriction(element.getType());
element.getSimpleType().setRestriction(restriction);
}
// Prevent error: "Cannot have both a 'type' attribute and an 'anonymous type' child".
element.setType(null);
facet.accept(FacetVisitorHolder.VISITOR, restriction);
}
use of org.eclipse.persistence.internal.oxm.schema.model.Restriction in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method processSimpleType.
private SDOType processSimpleType(String targetNamespace, String defaultNamespace, String sdoTypeName, SimpleType simpleType) {
if (simpleType == null) {
return null;
}
boolean addedNR = addNextNamespaceResolver(simpleType.getAttributesMap());
String name = sdoTypeName;
String originalName = name;
String nameValue = simpleType.getAttributesMap().get(SDOConstants.SDOXML_NAME_QNAME);
if (nameValue != null) {
itemNameToSDOName.put(sdoTypeName, nameValue);
name = nameValue;
}
SDOType newType = startSimpleType(targetNamespace, defaultNamespace, name, originalName, simpleType);
if (newType != null) {
Restriction restriction = simpleType.getRestriction();
if (restriction != null) {
processRestriction(targetNamespace, defaultNamespace, newType, restriction);
}
List list = simpleType.getList();
if (list != null) {
processList(targetNamespace, defaultNamespace, sdoTypeName, list, newType);
}
Union union = simpleType.getUnion();
if (union != null) {
processUnion(targetNamespace, defaultNamespace, sdoTypeName, union, newType);
}
finishSimpleType(targetNamespace, defaultNamespace, sdoTypeName, simpleType, newType);
}
if (addedNR) {
namespaceResolvers.remove(namespaceResolvers.size() - 1);
}
return newType;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Restriction in project eclipselink by eclipse-ee4j.
the class SchemaModelGenerator method buildSimpleType.
/**
* Create and return a SimpleType for a given XMLDescriptor.
*/
protected SimpleType buildSimpleType(Descriptor desc, Schema workingSchema, boolean global) {
SimpleType st;
if (global) {
st = buildNewSimpleType(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
} else {
st = new SimpleType();
}
CoreMapping mapping = (CoreMapping) desc.getMappings().get(0);
QName qname = conversionManager.schemaType(mapping.getAttributeClassification());
String baseType = qname.getLocalPart();
if (qname.getNamespaceURI() != null) {
String prefix = workingSchema.getNamespaceResolver().resolveNamespaceURI(qname.getNamespaceURI());
if (prefix == null) {
prefix = workingSchema.getNamespaceResolver().generatePrefix();
workingSchema.getNamespaceResolver().put(prefix, qname.getNamespaceURI());
}
baseType = prefix + Constants.COLON + baseType;
}
Restriction restriction = new Restriction();
restriction.setBaseType(baseType);
st.setRestriction(restriction);
return st;
}
use of org.eclipse.persistence.internal.oxm.schema.model.Restriction 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);
}
}
use of org.eclipse.persistence.internal.oxm.schema.model.Restriction in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addSchemaComponents.
public void addSchemaComponents(JavaClass myClass) {
// first check for type
String myClassName = myClass.getQualifiedName();
Element rootElement = null;
TypeInfo info = typeInfo.get(myClassName);
if (info.isTransient() || info.getClassNamespace().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
return;
}
SchemaTypeInfo schemaTypeInfo = new SchemaTypeInfo();
schemaTypeInfo.setSchemaTypeName(new QName(info.getClassNamespace(), info.getSchemaTypeName()));
this.schemaTypeInfo.put(myClass.getQualifiedName(), schemaTypeInfo);
NamespaceInfo namespaceInfo = this.packageToPackageInfoMappings.get(myClass.getPackageName()).getNamespaceInfo();
if (namespaceInfo.getLocation() != null && !namespaceInfo.getLocation().equals(GENERATE)) {
return;
}
Schema schema = getSchemaForNamespace(info.getClassNamespace(), myClass.getPackageName());
info.setSchema(schema);
String typeName = info.getSchemaTypeName();
String pfx = EMPTY_STRING;
Property valueField = null;
if (info.isSetXmlRootElement()) {
// Create the root element and add it to the schema
org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement xmlRE = info.getXmlRootElement();
rootElement = new Element();
String elementName = xmlRE.getName();
if (elementName.equals(XMLProcessor.DEFAULT) || elementName.equals(EMPTY_STRING)) {
try {
elementName = info.getXmlNameTransformer().transformRootElementName(myClassName);
} catch (Exception ex) {
throw org.eclipse.persistence.exceptions.JAXBException.exceptionDuringNameTransformation(myClassName, info.getXmlNameTransformer().getClass().getName(), ex);
}
}
rootElement.setName(elementName);
String rootNamespace = xmlRE.getNamespace();
if (rootNamespace.equals(XMLProcessor.DEFAULT)) {
Schema rootElementSchema = getSchemaForNamespace(namespaceInfo.getNamespace());
if (rootElementSchema != null) {
rootElementSchema.addTopLevelElement(rootElement);
}
schemaTypeInfo.getGlobalElementDeclarations().add(new QName(namespaceInfo.getNamespace(), rootNamespace));
rootNamespace = namespaceInfo.getNamespace();
} else {
Schema rootElementSchema = getSchemaForNamespace(rootNamespace);
if (rootElementSchema != null) {
rootElementSchema.addTopLevelElement(rootElement);
}
schemaTypeInfo.getGlobalElementDeclarations().add(new QName(rootNamespace, elementName));
}
// handle root-level imports/includes [schema = the type's schema]
Schema rootSchema = getSchemaForNamespace(rootNamespace);
addImportIfRequired(rootSchema, schema, schema.getTargetNamespace());
// setup a prefix, if necessary
if (rootSchema != null && !info.getClassNamespace().equals(EMPTY_STRING)) {
pfx = getOrGeneratePrefixForNamespace(info.getClassNamespace(), rootSchema);
pfx += COLON;
}
}
if (CompilerHelper.isSimpleType(info)) {
SimpleType type = new SimpleType();
// simple type case, we just need the name and namespace info
if (typeName.equals(EMPTY_STRING)) {
// A root elem or locally defined whenever used
if (rootElement != null) {
rootElement.setSimpleType(type);
}
} else {
type.setName(typeName);
schema.addTopLevelSimpleTypes(type);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
}
// Figure out schema type and set it as Restriction
QName restrictionType = null;
Restriction restriction = new Restriction();
if (info.isEnumerationType()) {
restrictionType = ((EnumTypeInfo) info).getRestrictionBase();
restriction.setEnumerationFacets(this.getEnumerationFacetsFor((EnumTypeInfo) info));
String prefix = null;
if (restrictionType.getNamespaceURI() != null && !EMPTY_STRING.equals(restrictionType.getNamespaceURI())) {
if (javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(restrictionType.getNamespaceURI())) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, restrictionType.getNamespaceURI());
}
}
String extensionTypeName = restrictionType.getLocalPart();
if (prefix != null) {
extensionTypeName = prefix + COLON + extensionTypeName;
}
restriction.setBaseType(extensionTypeName);
type.setRestriction(restriction);
} else {
valueField = info.getXmlValueProperty();
JavaClass javaType = valueField.getActualType();
QName baseType = getSchemaTypeFor(javaType);
String prefix = null;
if (baseType.getNamespaceURI() != null && !baseType.getNamespaceURI().equals(EMPTY_STRING)) {
if (baseType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, baseType.getNamespaceURI());
}
}
String baseTypeName = baseType.getLocalPart();
if (prefix != null) {
baseTypeName = prefix + COLON + baseTypeName;
}
if (valueField.isXmlList() || (valueField.getGenericType() != null)) {
// generate a list instead of a restriction
org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
list.setItemType(baseTypeName);
type.setList(list);
} else {
if (helper.isAnnotationPresent(valueField.getElement(), XmlSchemaType.class)) {
XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(valueField.getElement(), XmlSchemaType.class);
// TODO: This assignment seems like a bug, probably this should be "baseTypeName" ?
baseType = new QName(schemaType.namespace(), schemaType.name());
}
restriction.setBaseType(baseTypeName);
type.setRestriction(restriction);
}
}
info.setSimpleType(type);
} else if ((valueField = this.getXmlValueFieldForSimpleContent(info)) != null) {
ComplexType type = new ComplexType();
SimpleContent content = new SimpleContent();
if (EMPTY_STRING.equals(typeName)) {
if (rootElement != null) {
rootElement.setComplexType(type);
}
info.setComplexType(type);
} else {
type.setName(typeName);
schema.addTopLevelComplexTypes(type);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
}
QName extensionType = getSchemaTypeFor(valueField.getType());
if (helper.isAnnotationPresent(valueField.getElement(), XmlSchemaType.class)) {
XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(valueField.getElement(), XmlSchemaType.class);
extensionType = new QName(schemaType.namespace(), schemaType.name());
}
String prefix = null;
if (extensionType.getNamespaceURI() != null && !extensionType.getNamespaceURI().equals(EMPTY_STRING)) {
if (extensionType.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
prefix = Constants.SCHEMA_PREFIX;
} else {
prefix = getPrefixForNamespace(schema, extensionType.getNamespaceURI());
}
}
String extensionTypeName = extensionType.getLocalPart();
if (prefix != null) {
extensionTypeName = prefix + COLON + extensionTypeName;
}
Extension extension = new Extension();
extension.setBaseType(extensionTypeName);
content.setExtension(extension);
type.setSimpleContent(content);
info.setComplexType(type);
} else {
ComplexType type = createComplexTypeForClass(myClass, info);
TypeDefParticle compositor = null;
if (type.getComplexContent() != null && type.getComplexContent().getExtension() != null) {
compositor = type.getComplexContent().getExtension().getTypeDefParticle();
} else {
compositor = type.getTypeDefParticle();
}
if (EMPTY_STRING.equals(typeName)) {
if (rootElement != null) {
rootElement.setComplexType(type);
}
info.setComplexType(type);
info.setCompositor(compositor);
} else {
type.setName(typeName);
if (rootElement != null) {
rootElement.setType(pfx + type.getName());
}
schema.addTopLevelComplexTypes(type);
info.setComplexType(type);
info.setCompositor(compositor);
}
}
}
Aggregations