public void defaultNamespaceDeclaration(String defaultNamespace){ try{ xmlStreamWriter.writeDefaultNamespace(defaultNamespace); } catch(XMLStreamException e) { throw XMLMarshalException.marshalException(e); } }
private JAXBException handleXMLMarshalException(XMLMarshalException xmlMarshalException) { if(xmlMarshalException.getErrorCode() == XMLMarshalException.NULL_ARGUMENT) { throw new IllegalArgumentException(xmlMarshalException); } else { return new UnmarshalException(xmlMarshalException); } }
/** * PUBLIC: * Read and parse the XML document from the url and map the XML data into an object. * The url must reference a valid XML document, and be mapped by a project used to * create the XMLContext. * @param url The url to unmarshal from * @param clazz The type of object to return. * @return the object which resulted from unmarshalling the given url * @throws XMLMarshalException if an error occurred during unmarshalling */ public Object unmarshal(URL url, Class clazz) throws XMLMarshalException { if ((null == url) || (null == clazz)) { throw XMLMarshalException.nullArgumentException(); } return platformUnmarshaller.unmarshal(url, clazz); }
private void handleXMLMarshalException(XMLMarshalException xmlException) throws IOException { if(xmlException.getErrorCode() == XMLMarshalException.NO_DESCRIPTOR_WITH_MATCHING_ROOT_ELEMENT || xmlException.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT){ throw SDOException.globalPropertyNotFound(); } else if (xmlException.getCause() instanceof IOException) { throw (IOException) xmlException.getCause(); } else{ throw xmlException; } }
public static XMLMarshalException unmappedContentHandlerDoesntImplement(Exception nestedException, String className) { Object[] args = { className }; XMLMarshalException exception = new XMLMarshalException(ExceptionMessageGenerator.buildMessage(XMLMarshalException.class, UNMAPPED_CONTENTHANDLER_DOESNT_IMPLEMENT, args), nestedException); exception.setErrorCode(UNMAPPED_CONTENTHANDLER_DOESNT_IMPLEMENT); exception.setInternalException(nestedException); return exception; }
public static XMLMarshalException nullArgumentException() { Object[] args = { }; XMLMarshalException exception = new XMLMarshalException(ExceptionMessageGenerator.buildMessage(XMLMarshalException.class, NULL_ARGUMENT, args)); exception.setErrorCode(NULL_ARGUMENT); return exception; }
/** * INTERNAL: * Return the namespace uri for the prefix of the given local name */ private String resolveNamespace(NamespaceResolver namespaceResolver, String localName) { int colonIndex = localName.indexOf(':'); if (colonIndex < 0) { // handle target/default namespace if (namespaceResolver != null) { return namespaceResolver.resolveNamespacePrefix(Constants.EMPTY_STRING); } return null; } else { if (namespaceResolver == null) { //throw an exception if the name has a : in it but the namespaceresolver is null throw XMLMarshalException.namespaceResolverNotSpecified(localName); } String prefix = localName.substring(0, colonIndex); String uri = namespaceResolver.resolveNamespacePrefix(prefix); if (uri == null) { //throw an exception if the prefix is not found in the namespaceresolver throw XMLMarshalException.namespaceNotFound(prefix); } return uri; } }
writerRecord.flush(); }catch(XMLMarshalException xme){ if(xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT){ if(aHelperContext != ((SDOType)rootObject.getType()).getHelperContext()){ throw SDOException.dataObjectNotFromHelperContext(); writer.flush(); } catch(IOException ex) { throw XMLMarshalException.marshalException(ex);
private EclipseLinkException convertSAXException(SAXException saxException) { Exception internalException = saxException.getException(); if (internalException != null) { if (EclipseLinkException.class.isAssignableFrom(internalException.getClass())) { return (EclipseLinkException) internalException; } else { return XMLMarshalException.unmarshalException(internalException); } } return XMLMarshalException.unmarshalException(saxException); }
unmarshalRecord = xmlUnmarshaller.createUnmarshalRecord(xmlDescriptor, session); } catch (XMLMarshalException xme) { if (xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT) { isPrimitiveWrapper = isPrimitiveWrapper(clazz); if (isPrimitiveWrapper) { throw XMLMarshalException.unmarshalException(e); } catch (SAXException e) { throw convertSAXException(e);
public SAXUnmarshaller(Unmarshaller xmlUnmarshaller, Map<String, Boolean> parserFeatures) throws XMLMarshalException { super(); this.parserFeatures = parserFeatures; try { this.xmlUnmarshaller = xmlUnmarshaller; } catch (Exception e) { throw XMLMarshalException.errorInstantiatingSchemaPlatform(e); } }
/** * INTERNAL: * Return the descriptor for the root object. */ private XMLDescriptor getDescriptor(Class clazz, AbstractSession session) throws XMLMarshalException { XMLDescriptor descriptor = (XMLDescriptor) session.getDescriptor(clazz); if (descriptor == null) { throw XMLMarshalException.descriptorNotFoundInProject(clazz.getName()); } return descriptor; }
protected AbstractRecord buildCompositeRow(Object attributeValue, AbstractSession session, XMLDescriptor referenceDescriptor, AbstractRecord parentRow, DatabaseField field, Object originalObject, boolean wasXMLRoot) { String defaultRootElementString = null; if(referenceDescriptor != null){ defaultRootElementString = referenceDescriptor.getDefaultRootElement(); if (!wasXMLRoot && defaultRootElementString == null) { throw XMLMarshalException.defaultRootElementNotSpecified((XMLDescriptor) descriptor); } } if ((field == null) && (referenceDescriptor != null) && (defaultRootElementString != null)) { field = referenceDescriptor.buildField(defaultRootElementString); } if ((field != null) && (referenceDescriptor != null)) { ((XMLRecord) parentRow).setLeafElementType(referenceDescriptor.getDefaultRootElementType()); XMLObjectBuilder objectBuilder = (XMLObjectBuilder) referenceDescriptor.getObjectBuilder(); XMLRecord child = (XMLRecord) objectBuilder.createRecordFor(attributeValue, (XMLField) field, (XMLRecord) parentRow, this); child.setNamespaceResolver(((XMLRecord) parentRow).getNamespaceResolver()); objectBuilder.buildIntoNestedRow(child, originalObject, attributeValue, session, referenceDescriptor, (XMLField) field, wasXMLRoot); return child; } return null; }
/** * Return a QName representing the value of the xsi:type attribute or null if one is not present */ private QName getTypeAttributeQName(Attributes atts) { int attributeSize = atts.getLength(); for (int i = 0; i < attributeSize; i++) { String stringValue = atts.getValue(i); String uri = atts.getURI(i); String attrName = atts.getLocalName(i); if (javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(uri) && XMLConstants.SCHEMA_TYPE_ATTRIBUTE.equals(attrName)) { int colonIndex = stringValue.indexOf(':'); String localPrefix = stringValue.substring(0, colonIndex); String localURI = unmarshalNamespaceResolver.getNamespaceURI(localPrefix); if (localURI != null) { String localName = stringValue.substring(colonIndex + 1, stringValue.length()); QName theQName = new QName(localURI, localName); currentSchemaType = theQName; return theQName; } else { throw XMLMarshalException.namespaceNotFound(localPrefix); } } } return null; }
final XMLMarshalException e = XMLMarshalException.missingIDForIDRef( Object.class.getName(), primaryKey.getPrimaryKey()); if (handler != null) { final SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), null, e); try { handler.warning(saxParseException); final XMLMarshalException e = XMLMarshalException.missingIDForIDRef( referenceTargetClass.getName(), primaryKey.getPrimaryKey()); if (handler != null) { SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), null, e); try { handler.warning(saxParseException);
/** * INTERNAL: * Exception when an XMLMarshalException happens */ public static SDOException xmlMarshalExceptionOccurred(XMLMarshalException nestedException, String rootElementURI, String rootElementName) { Object[] args = { nestedException.getLocalizedMessage(), rootElementURI, rootElementName}; SDOException exception = new SDOException(ExceptionMessageGenerator.buildMessage(SDOException.class, XMLMARSHAL_EXCEPTION_OCCURRED, args), nestedException); exception.setErrorCode(XMLMARSHAL_EXCEPTION_OCCURRED); return exception; }
public static XMLMarshalException errorProcessingIDResolver(String methodName, Object resolver, Throwable nestedException) { Object[] args = {methodName, resolver}; XMLMarshalException exception = new XMLMarshalException(ExceptionMessageGenerator.buildMessage(XMLMarshalException.class, ERROR_PROCESSING_ID_RESOLVER, args)); exception.setErrorCode(ERROR_PROCESSING_ID_RESOLVER); exception.setInternalException(nestedException); return exception; }
/** * INTERNAL: * Return the namespace uri for the prefix of the given local name */ private String resolveNamespace(NamespaceResolver namespaceResolver, String localName) { int colonIndex = localName.indexOf(':'); if (colonIndex < 0) { // handle target/default namespace if (namespaceResolver != null) { return namespaceResolver.resolveNamespacePrefix(XMLConstants.EMPTY_STRING); } return null; } else { if (namespaceResolver == null) { //throw an exception if the name has a : in it but the namespaceresolver is null throw XMLMarshalException.namespaceResolverNotSpecified(localName); } String prefix = localName.substring(0, colonIndex); String uri = namespaceResolver.resolveNamespacePrefix(prefix); if (uri == null) { //throw an exception if the prefix is not found in the namespaceresolver throw XMLMarshalException.namespaceNotFound(prefix); } return uri; } }
public static XMLMarshalException errorInvokingPrefixMapperMethod(String methodName, Object prefixMapper) { Object[] args = {methodName, prefixMapper}; XMLMarshalException exception = new XMLMarshalException(ExceptionMessageGenerator.buildMessage(XMLMarshalException.class, ERROR_INVOKING_NAMESPACE_PREFIX_MAPPER, args)); exception.setErrorCode(ERROR_INVOKING_NAMESPACE_PREFIX_MAPPER); return exception; }
writerRecord.flush(); }catch(XMLMarshalException xme){ if(xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT){ if(aHelperContext != ((SDOType)rootObject.getType()).getHelperContext()){ throw SDOException.dataObjectNotFromHelperContext(); writer.flush(); } catch(IOException ex) { throw XMLMarshalException.marshalException(ex);