Search in sources :

Example 86 with NamespaceResolver

use of org.eclipse.persistence.oxm.NamespaceResolver 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 87 with NamespaceResolver

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

the class SDOXMLHelperDelegate method getTopLinkProject.

@Override
public Project getTopLinkProject() {
    if (topLinkProject == null) {
        topLinkProject = new Project();
        XMLLogin xmlLogin = new XMLLogin();
        xmlLogin.setEqualNamespaceResolvers(false);
        topLinkProject.setDatasourceLogin(xmlLogin);
        // 200606_changeSummary
        NamespaceResolver nr = new NamespaceResolver();
        SDOTypeHelper sdoTypeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
        String sdoPrefix = sdoTypeHelper.getPrefix(SDOConstants.SDO_URL);
        nr.put(sdoPrefix, SDOConstants.SDO_URL);
        SDOType changeSummaryType = (SDOType) sdoTypeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);
        changeSummaryType.getXmlDescriptor().setNamespaceResolver(nr);
        topLinkProject.addDescriptor(changeSummaryType.getXmlDescriptor());
        SDOType openSequencedType = (SDOType) aHelperContext.getTypeHelper().getType(SDOConstants.ORACLE_SDO_URL, "OpenSequencedType");
        topLinkProject.addDescriptor(openSequencedType.getXmlDescriptor());
        SDOTypeType typeType = (SDOTypeType) aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.TYPE);
        typeType.getXmlDescriptor().setNamespaceResolver(nr);
        if (!typeType.isInitialized()) {
            typeType.initializeMappings();
        }
        topLinkProject.addDescriptor(typeType.getXmlDescriptor());
        SDOPropertyType propertyType = (SDOPropertyType) aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.PROPERTY);
        if (!propertyType.isInitialized()) {
            propertyType.initializeMappings();
        }
        topLinkProject.addDescriptor(propertyType.getXmlDescriptor());
        ((SDOTypeHelper) aHelperContext.getTypeHelper()).addWrappersToProject(topLinkProject);
    }
    return topLinkProject;
}
Also used : Project(org.eclipse.persistence.sessions.Project) SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) SDOTypeType(org.eclipse.persistence.sdo.types.SDOTypeType) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) SDOType(org.eclipse.persistence.sdo.SDOType) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) SDOPropertyType(org.eclipse.persistence.sdo.types.SDOPropertyType)

Example 88 with NamespaceResolver

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

the class SDOXSDHelperDelegate method buildAppInfoMap.

/**
 * INTERNAL:
 */
@Override
public Map buildAppInfoMap(List appInfoElements) {
    HashMap appInfoMap = new HashMap();
    // Build AppInfo map
    if (appInfoElements != null) {
        for (int i = 0; i < appInfoElements.size(); i++) {
            Element nextElement = (Element) appInfoElements.get(i);
            if (nextElement.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI) && nextElement.getLocalName().equals("appinfo")) {
                String key = nextElement.getAttribute(SDOConstants.APPINFO_SOURCE_ATTRIBUTE);
                String value = (String) appInfoMap.get(key);
                StringWriter sw = new StringWriter();
                WriterRecord wrec = new WriterRecord();
                wrec.setWriter(sw);
                wrec.node(nextElement, new NamespaceResolver());
                wrec.flush();
                appInfoMap.put(key, value == null ? sw.toString() : value + sw.toString());
            }
        }
    }
    return appInfoMap;
}
Also used : StringWriter(java.io.StringWriter) WriterRecord(org.eclipse.persistence.oxm.record.WriterRecord) FormattedWriterRecord(org.eclipse.persistence.oxm.record.FormattedWriterRecord) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 89 with NamespaceResolver

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

the class QNameTransformer method buildFieldValue.

@Override
public Object buildFieldValue(Object instance, String fieldName, Session session) {
    if (null == instance) {
        return null;
    }
    String value = (String) transformationMapping.getAttributeValueFromObject(instance);
    if (value == null) {
        return null;
    }
    int index = value.lastIndexOf(HASH);
    if (index > -1) {
        String namespaceURI = value.substring(0, index);
        String localName = value.substring(index + 1);
        String prefix = null;
        NamespaceResolver namespaceResolver = xPath.getNamespaceResolver();
        if (null != namespaceResolver) {
            prefix = namespaceResolver.resolveNamespaceURI(namespaceURI);
            if (prefix == null) {
                if (namespaceURI.equals(namespaceResolver.getDefaultNamespaceURI())) {
                    return localName;
                }
            }
            return prefix + COLON + localName;
        }
        return localName;
    } else {
        return value;
    }
}
Also used : NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 90 with NamespaceResolver

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

the class ChangeSummaryProject 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:changesummary");
    xmlDescriptor.setNamespaceResolver(namespaceResolver);
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    xmlDescriptor.addMapping(idMapping);
    XMLObjectReferenceMapping child1Mapping = new XMLObjectReferenceMapping();
    child1Mapping.setReferenceClass(Child1.class);
    child1Mapping.setAttributeName("child1");
    child1Mapping.addSourceToTargetKeyFieldAssociation("tns:child1/text()", "@id");
    xmlDescriptor.addMapping(child1Mapping);
    XMLObjectReferenceMapping child1AttributeMapping = new XMLObjectReferenceMapping();
    child1AttributeMapping.setReferenceClass(Child1.class);
    child1AttributeMapping.setAttributeName("child1Attribute");
    child1AttributeMapping.addSourceToTargetKeyFieldAssociation("@child1", "@id");
    xmlDescriptor.addMapping(child1AttributeMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLSchemaClassPathReference(org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)

Aggregations

NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)227 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)142 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)74 XMLField (org.eclipse.persistence.oxm.XMLField)36 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)36 Document (org.w3c.dom.Document)35 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)23 QName (javax.xml.namespace.QName)20 InputStream (java.io.InputStream)17 StringReader (java.io.StringReader)17 StringWriter (java.io.StringWriter)17 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)16 InputSource (org.xml.sax.InputSource)14 Element (org.w3c.dom.Element)13 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)12 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)12 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)10 HashMap (java.util.HashMap)9 Project (org.eclipse.persistence.sessions.Project)9 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)8