Search in sources :

Example 11 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method processXMLCompositeDirectCollectionMapping.

/**
 * Process a given XMLCompositeDirectCollectionMapping.
 */
protected void processXMLCompositeDirectCollectionMapping(DirectCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    Field xmlField = ((Field) (mapping).getField());
    XPathFragment frag = xmlField.getXPathFragment();
    seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
    frag = getTargetXPathFragment(frag);
    String schemaTypeString = getSchemaTypeForElement(xmlField, mapping.getAttributeElementClass(), workingSchema);
    Element element = null;
    if (xmlField.usesSingleNode()) {
        SimpleType st = new SimpleType();
        org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
        if (schemaTypeString == null) {
            schemaTypeString = getSchemaTypeString(Constants.ANY_SIMPLE_TYPE_QNAME, workingSchema);
        }
        list.setItemType(schemaTypeString);
        st.setList(list);
        element = buildElement(xmlField.getXPathFragment(), null, Occurs.ZERO, null);
        element.setSimpleType(st);
    } else {
        if (frag.getNamespaceURI() != null) {
            element = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, element, schemaTypeString);
            element.setMaxOccurs(Occurs.UNBOUNDED);
        } else {
            element = buildElement(frag, schemaTypeString, Occurs.ZERO, Occurs.UNBOUNDED);
        }
    }
    if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
        element.setNillable(true);
    }
    if (xmlField.isRequired()) {
        element.setMinOccurs("1");
    }
    seq.addElement(element);
}
Also used : Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) Field(org.eclipse.persistence.internal.oxm.mappings.Field) SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method buildNewSimpleType.

/**
 * Create and return a SimpleType with name set to the given name.
 */
protected SimpleType buildNewSimpleType(String name) {
    SimpleType st = new SimpleType();
    st.setName(name);
    return st;
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType)

Example 13 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType 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);
    }
}
Also used : Restriction(org.eclipse.persistence.internal.oxm.schema.model.Restriction) SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) ArrayList(java.util.ArrayList)

Example 14 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType 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);
        }
    }
}
Also used : TypeDefParticle(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XmlVirtualAccessMethodsSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema) SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) List(java.util.List) ArrayList(java.util.ArrayList) QName(javax.xml.namespace.QName) XmlSchemaType(jakarta.xml.bind.annotation.XmlSchemaType) BeanValidationException(org.eclipse.persistence.exceptions.BeanValidationException) IOException(java.io.IOException) Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) Restriction(org.eclipse.persistence.internal.oxm.schema.model.Restriction) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) SimpleContent(org.eclipse.persistence.internal.oxm.schema.model.SimpleContent) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 15 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SDOTypesGenerator method processGlobalItem.

private void processGlobalItem(String targetNamespace, String defaultNamespace, String qualifiedName) {
    if (rootSchema == null) {
        return;
    }
    String localName = null;
    int index = qualifiedName.indexOf(':');
    if (index != -1) {
        localName = qualifiedName.substring(index + 1, qualifiedName.length());
    } else {
        localName = qualifiedName;
    }
    SimpleType simpleType = rootSchema.getTopLevelSimpleTypes().get(localName);
    if (simpleType == null) {
        ComplexType complexType = rootSchema.getTopLevelComplexTypes().get(localName);
        if (complexType == null) {
            Element element = rootSchema.getTopLevelElements().get(localName);
            if (element == null) {
                Attribute attribute = rootSchema.getTopLevelAttributes().get(localName);
                if (attribute != null) {
                    processGlobalAttribute(targetNamespace, defaultNamespace, attribute);
                }
            } else {
                processGlobalElement(targetNamespace, defaultNamespace, element);
            }
        } else {
            processGlobalComplexType(targetNamespace, defaultNamespace, complexType);
        }
    } else {
        processGlobalSimpleType(targetNamespace, defaultNamespace, simpleType);
    }
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Aggregations

SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)18 QName (javax.xml.namespace.QName)10 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)6 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)6 ArrayList (java.util.ArrayList)5 SDOType (org.eclipse.persistence.sdo.SDOType)5 List (java.util.List)4 Attribute (org.eclipse.persistence.internal.oxm.schema.model.Attribute)4 Restriction (org.eclipse.persistence.internal.oxm.schema.model.Restriction)4 AnyAttribute (org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute)3 Property (commonj.sdo.Property)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)2 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)2 SimpleContent (org.eclipse.persistence.internal.oxm.schema.model.SimpleContent)2 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)2 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)2 XmlSchemaType (jakarta.xml.bind.annotation.XmlSchemaType)1