Search in sources :

Example 96 with XMLDescriptor

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

the class EmployeeProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setGetMethodName("getID");
    idMapping.setSetMethodName("setID");
    idMapping.setXPath("id/text()");
    descriptor.addMapping(idMapping);
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setGetMethodName("getName");
    nameMapping.setSetMethodName("setName");
    nameMapping.setXPath("name/text()");
    descriptor.addMapping(nameMapping);
    XMLCompositeObjectMapping homeAddressMapping = new XMLCompositeObjectMapping();
    homeAddressMapping.setReferenceClass(Address.class);
    homeAddressMapping.setAttributeName("home-address");
    homeAddressMapping.setGetMethodName("getHomeAddress");
    homeAddressMapping.setSetMethodName("setHomeAddress");
    homeAddressMapping.setXPath("home-address");
    descriptor.addMapping(homeAddressMapping);
    XMLCompositeObjectMapping workAddressMapping = new XMLCompositeObjectMapping();
    workAddressMapping.setReferenceClass(Address.class);
    workAddressMapping.setAttributeName("work-address");
    workAddressMapping.setGetMethodName("getWorkAddress");
    workAddressMapping.setSetMethodName("setWorkAddress");
    workAddressMapping.setXPath("work-address");
    descriptor.addMapping(workAddressMapping);
    XMLCompositeObjectMapping phoneMapping = new XMLCompositeObjectMapping();
    phoneMapping.setReferenceClass(Phone.class);
    phoneMapping.setAttributeName("phone");
    phoneMapping.setGetMethodName("getPhone");
    phoneMapping.setSetMethodName("setPhone");
    phoneMapping.setXPath("phone");
    descriptor.addMapping(phoneMapping);
    XMLCompositeObjectMapping badgeMapping = new XMLCompositeObjectMapping();
    badgeMapping.setReferenceClass(Badge.class);
    badgeMapping.setAttributeName("badge");
    badgeMapping.setGetMethodName("getBadge");
    badgeMapping.setSetMethodName("setBadge");
    badgeMapping.setXPath("badge-id");
    descriptor.addMapping(badgeMapping);
    XMLDirectMapping empCodeMapping = new XMLDirectMapping();
    empCodeMapping.setAttributeName("empCode");
    empCodeMapping.setGetMethodName("getEmpCode");
    empCodeMapping.setSetMethodName("setEmpCode");
    empCodeMapping.setXPath("@empCode");
    descriptor.addMapping(empCodeMapping);
    URL schemaURL = ClassLoader.getSystemResource("org/eclipse/persistence/testing/jaxb/xmlmarshaller/Employee.xsd");
    XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL);
    schemaRef.setType(XMLSchemaReference.ELEMENT);
    schemaRef.setSchemaContext("/employee");
    descriptor.setSchemaReference(schemaRef);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) URL(java.net.URL)

Example 97 with XMLDescriptor

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

the class EmployeeProject method getPhoneDescriptor.

private XMLDescriptor getPhoneDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Phone.class);
    XMLDirectMapping numberMapping = new XMLDirectMapping();
    numberMapping.setAttributeName("number");
    numberMapping.setGetMethodName("getNumber");
    numberMapping.setSetMethodName("setNumber");
    numberMapping.setXPath("text()");
    descriptor.addMapping(numberMapping);
    URL schemaURL = ClassLoader.getSystemResource("org/eclipse/persistence/testing/jaxb/xmlmarshaller/Employee.xsd");
    XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL);
    schemaRef.setType(XMLSchemaReference.SIMPLE_TYPE);
    schemaRef.setSchemaContext("/phone-type");
    descriptor.setSchemaReference(schemaRef);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) URL(java.net.URL)

Example 98 with XMLDescriptor

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

the class EmployeeProject method getJobDescriptor.

private XMLDescriptor getJobDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Job.class);
    descriptor.setDefaultRootElement("job");
    XMLDirectMapping titleMapping = new XMLDirectMapping();
    titleMapping.setAttributeName("title");
    titleMapping.setGetMethodName("getTitle");
    titleMapping.setSetMethodName("setTitle");
    titleMapping.setXPath("title/text()");
    descriptor.addMapping(titleMapping);
    URL schemaURL = ClassLoader.getSystemResource("org/eclipse/persistence/testing/jaxb/xmlmarshaller/Employee.xsd");
    XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL);
    schemaRef.setType(XMLSchemaReference.ELEMENT);
    schemaRef.setSchemaContext("/employee/job");
    descriptor.setSchemaReference(schemaRef);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) URL(java.net.URL)

