use of org.eclipse.persistence.oxm.XMLRoot in project eclipselink by eclipse-ee4j.
the class SDODataObject method _getOpenContentPropertiesWithXMLRoots.
/**
* INTERNAL:
* This function is implemented by SDOType.setOpen() in a mapping setGet/SetMethodName call
* @return
*/
public List _getOpenContentPropertiesWithXMLRoots() {
List returnList = new ArrayList();
for (int i = 0, size = openContentProperties.size(); i < size; i++) {
SDOProperty next = (SDOProperty) openContentProperties.get(i);
XMLRoot root = new XMLRoot();
String localName = next.getXPath();
if (next.getType() != null) {
if (!next.getType().isDataType()) {
String uri = next.getUri();
root.setNamespaceURI(uri);
} else {
String uri = next.getUri();
root.setNamespaceURI(uri);
}
}
root.setLocalName(localName);
Object value = get(next);
if (next.isMany()) {
for (int j = 0, sizel = ((List) value).size(); j < sizel; j++) {
XMLRoot nextRoot = new XMLRoot();
nextRoot.setNamespaceURI(root.getNamespaceURI());
nextRoot.setLocalName(root.getLocalName());
Object nextItem = ((List) value).get(j);
if ((next.getType() != null) && (next.getType().getXmlDescriptor() == null)) {
nextItem = XMLConversionManager.getDefaultXMLManager().convertObject(nextItem, String.class);
}
nextRoot.setObject(nextItem);
returnList.add(nextRoot);
}
} else {
if ((next.getType() != null) && (next.getType().getXmlDescriptor() == null)) {
value = XMLConversionManager.getDefaultXMLManager().convertObject(value, String.class);
}
root.setObject(value);
returnList.add(root);
}
}
return returnList;
}
use of org.eclipse.persistence.oxm.XMLRoot 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;
}
use of org.eclipse.persistence.oxm.XMLRoot 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));
}
}
}
use of org.eclipse.persistence.oxm.XMLRoot in project eclipselink by eclipse-ee4j.
the class SDOXMLHelperDelegate method load.
/**
* Creates and returns an XMLDocument from the inputSource.
* The InputSource will be closed after reading.
* By default does not perform XSD validation.
* @param inputSource specifies the InputSource to read from
* @param locationURI specifies the URI of the document for relative schema locations
* @param options implementation-specific options.
* @return the new XMLDocument loaded
* @throws IOException for stream exceptions.
* @throws RuntimeException for errors in XML parsing or
* implementation-specific validation.
*/
@Override
public XMLDocument load(InputSource inputSource, String locationURI, Object options) throws IOException {
// get XMLUnmarshaller once - as we may create a new instance if this helper isDirty=true
XMLUnmarshaller anXMLUnmarshaller = getXmlUnmarshaller(options);
Object unmarshalledObject = null;
if (options == null) {
try {
unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
} catch (XMLMarshalException xmlException) {
handleXMLMarshalException(xmlException);
}
} else {
try {
DataObject optionsDataObject = (DataObject) options;
try {
SDOType theType = (SDOType) optionsDataObject.get(SDOConstants.TYPE_LOAD_OPTION);
try {
if (theType != null) {
if (theType.isDataType()) {
theType = (SDOType) ((SDOTypeHelper) this.aHelperContext.getTypeHelper()).getWrappersHashMap().get(theType.getQName());
}
if (theType != null) {
unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource, theType.getImplClass());
} else {
unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
}
} else {
unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
}
} catch (XMLMarshalException xmlException) {
handleXMLMarshalException(xmlException);
}
} catch (ClassCastException ccException) {
throw SDOException.typePropertyMustBeAType(ccException);
}
} catch (ClassCastException ccException) {
throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
}
}
if (unmarshalledObject instanceof XMLRoot) {
XMLRoot xmlRoot = (XMLRoot) unmarshalledObject;
XMLDocument xmlDocument = createDocument((DataObject) ((XMLRoot) unmarshalledObject).getObject(), ((XMLRoot) unmarshalledObject).getNamespaceURI(), ((XMLRoot) unmarshalledObject).getLocalName());
if (xmlRoot.getEncoding() != null) {
xmlDocument.setEncoding(xmlRoot.getEncoding());
}
if (xmlRoot.getXMLVersion() != null) {
xmlDocument.setXMLVersion(xmlRoot.getXMLVersion());
}
xmlDocument.setSchemaLocation(xmlRoot.getSchemaLocation());
xmlDocument.setNoNamespaceSchemaLocation(xmlRoot.getNoNamespaceSchemaLocation());
return xmlDocument;
} else if (unmarshalledObject instanceof DataObject) {
String localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXmlDescriptor().getDefaultRootElement();
if (localName == null) {
localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXsdLocalName();
}
return createDocument((DataObject) unmarshalledObject, ((DataObject) unmarshalledObject).getType().getURI(), localName);
} else if (unmarshalledObject instanceof XMLDocument) {
return (XMLDocument) unmarshalledObject;
}
return null;
}
use of org.eclipse.persistence.oxm.XMLRoot in project eclipselink by eclipse-ee4j.
the class SDOXMLHelperDelegate method load.
@Override
public XMLDocument load(Source source, String locationURI, Object options) throws IOException {
// get XMLUnmarshaller once - as we may create a new instance if this helper isDirty=true
XMLUnmarshaller anXMLUnmarshaller = getXmlUnmarshaller(options);
Object unmarshalledObject = null;
if (options == null) {
try {
unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
} catch (XMLMarshalException xmlException) {
handleXMLMarshalException(xmlException);
}
} else {
try {
DataObject optionsDataObject = (DataObject) options;
try {
SDOType theType = (SDOType) optionsDataObject.get(SDOConstants.TYPE_LOAD_OPTION);
try {
if (theType != null) {
if (theType.isDataType()) {
theType = (SDOType) ((SDOTypeHelper) this.aHelperContext.getTypeHelper()).getWrappersHashMap().get(theType.getQName());
}
if (theType != null) {
unmarshalledObject = anXMLUnmarshaller.unmarshal(source, theType.getImplClass());
} else {
unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
}
} else {
unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
}
} catch (XMLMarshalException xmlException) {
handleXMLMarshalException(xmlException);
}
} catch (ClassCastException ccException) {
throw SDOException.typePropertyMustBeAType(ccException);
}
} catch (ClassCastException ccException) {
throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
}
}
if (unmarshalledObject instanceof XMLRoot) {
XMLRoot xmlRoot = (XMLRoot) unmarshalledObject;
XMLDocument xmlDocument = createDocument((DataObject) ((XMLRoot) unmarshalledObject).getObject(), ((XMLRoot) unmarshalledObject).getNamespaceURI(), ((XMLRoot) unmarshalledObject).getLocalName());
if (xmlRoot.getEncoding() != null) {
xmlDocument.setEncoding(xmlRoot.getEncoding());
}
if (xmlRoot.getXMLVersion() != null) {
xmlDocument.setXMLVersion(xmlRoot.getXMLVersion());
}
xmlDocument.setSchemaLocation(xmlRoot.getSchemaLocation());
xmlDocument.setNoNamespaceSchemaLocation(xmlRoot.getNoNamespaceSchemaLocation());
return xmlDocument;
} else if (unmarshalledObject instanceof DataObject) {
DataObject unmarshalledDataObject = (DataObject) unmarshalledObject;
String localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXmlDescriptor().getDefaultRootElement();
if (localName == null) {
localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXsdLocalName();
}
return createDocument(unmarshalledDataObject, unmarshalledDataObject.getType().getURI(), localName);
} else if (unmarshalledObject instanceof XMLDocument) {
return (XMLDocument) unmarshalledObject;
}
return null;
}
Aggregations