// Path: mathdragon/src/main/java/org/teaminfty/math_dragon/exceptions/ParseException.java
// public class ParseException extends MathException
// {
//     private static final long serialVersionUID = -5061683875213406313L;
// 
//     // note: javadoc copy-pasted from exception, because {@inheritDoc} doesn't
//     // work for some reason
//     /**
//      * Constructs a new parse exception with <code>null</code> as its detail
//      * message. The cause is not initialized, and may subsequently be
//      * initialized by a call to {@link #initCause}.
//      */
//     public ParseException()
//     {}
// 
//     /**
//      * Constructs a new parse exception with the specified detail message. The
//      * cause is not initialized, and may subsequently be initialized by a call
//      * to {@link #initCause}.
//      * 
//      * @param message
//      *        the detail message. The detail message is saved for later
//      *        retrieval by the {@link #getMessage()} method.
//      */
//     public ParseException(String message)
//     {
//         super(message);
//     }
// 
//     /**
//      * Constructs a new parse exception with the specified cause and a detail
//      * message of <tt>(cause==null ? null : cause.toString())</tt> (which
//      * typically contains the class and detail message of <tt>cause</tt>). This
//      * constructor is useful for exceptions that are little more than wrappers
//      * for other throwables (for example,
//      * {@link java.security.PrivilegedActionException}).
//      * 
//      * @param cause
//      *        the cause (which is saved for later retrieval by the
//      *        {@link #getCause()} method). (A <tt>null</tt> value is permitted,
//      *        and indicates that the cause is nonexistent or unknown.)
//      * @since 1.4
//      */
//     public ParseException(Throwable cause)
//     {
//         super(cause);
//     }
// 
//     /**
//      * Construct a new parse exception with the specified cause and a detail
//      * message that describes the error.
//      * 
//      * @param message
//      *        The detailed human-readable message.
//      * @param cause
//      *        Some evil demon that wants to crash our program.
//      */
//     public ParseException(String message, Throwable cause)
//     {
//         super(message, cause);
//     }
// 
//     /**
//      * Construct a new parse exception with the specified abstract syntax tree
//      * that caused this exception to be thrown.
//      * 
//      * @param ast
//      *        The abstract syntax tree from Symja.
//      */
//     public ParseException(AST ast)
//     {
//         super(ast.toString() + ": invalid operation");
//     }
// 
//     /**
//      * Construct a new parse exception with the specified mathematical
//      * expression that caused this exception to be thrown.
//      * 
//      * @param expr
//      *        The mathematical expression from Symja.
//      */
//     public ParseException(IExpr expr)
//     {
//         super(expr.toString() + ": invalid operation");
//     }
// }


import javax.xml.parsers.ParserConfigurationException;
import org.teaminfty.math_dragon.exceptions.ParseException;
import org.w3c.dom.Document;
package org.teaminfty.math_dragon.view.math;



public final class ExpressionDuplicator
{
    /** Creates a deep copy of the given {@link Expression}
     * @param src The {@link Expression} to copy
     * @return The copy of the given {@link Expression} (returns <tt>null</tt> if the function somehow fails) */
    public static Expression deepCopy(Expression src)
    {
        try
        {
            // Create a XML document of the source object
            Document doc = Expression.createXMLDocument();
            src.writeToXML(doc, doc.getDocumentElement());
            
            // Create a new object from the XML and return that object
            return ExpressionXMLReader.fromXML(doc);
        }
        catch(ParserConfigurationException e)
        {
            e.printStackTrace();
            return null;
        }
// Path: mathdragon/src/main/java/org/teaminfty/math_dragon/exceptions/ParseException.java
// public class ParseException extends MathException
// {
//     private static final long serialVersionUID = -5061683875213406313L;
// 
//     // note: javadoc copy-pasted from exception, because {@inheritDoc} doesn't
//     // work for some reason
//     /**
//      * Constructs a new parse exception with <code>null</code> as its detail
//      * message. The cause is not initialized, and may subsequently be
//      * initialized by a call to {@link #initCause}.
//      */
//     public ParseException()
//     {}
// 
//     /**
//      * Constructs a new parse exception with the specified detail message. The
//      * cause is not initialized, and may subsequently be initialized by a call
//      * to {@link #initCause}.
//      * 
//      * @param message
//      *        the detail message. The detail message is saved for later
//      *        retrieval by the {@link #getMessage()} method.
//      */
//     public ParseException(String message)
//     {
//         super(message);
//     }
// 
//     /**
//      * Constructs a new parse exception with the specified cause and a detail
//      * message of <tt>(cause==null ? null : cause.toString())</tt> (which
//      * typically contains the class and detail message of <tt>cause</tt>). This
//      * constructor is useful for exceptions that are little more than wrappers
//      * for other throwables (for example,
//      * {@link java.security.PrivilegedActionException}).
//      * 
//      * @param cause
//      *        the cause (which is saved for later retrieval by the
//      *        {@link #getCause()} method). (A <tt>null</tt> value is permitted,
//      *        and indicates that the cause is nonexistent or unknown.)
//      * @since 1.4
//      */
//     public ParseException(Throwable cause)
//     {
//         super(cause);
//     }
// 
//     /**
//      * Construct a new parse exception with the specified cause and a detail
//      * message that describes the error.
//      * 
//      * @param message
//      *        The detailed human-readable message.
//      * @param cause
//      *        Some evil demon that wants to crash our program.
//      */
//     public ParseException(String message, Throwable cause)
//     {
//         super(message, cause);
//     }
// 
//     /**
//      * Construct a new parse exception with the specified abstract syntax tree
//      * that caused this exception to be thrown.
//      * 
//      * @param ast
//      *        The abstract syntax tree from Symja.
//      */
//     public ParseException(AST ast)
//     {
//         super(ast.toString() + ": invalid operation");
//     }
// 
//     /**
//      * Construct a new parse exception with the specified mathematical
//      * expression that caused this exception to be thrown.
//      * 
//      * @param expr
//      *        The mathematical expression from Symja.
//      */
//     public ParseException(IExpr expr)
//     {
//         super(expr.toString() + ": invalid operation");
//     }
// }


// Path: mathdragon/src/main/java/org/teaminfty/math_dragon/view/math/ExpressionDuplicator.java
import javax.xml.parsers.ParserConfigurationException;
import org.teaminfty.math_dragon.exceptions.ParseException;
import org.w3c.dom.Document;

package org.teaminfty.math_dragon.view.math;



public final class ExpressionDuplicator
{
    /** Creates a deep copy of the given {@link Expression}
     * @param src The {@link Expression} to copy
     * @return The copy of the given {@link Expression} (returns <tt>null</tt> if the function somehow fails) */
    public static Expression deepCopy(Expression src)
    {
        try
        {
            // Create a XML document of the source object
            Document doc = Expression.createXMLDocument();
            src.writeToXML(doc, doc.getDocumentElement());
            
            // Create a new object from the XML and return that object
            return ExpressionXMLReader.fromXML(doc);
        }
        catch(ParserConfigurationException e)
        {
            e.printStackTrace();
            return null;
        }
        catch(ParseException e)