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;
}
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;
}
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;
}
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;
}
}
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;
}
Aggregations