Search in sources :

Example 56 with XMLSchemaClassPathReference

use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.

the class XMLRootComplexInheritanceProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.getInheritancePolicy().setParentClass(Person.class);
    // descriptor.setDefaultRootElement("oxm:eRoot");
    // descriptor.setDefaultRootElement("oxm:pRoot");
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("empId");
    nameMapping.setGetMethodName("getEmpId");
    nameMapping.setSetMethodName("setEmpId");
    // nameMapping.setNullValue(Integer.valueOf(0));
    nameMapping.setXPath("id/text()");
    descriptor.addMapping(nameMapping);
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/oxm:emp");
    schemaReference.setType(XMLSchemaClassPathReference.COMPLEX_TYPE);
    descriptor.setSchemaReference(schemaReference);
    namespaceResolver.put("oxm", "test");
    descriptor.setNamespaceResolver(namespaceResolver);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 57 with XMLSchemaClassPathReference

use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method setSchemaContext.

private void setSchemaContext(Descriptor desc, TypeInfo info) {
    XMLSchemaClassPathReference schemaRef = new XMLSchemaClassPathReference();
    if (info.getClassNamespace() == null || info.getClassNamespace().equals("")) {
        schemaRef.setSchemaContext("/" + info.getSchemaTypeName());
        schemaRef.setSchemaContextAsQName(new QName(info.getSchemaTypeName()));
    } else {
        String prefix = desc.getNonNullNamespaceResolver().resolveNamespaceURI(info.getClassNamespace());
        if (prefix != null && !prefix.equals("")) {
            schemaRef.setSchemaContext("/" + prefix + ":" + info.getSchemaTypeName());
            schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName(), prefix));
        } else {
            String generatedPrefix = getPrefixForNamespace(info.getClassNamespace(), desc.getNonNullNamespaceResolver(), false);
            schemaRef.setSchemaContext("/" + getQualifiedString(generatedPrefix, info.getSchemaTypeName()));
            if (generatedPrefix == null || generatedPrefix.equals(Constants.EMPTY_STRING)) {
                schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName()));
            } else {
                schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName(), generatedPrefix));
            }
        }
    }
    // the default type is complex; need to check for simple type case
    if (info.isEnumerationType() || (info.getPropertyNames().size() == 1 && helper.isAnnotationPresent(info.getProperties().get(info.getPropertyNames().get(0)).getElement(), XmlValue.class))) {
        schemaRef.setType(XMLSchemaReference.SIMPLE_TYPE);
    }
    desc.setSchemaReference(schemaRef);
}
Also used : QName(javax.xml.namespace.QName) XmlValue(jakarta.xml.bind.annotation.XmlValue) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 58 with XMLSchemaClassPathReference

use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.

the class XSDHelperProject method getChild2Descriptor.

private XMLDescriptor getChild2Descriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child2.class);
    xmlDescriptor.setDefaultRootElement("tns:child2");
    xmlDescriptor.addPrimaryKeyFieldName("@id");
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:child2");
    schemaReference.setType(XMLSchemaReference.ELEMENT);
    xmlDescriptor.setSchemaReference(schemaReference);
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:xsd");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    xmlDescriptor.addMapping(idMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 59 with XMLSchemaClassPathReference

use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.

the class XSDHelperProject method getChild1Descriptor.

private XMLDescriptor getChild1Descriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child1.class);
    xmlDescriptor.addPrimaryKeyFieldName("@id");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:xsd");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:child1");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(schemaReference);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    xmlDescriptor.addMapping(idMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Example 60 with XMLSchemaClassPathReference

use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.

the class OppositeProject method getChild1Descriptor.

private XMLDescriptor getChild1Descriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Child1.class);
    xmlDescriptor.addPrimaryKeyFieldName("@id");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("tns", "urn:opposite");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
    schemaReference.setSchemaContext("/tns:child1");
    schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
    xmlDescriptor.setSchemaReference(schemaReference);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    xmlDescriptor.addMapping(idMapping);
    XMLObjectReferenceMapping child2Mapping = new XMLObjectReferenceMapping();
    child2Mapping.setReferenceClass(Child2.class);
    child2Mapping.setAttributeName("child2");
    child2Mapping.addSourceToTargetKeyFieldAssociation("tns:child2/text()", "@id");
    xmlDescriptor.addMapping(child2Mapping);
    XMLCollectionReferenceMapping child2CollectionMapping = new XMLCollectionReferenceMapping();
    child2CollectionMapping.setReferenceClass(Child2.class);
    child2CollectionMapping.setAttributeName("child2Collection");
    child2CollectionMapping.addSourceToTargetKeyFieldAssociation("tns:child2collection/text()", "@id");
    xmlDescriptor.addMapping(child2CollectionMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Aggregations

XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)71 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)69 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)52 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)36 QName (javax.xml.namespace.QName)13 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)9 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)9 XMLField (org.eclipse.persistence.oxm.XMLField)8 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)6 XMLSchemaReference (org.eclipse.persistence.oxm.schema.XMLSchemaReference)5 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)4 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)2 XmlValue (jakarta.xml.bind.annotation.XmlValue)1 XMLAnyCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping)1 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)1