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 <code>Workspace</code> class is the business object for a ModeShape repository workspace. 33 */ 34 @Immutable 35 public class Workspace implements IModeShapeObject { 36 37 // =========================================================================================================================== 38 // Fields 39 // =========================================================================================================================== 40 41 /** 42 * The workspace name. 43 */ 44 private final String name; 45 46 /** 47 * The repository where this workspace resides. 48 */ 49 private final Repository repository; 50 51 // =========================================================================================================================== 52 // Constructors 53 // =========================================================================================================================== 54 55 /** 56 * Constructs a new <code>Workspace</code>. 57 * 58 * @param name the workspace name (never <code>null</code>) 59 * @param repository the repository where this workspace resides (never <code>null</code>) 60 * @throws IllegalArgumentException if any of the arguments are <code>null</code> 61 */ 62 public Workspace( String name, 63 Repository repository ) { 64 assert name != null; 65 assert repository != null; 66 this.name = name; 67 this.repository = repository; 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 Workspace otherWorkspace = (Workspace)obj; 85 return (this.name.equals(otherWorkspace.name) && this.repository.equals(otherWorkspace.repository)); 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 repository where this workspace is located (never <code>null</code>) 99 */ 100 public Repository getRepository() { 101 return this.repository; 102 } 103 104 /** 105 * @return the server where this workspace is located (never <code>null</code>) 106 */ 107 public Server getServer() { 108 return this.repository.getServer(); 109 } 110 111 /** 112 * {@inheritDoc} 113 * 114 * @see org.modeshape.web.jcr.rest.client.domain.IModeShapeObject#getShortDescription() 115 */ 116 public String getShortDescription() { 117 return RestClientI18n.workspaceShortDescription.text(this.name, this.repository.getName()); 118 } 119 120 /** 121 * {@inheritDoc} 122 * 123 * @see java.lang.Object#hashCode() 124 */ 125 @Override 126 public int hashCode() { 127 return HashCode.compute(this.name, this.repository); 128 } 129 130 /** 131 * {@inheritDoc} 132 * 133 * @see java.lang.Object#toString() 134 */ 135 @Override 136 public String toString() { 137 return getShortDescription(); 138 } 139 140 }