1 /* 2 * ModeShape (http://www.modeshape.org) 3 * See the COPYRIGHT.txt file distributed with this work for information 4 * regarding copyright ownership. Some portions may be licensed 5 * to Red Hat, Inc. under one or more contributor license agreements. 6 * See the AUTHORS.txt file in the distribution for a full listing of 7 * individual contributors. 8 * 9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape 10 * is licensed to you under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation; either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * ModeShape is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this software; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 23 */ 24 package org.modeshape.web.jcr.rest.client.domain; 25 26 import net.jcip.annotations.Immutable; 27 import org.modeshape.common.util.CheckArg; 28 import org.modeshape.common.util.HashCode; 29 import org.modeshape.web.jcr.rest.client.RestClientI18n; 30 import org.modeshape.web.jcr.rest.client.Utils; 31 32 /** 33 * The <code>Server</code> class is the business object for a server that is hosting one or more ModeShape repositories. 34 */ 35 @Immutable 36 public class Server implements IModeShapeObject { 37 38 // =========================================================================================================================== 39 // Fields 40 // =========================================================================================================================== 41 42 /** 43 * The password to use when logging on to the server. 44 */ 45 private final String password; 46 47 /** 48 * The server URL (never <code>null</code>). 49 */ 50 private final String url; 51 52 /** 53 * The user name to use when logging on to the server (never <code>null</code>). 54 */ 55 private final String user; 56 57 // =========================================================================================================================== 58 // Constructors 59 // =========================================================================================================================== 60 61 /** 62 * Constructs on new <code>Server</code>. 63 * 64 * @param url the server URL (never <code>null</code>) 65 * @param user the server user (may be <code>null</code>) 66 * @param password the server password (may be <code>null</code>) 67 * @throws IllegalArgumentException if the URL or user arguments are <code>null</code> 68 */ 69 public Server( String url, 70 String user, 71 String password ) { 72 CheckArg.isNotNull(url, "url"); 73 CheckArg.isNotNull(user, "user"); 74 75 this.url = url; 76 this.user = user; 77 this.password = password; 78 } 79 80 // =========================================================================================================================== 81 // Methods 82 // =========================================================================================================================== 83 84 /** 85 * {@inheritDoc} 86 * 87 * @see java.lang.Object#equals(java.lang.Object) 88 */ 89 @Override 90 public boolean equals( Object obj ) { 91 if (this == obj) return true; 92 if ((obj == null) || (getClass() != obj.getClass())) return false; 93 94 Server otherServer = (Server)obj; 95 return Utils.equivalent(this.url, otherServer.url) && Utils.equivalent(this.user, otherServer.user) 96 && Utils.equivalent(this.password, otherServer.password); 97 } 98 99 /** 100 * {@inheritDoc} 101 * 102 * @see org.modeshape.web.jcr.rest.client.domain.IModeShapeObject#getName() 103 */ 104 public String getName() { 105 return getUrl(); 106 } 107 108 /** 109 * @return the server authentication password 110 */ 111 public String getPassword() { 112 return this.password; 113 } 114 115 /** 116 * {@inheritDoc} 117 * 118 * @see org.modeshape.web.jcr.rest.client.domain.IModeShapeObject#getShortDescription() 119 */ 120 public String getShortDescription() { 121 return RestClientI18n.serverShortDescription.text(this.url, this.user); 122 } 123 124 /** 125 * @return the server URL (never <code>null</code>) 126 */ 127 public String getUrl() { 128 return this.url; 129 } 130 131 /** 132 * @return the server authentication user (never <code>null</code>) 133 */ 134 public String getUser() { 135 return this.user; 136 } 137 138 /** 139 * {@inheritDoc} 140 * 141 * @see java.lang.Object#hashCode() 142 */ 143 @Override 144 public int hashCode() { 145 return HashCode.compute(this.url, this.user, this.password); 146 } 147 148 /** 149 * A server has the same identifying properties if their URL and user matches. 150 * 151 * @param otherServer the server whose key is being compared (never <code>null</code>) 152 * @return <code>true</code> if the servers have the same key 153 * @throws IllegalArgumentException if the argument is <code>null</code> 154 */ 155 public boolean hasSameKey( Server otherServer ) { 156 CheckArg.isNotNull(otherServer, "otherServer"); 157 return (Utils.equivalent(this.url, otherServer.url) && Utils.equivalent(this.user, otherServer.user)); 158 } 159 160 /** 161 * {@inheritDoc} 162 * 163 * @see java.lang.Object#toString() 164 */ 165 @Override 166 public String toString() { 167 return getShortDescription(); 168 } 169 170 }