View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.impl.wsdl.teststeps.assertions;
    14
    15  import org.apache.xmlbeans.XmlError;
    16
    17  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.support.ValidationError;
    18
    19  /***
    20   * Holder for an assertion error
    21   *
    22   * @author Ole.Matzura
    23   */
    24
    25  public class AssertionError implements ValidationError
    26  {
    27  	private String message;
    28  	private XmlError xmlError;
    29
    30  	public AssertionError( String message )
    31  	{
    32  		this.message = message;
    33  	}
    34
    35  	public AssertionError( XmlError xmlError )
    36  	{
    37  		this.xmlError = xmlError;
    38  		this.message = xmlError.getMessage();
    39  	}
    40
    41  	public String getMessage()
    42  	{
    43  		return message;
    44  	}
    45
    46  	public int getLineNumber()
    47  	{
    48  		return xmlError == null ? -1 : xmlError.getLine();
    49  	}
    50
    51  	public XmlError getXmlError()
    52  	{
    53  		return xmlError;
    54  	}
    55
    56  	public String toString()
    57  	{
    58  		if( xmlError == null )
    59  			return message;
    60
    61  		return "line " + getLineNumber() + ": " + message;
    62  	}
    63
    64  	public int hashCode()
    65  	{
    66  		final int PRIME = 31;
    67  		int result = 1;
    68  		String msg = toString();
    69  		result = PRIME * result + ((msg == null) ? 0 : msg.hashCode());
    70  		return result;
    71  	}
    72
    73  	public boolean equals(Object obj)
    74  	{
    75  		if (this == obj)
    76  			return true;
    77  		if (obj == null)
    78  			return false;
    79  		if (getClass() != obj.getClass())
    80  			return false;
    81  		final AssertionError other = (AssertionError) obj;
    82
    83  		return other.toString().equals( toString() );
    84  	}
    85  }