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 28 import org.modeshape.common.util.HashCode; 29 import org.modeshape.web.jcr.rest.client.RestClientI18n; 30 31 /** 32 * The Repository class is the business object for a ModeShape repository. 33 */ 34 @Immutable 35 public class Repository implements IModeShapeObject { 36 37 // =========================================================================================================================== 38 // Fields 39 // =========================================================================================================================== 40 41 /** 42 * The repository name. 43 */ 44 private final String name; 45 46 /** 47 * The server where this repository resides. 48 */ 49 private final Server server; 50 51 // =========================================================================================================================== 52 // Constructors 53 // =========================================================================================================================== 54 55 /** 56 * Constructs a new <code>Repository</code>. 57 * 58 * @param name the repository name (never <code>null</code>) 59 * @param server the server where this repository resides (never <code>null</code>) 60 * @throws IllegalArgumentException if the name or server argument is <code>null</code> 61 */ 62 public Repository( String name, 63 Server server ) { 64 assert name != null; 65 assert server != null; 66 this.name = name; 67 this.server = server; 68 } 69 70 // =========================================================================================================================== 71 // Methods 72 // =========================================================================================================================== 73 74 /** 75 * {@inheritDoc} 76 * 77 * @see java.lang.Object#equals(java.lang.Object) 78 */ 79 @Override 80 public boolean equals( Object obj ) { 81 if (this == obj) return true; 82 if ((obj == null) || (getClass() != obj.getClass())) return false; 83 84 Repository otherRepository = (Repository)obj; 85 return (this.name.equals(otherRepository.name) && this.server.equals(otherRepository.server)); 86 } 87 88 /** 89 * {@inheritDoc} 90 * 91 * @see org.modeshape.web.jcr.rest.client.domain.IModeShapeObject#getName() 92 */ 93 public String getName() { 94 return this.name; 95 } 96 97 /** 98 * @return the server where this repository is located (never <code>null</code>) 99 */ 100 public Server getServer() { 101 return this.server; 102 } 103 104 /** 105 * {@inheritDoc} 106 * 107 * @see org.modeshape.web.jcr.rest.client.domain.IModeShapeObject#getShortDescription() 108 */ 109 public String getShortDescription() { 110 return RestClientI18n.repositoryShortDescription.text(this.name, this.server.getName()); 111 } 112 113 /** 114 * {@inheritDoc} 115 * 116 * @see java.lang.Object#hashCode() 117 */ 118 @Override 119 public int hashCode() { 120 return HashCode.compute(this.name, this.server); 121 } 122 123 /** 124 * {@inheritDoc} 125 * 126 * @see java.lang.Object#toString() 127 */ 128 @Override 129 public String toString() { 130 return getShortDescription(); 131 } 132 133 }