Search in sources :

Example 1 with Setting

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

the class SDOSequence method convertToSetting.

private Setting convertToSetting(XPathFragment xPathFragment, NamespaceResolver nsResolver) {
    Setting setting = new Setting();
    String name = xPathFragment.getLocalName();
    if (null == name) {
        name = xPathFragment.getShortName();
    }
    setting.setName(name);
    if (xPathFragment.hasNamespace()) {
        setting.setNamespaceURI(nsResolver.resolveNamespacePrefix(xPathFragment.getPrefix()));
    }
    return setting;
}
Also used : Setting(org.eclipse.persistence.oxm.sequenced.Setting)

Example 2 with Setting

use of org.eclipse.persistence.oxm.sequenced.Setting 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 3 with Setting

use of org.eclipse.persistence.oxm.sequenced.Setting 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)

Example 4 with Setting

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

the class SDOSequence method remove.

private void remove(Setting setting) {
    CoreMapping mapping = setting.getMapping();
    if (null != mapping) {
        Property property = null;
        if (null == setting.getName()) {
            XMLRoot xmlRoot = (XMLRoot) setting.getValue();
            if (null != xmlRoot) {
                property = dataObject.getInstanceProperty(xmlRoot.getLocalName());
                valuesToSettings.remove(new Key(property, setting.getValue()));
            }
        } else {
            property = dataObject.getInstanceProperty(mapping.getAttributeName());
            valuesToSettings.remove(new Key(property, setting.getValue()));
        }
        if (property.isMany()) {
            ListWrapper listWrapper = (ListWrapper) dataObject.getList(property);
            listWrapper.remove(setting.getValue(), false, false);
        } else {
            dataObject.unset(property, false, false);
        }
    } else if (setting.getName() != null && setting.getName().equals(TEXT_XPATH)) {
        // Handle "text()"
        dataObject._setModified(true);
    }
    List<Setting> children = setting.getChildren();
    if (null != children) {
        int childrenSize = children.size();
        for (int x = 0; x < childrenSize; x++) {
            remove(children.get(x));
        }
    }
}
Also used : XMLRoot(org.eclipse.persistence.oxm.XMLRoot) Setting(org.eclipse.persistence.oxm.sequenced.Setting) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) Property(commonj.sdo.Property)

Example 5 with Setting

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

the class SDOSequence method addSettingWithoutModifyingDataObject.

/**
 * INTERNAL:
 */
public boolean addSettingWithoutModifyingDataObject(Property property, Object value, boolean checkAllowed) {
    if (checkAllowed && !isAllowedInSequence(property)) {
        return false;
    }
    Setting setting = convertToSetting(property, value);
    valuesToSettings.put(new Key(property, value), setting);
    settings.add(setting);
    return true;
}
Also used : Setting(org.eclipse.persistence.oxm.sequenced.Setting)

Aggregations

Setting (org.eclipse.persistence.oxm.sequenced.Setting)33 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)9 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)8 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)6 DataObject (commonj.sdo.DataObject)4 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)4 Property (commonj.sdo.Property)3 List (java.util.List)3 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)3 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)2 QName (javax.xml.namespace.QName)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)1