001    package org.trails.callback;
002    
003    import org.apache.commons.logging.Log;
004    import org.apache.commons.logging.LogFactory;
005    import org.apache.tapestry.IRequestCycle;
006    import org.apache.tapestry.RedirectException;
007    import org.apache.tapestry.callback.ICallback;
008    
009    /**
010     * A callback for returning to a given URL.
011     */
012    public class UrlCallback implements ICallback
013    {
014    
015            private static final Log LOG = LogFactory.getLog(UrlCallback.class);
016            private String url;
017    
018            public UrlCallback(String url)
019            {
020                    if (LOG.isDebugEnabled())
021                    {
022                            LOG.debug("Creating redirect callback for: " + url);
023                    }
024    
025                    this.url = url;
026            }
027    
028            public void performCallback(IRequestCycle iRequestCycle)
029            {
030                    throw new RedirectException(url);
031            }
032    
033            public boolean equals(Object o)
034            {
035                    if (this == o) return true;
036                    if (o == null || getClass() != o.getClass()) return false;
037    
038                    UrlCallback that = (UrlCallback) o;
039    
040                    if (!url.equals(that.url)) return false;
041    
042                    return true;
043            }
044    
045            public int hashCode()
046            {
047                    return url.hashCode();
048            }
049    }