Example 99 with XMLDescriptor

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

the class SDOSequence method convertToSetting.

private Setting convertToSetting(Property property, Object value) {
    SDOProperty sdoProperty = (SDOProperty) property;
    DatabaseMapping mapping = sdoProperty.getXmlMapping();
    Setting setting = new Setting();
    SDOType sdoType = dataObject.getType();
    XMLDescriptor xmlDescriptor = sdoType.getXmlDescriptor();
    if (null == mapping) {
        setting.setObject(dataObject);
        mapping = xmlDescriptor.getMappingForAttributeName("openContentProperties");
        setting.setMapping(mapping);
        XMLRoot xmlRoot = new XMLRoot();
        if (value instanceof XMLRoot) {
            xmlRoot.setLocalName(((XMLRoot) value).getLocalName());
            xmlRoot.setNamespaceURI(((XMLRoot) value).getNamespaceURI());
            xmlRoot.setObject(((XMLRoot) value).getObject());
        } else {
            xmlRoot.setLocalName(sdoProperty.getName());
            xmlRoot.setNamespaceURI(sdoProperty.getUri());
            xmlRoot.setObject(value);
            // do not set schema type for global properties
            SDOTypeHelper hlpr = (SDOTypeHelper) dataObject.getType().getHelperContext().getTypeHelper();
            if (hlpr.getOpenContentProperty(sdoProperty.getUri(), sdoProperty.getName()) == null) {
                QName schemaTypeQName = hlpr.getXSDTypeFromSDOType(property.getType());
                if (schemaTypeQName != null && schemaTypeQName != XMLConstants.STRING_QNAME) {
                    xmlRoot.setSchemaType(schemaTypeQName);
                }
            }
        }
        setting.setValue(xmlRoot, false);
    } else {
        setting = convertToSetting(mapping, value);
    }
    return setting;
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) QName(javax.xml.namespace.QName) Setting(org.eclipse.persistence.oxm.sequenced.Setting) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 100 with XMLDescriptor

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

the class SDOSequence method convertToSetting.

private Setting convertToSetting(DatabaseMapping mapping, Object value) {
    XMLDescriptor xmlDescriptor = (XMLDescriptor) mapping.getDescriptor();
    NamespaceResolver nsResolver = xmlDescriptor.getNamespaceResolver();
    Setting rootSetting = new Setting();
    XMLField xmlField = (XMLField) mapping.getField();
    if (xmlField == null) {
        if (mapping instanceof XMLObjectReferenceMapping) {
            xmlField = (XMLField) ((XMLObjectReferenceMapping) mapping).getFields().get(0);
        } else if (mapping instanceof XMLCollectionReferenceMapping) {
            xmlField = (XMLField) ((XMLCollectionReferenceMapping) mapping).getFields().get(0);
        }
    }
    Setting setting = rootSetting;
    if (xmlField != null) {
        XPathFragment xPathFragment = xmlField.getXPathFragment();
        rootSetting = convertToSetting(xPathFragment, nsResolver);
        setting = rootSetting;
        while (xPathFragment.getNextFragment() != null) {
            xPathFragment = xPathFragment.getNextFragment();
            Setting childSetting = convertToSetting(xPathFragment, nsResolver);
            setting.addChild(childSetting);
            setting = childSetting;
        }
    }
    setting.setObject(dataObject);
    setting.setMapping(mapping);
    setting.setValue(value, false);
    return rootSetting;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) Setting(org.eclipse.persistence.oxm.sequenced.Setting) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Aggregations

XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1206 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)629 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)198 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)151 XMLField (org.eclipse.persistence.oxm.XMLField)143 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)141 QName (javax.xml.namespace.QName)75 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)69 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)49 ArrayList (java.util.ArrayList)37 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)37 XMLSchemaURLReference (org.eclipse.persistence.oxm.schema.XMLSchemaURLReference)36 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)34 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)32 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)32 Document (org.w3c.dom.Document)31 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)30 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)29 URL (java.net.URL)27 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)27