FileDocCategorySizeDatePackage
HeaderTerm.javaAPI DocGlassfish v2 API3875Mon May 14 15:28:50 BST 2007javax.mail.search

HeaderTerm

public final class HeaderTerm extends StringTerm
This class implements comparisons for Message headers. The comparison is case-insensitive.
author
Bill Shannon
author
John Mani

Fields Summary
protected String
headerName
The name of the header.
private static final long
serialVersionUID
Constructors Summary
public HeaderTerm(String headerName, String pattern)
Constructor.

param
headerName The name of the header
param
pattern The pattern to search for


                           
         
	super(pattern);
	this.headerName = headerName;
    
Methods Summary
public booleanequals(java.lang.Object obj)
Equality comparison.

	if (!(obj instanceof HeaderTerm))
	    return false;
	HeaderTerm ht = (HeaderTerm)obj;
	// XXX - depends on header comparisons being case independent
	return ht.headerName.equalsIgnoreCase(headerName) && super.equals(ht);
    
public java.lang.StringgetHeaderName()
Return the name of the header to compare with.

	return headerName;
    
public inthashCode()
Compute a hashCode for this object.

	// XXX - depends on header comparisons being case independent
	return headerName.toLowerCase(Locale.ENGLISH).hashCode() +
					super.hashCode();
    
public booleanmatch(javax.mail.Message msg)
The header match method.

param
msg The match is applied to this Message's header
return
true if the match succeeds, otherwise false

	String[] headers;

	try {
	    headers = msg.getHeader(headerName);
	} catch (Exception e) {
	    return false;
	}

	if (headers == null)
	    return false;

	for (int i=0; i < headers.length; i++)
	    if (super.match(headers[i]))
		return true;
	return false;