Code example for JAXBException

Methods: getMessage

0
                    this.classLoader);
            if (getValidationEventHandler() != null) { 
                try { 
                    u.setEventHandler(getValidationEventHandler()); 
                } catch (JAXBException e) {
                    Context.getCurrentLogger().log(Level.WARNING,
                            "Unable to set the event handler", e);
                    throw new IOException("Unable to set the event handler."
                            + e.getMessage());
                } 
            } 
 
            try { 
                this.object = (T) u.unmarshal(this,
                        this.xmlRepresentation.getReader());
            } catch (JAXBException e) {
                Context.getCurrentLogger().log(Level.WARNING,
                        "Unable to unmarshal the XML representation", e);
                throw new IOException(
                        "Unable to unmarshal the XML representation." 
                                + e.getMessage());
            } 
        } 
        return this.object;
    } 
 
    /** 
     * Returns the "xsi:schemaLocation" attribute in the generated XML data. 
     *  
     * @return The "xsi:schemaLocation" attribute in the generated XML data. 
     */ 
    public String getSchemaLocation() {
        return schemaLocation;
    } 
 
    /** 
     * Returns the optional validation event handler. 
     *  
     * @return The optional validation event handler. 
     */ 
    public ValidationEventHandler getValidationEventHandler() {
        return this.validationEventHandler;
    } 
 
    /** 
     * Indicates if the parser will expand entity reference nodes. By default 
     * the value of this is set to true. 
     *  
     * @return True if the parser will expand entity reference nodes. 
     */ 
    public boolean isExpandingEntityRefs() { 
        return expandingEntityRefs;
    } 
 
    /** 
     * Indicates if the resulting XML data should be formatted with line breaks 
     * and indentation. Defaults to false. 
     *  
     * @return the formattedOutput 
     */ 
    public boolean isFormattedOutput() { 
        return this.formattedOutput;
    } 
 
    /** 
     * Indicates whether or not document level events will be generated by the 
     * Marshaller. 
     *  
     * @return True if the document level events will be generated by the 
     *         Marshaller. 
     */ 
    public boolean isFragment() { 
        return fragment;
    } 
 
    /** 
     * Indicates if it limits potential XML overflow attacks. 
     *  
     * @return True if it limits potential XML overflow attacks. 
     */ 
    public boolean isSecureProcessing() { 
        return secureProcessing;
    } 
 
    /** 
     * Indicates the desire for validating this type of XML representations 
     * against an XML schema if one is referenced within the contents. 
     *  
     * @return True if the schema-based validation is enabled. 
     */ 
    public boolean isValidatingDtd() { 
        return validatingDtd;
    } 
 
    /** 
     * Indicates the desire for processing <em>XInclude</em> if found in this 
     * type of XML representations. By default the value of this is set to 
     * false. 
     *  
     * @return The current value of the xIncludeAware flag. 
     */ 
    public boolean isXIncludeAware() { 
        return xIncludeAware;
    } 
 
    /** 
     * Sets the classloader to use for JAXB annotated classes. 
     *  
     * @param classLoader 
     *            The classloader to use for JAXB annotated classes. 
     */ 
    public void setClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
    } 
 
    /** 
     * Sets the list of Java package names that contain schema derived class 
     * and/or Java to schema (JAXB-annotated) mapped classes. 
     *  
     * @param contextPath 
     *            The JAXB context path. 
     */ 
    public void setContextPath(String contextPath) {
        this.contextPath = contextPath;
    } 
 
    /** 
     * Indicates if the parser will expand entity reference nodes. By default 
     * the value of this is set to true. 
     *  
     * @param expandEntityRefs 
     *            True if the parser will expand entity reference nodes. 
     */ 
    public void setExpandingEntityRefs(boolean expandEntityRefs) {
        this.expandingEntityRefs = expandEntityRefs;
    } 
 
    /** 
     * Indicates if the resulting XML data should be formatted with line breaks 
     * and indentation. 
     *  
     * @param formattedOutput 
     *            True if the resulting XML data should be formatted. 
     */ 
    public void setFormattedOutput(boolean formattedOutput) {
        this.formattedOutput = formattedOutput;
    } 
 
    /** 
     * Indicates whether or not document level events will be generated by the 
     * Marshaller. 
     *  
     * @param fragment 
     *            True if the document level events will be generated by the 
     *            Marshaller. 
     */ 
    public void setFragment(boolean fragment) {
        this.fragment = fragment;
    } 
 
    /** 
     * Sets the optional namespace prefix mapper for marshalling. 
     *  
     * @param namespacePrefixMapper 
     *            The optional namespace prefix mapper for marshalling. 
     */ 
    public void setNamespacePrefixMapper( 
            NamespacePrefixMapper namespacePrefixMapper) {
        this.namespacePrefixMapper = namespacePrefixMapper;
    } 
 
    /** 
     * Sets the "xsi:noNamespaceSchemaLocation" attribute in the generated XML 
     * data. 
     *  
     * @param noNamespaceSchemaLocation 
     *            The "xsi:noNamespaceSchemaLocation" attribute in the generated 
     *            XML data. 
     */ 
    public void setNoNamespaceSchemaLocation(String noNamespaceSchemaLocation) {
        this.noNamespaceSchemaLocation = noNamespaceSchemaLocation;
    } 
 
    /** 
     * Sets the wrapped Java object. 
     *  
     * @param object 
     *            The Java object to set. 
     */ 
    public void setObject(T object) {
        this.object = object;
    } 
 
    /** 
     * Sets the "xsi:schemaLocation" attribute in the generated XML data. 
     *  
     * @param schemaLocation 
     *            The "xsi:noNamespaceSchemaLocation" attribute in the generated 
     *            XML data. 
     */ 
    public void setSchemaLocation(String schemaLocation) {
        this.schemaLocation = schemaLocation;
    } 
 
    /** 
     * Indicates if it limits potential XML overflow attacks. 
     *  
     * @param secureProcessing 
     *            True if it limits potential XML overflow attacks. 
     */ 
    public void setSecureProcessing(boolean secureProcessing) {
        this.secureProcessing = secureProcessing;
    } 
 
    /** 
     * Indicates the desire for validating this type of XML representations 
     * against an XML schema if one is referenced within the contents. 
     *  
     * @param validating 
     *            The new validation flag to set. 
     */ 
    public void setValidatingDtd(boolean validating) {
        this.validatingDtd = validating;
    } 
 
    /** 
     * Sets the validation event handler. 
     *  
     * @param validationEventHandler 
     *            The optional validation event handler. 
     */ 
    public void setValidationEventHandler( 
            ValidationEventHandler validationEventHandler) {
        this.validationEventHandler = validationEventHandler;
    } 
 
    /** 
     * Indicates the desire for processing <em>XInclude</em> if found in this 
     * type of XML representations. By default the value of this is set to 
     * false. 
     *  
     * @param includeAware 
     *            The new value of the xIncludeAware flag. 
     */ 
    public void setXIncludeAware(boolean includeAware) {
        xIncludeAware = includeAware;
    } 
 
    /** 
     * Writes the representation to a stream of characters. 
     *  
     * @param writer 
     *            The writer to use when writing. 
     *  
     * @throws IOException 
     *             If any error occurs attempting to write the stream. 
     */ 
    @Override 
    public void write(Writer writer) throws IOException {
        try { 
            new Marshaller<T>(this, this.contextPath, getClassLoader())
                    .marshal(getObject(), writer);
        } catch (JAXBException e) {
            Context.getCurrentLogger().log(Level.WARNING,
                    "JAXB marshalling error caught.", e);
 
            // Maybe the tree represents a failure, try that. 
            try { 
                new Marshaller<T>(this, "failure", getClassLoader()).marshal(
                        getObject(), writer);
            } catch (JAXBException e2) {
                // We don't know what package this tree is from. 
                throw new IOException(e.getMessage());
            } 
        } 
    } 
 
}