private XMLUnmarshaller getXmlUnmarshaller(Object options) { XMLUnmarshaller xmlUnmarshaller = getXmlUnmarshaller().clone(); if (null == options) { return xmlUnmarshaller; } try { DataObject optionsDO = (DataObject) options; if (optionsDO.isSet(SDOConstants.ATTACHMENT_UNMARSHALLER_OPTION)) { xmlUnmarshaller.setAttachmentUnmarshaller( (XMLAttachmentUnmarshaller) optionsDO.get(SDOConstants.ATTACHMENT_UNMARSHALLER_OPTION)); } return xmlUnmarshaller; } catch (ClassCastException ccException) { throw SDOException.optionsMustBeADataObject( ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS); } }
private XMLMarshaller getXmlMarshaller(Object options) { XMLMarshaller xmlMarshaller = getXmlMarshaller().clone(); if (null == options) { return xmlMarshaller; } try { DataObject optionsDO = (DataObject) options; if (optionsDO.isSet(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)) { xmlMarshaller.setAttachmentMarshaller( (XMLAttachmentMarshaller) optionsDO.get(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)); } xmlMarshaller.setMarshalListener( new SDOMarshalListener(xmlMarshaller, (SDOTypeHelper) aHelperContext.getTypeHelper())); return xmlMarshaller; } catch (ClassCastException ccException) { throw SDOException.optionsMustBeADataObject( ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS); } }
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) { unmarshalledObject = anXMLUnmarshaller.unmarshal(source, theType.getImplClass()); } 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; }