001    package biz.hammurapi.remoting.http;
002    
003    import java.io.Serializable;
004    import java.util.Arrays;
005    
006    /**
007     * Reference for remote invocations over HTTP.
008     * @author Pavel
009     *
010     */
011    public class HttpReference implements Serializable {
012            
013    
014            private static int hashCode(Object[] array) {
015                    final int PRIME = 31;
016                    if (array == null)
017                            return 0;
018                    int result = 1;
019                    for (int index = 0; index < array.length; index++) {
020                            result = PRIME * result + (array[index] == null ? 0 : array[index].hashCode());
021                    }
022                    return result;
023            }
024    
025            private String remoteUrl;
026            
027            private String id;
028            
029            private String[] interfaces;
030    
031            public String[] getInterfaces() {
032                    return interfaces;
033            }
034    
035            public String getRemoteUrl() {
036                    return remoteUrl;
037            }
038            
039            public String getId() {
040                    return id;
041            }
042    
043            public int hashCode() {
044                    final int PRIME = 31;
045                    int result = 1;
046                    result = PRIME * result + ((id == null) ? 0 : id.hashCode());
047                    result = PRIME * result + HttpReference.hashCode(interfaces);
048                    result = PRIME * result + ((remoteUrl == null) ? 0 : remoteUrl.hashCode());
049                    return result;
050            }
051    
052            public boolean equals(Object obj) {
053                    if (this == obj)
054                            return true;
055                    if (obj == null)
056                            return false;
057                    if (getClass() != obj.getClass())
058                            return false;
059                    final HttpReference other = (HttpReference) obj;
060                    if (id == null) {
061                            if (other.id != null)
062                                    return false;
063                    } else if (!id.equals(other.id))
064                            return false;
065                    if (!Arrays.equals(interfaces, other.interfaces))
066                            return false;
067                    if (remoteUrl == null) {
068                            if (other.remoteUrl != null)
069                                    return false;
070                    } else if (!remoteUrl.equals(other.remoteUrl))
071                            return false;
072                    return true;
073            }
074    
075            public HttpReference(String remoteUrl, String[] interfaces, String id) {
076                    super();
077                    this.remoteUrl = remoteUrl;
078                    this.interfaces = interfaces;
079                    this.id = id;
080            }
081            
082            public String toString() {
083                    StringBuffer ret = new StringBuffer(getClass().getName());
084                    ret.append(" {");
085                    ret.append("url=").append(remoteUrl);
086                    ret.append(";id=").append(id);
087                    ret.append(";interfaces=");
088                    for (int i=0; i<interfaces.length; ++i) {
089                            if (i>0) {
090                                    ret.append(", ");
091                            }
092                            ret.append(interfaces[i]);
093                    }
094                    ret.append("}");
095                    return ret.toString();
096            }
097    
098    }