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 * Unless otherwise indicated, all code in ModeShape is licensed
10 * 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.graph.request;
25
26 import org.modeshape.common.util.CheckArg;
27 import org.modeshape.graph.Location;
28
29 /**
30 * Verify that a workspace exists with the supplied name. This is useful to determine the name of the "default" workspace for a
31 * source.
32 */
33 public final class VerifyWorkspaceRequest extends Request {
34
35 private static final long serialVersionUID = 1L;
36
37 private final String workspaceName;
38 private Location actualLocationOfRoot;
39 private String actualWorkspaceName;
40
41 /**
42 * Create a request to verify the existance of the named workspace.
43 *
44 * @param workspaceName the desired name of the workspace, or null if the source's default workspace should be used
45 */
46 public VerifyWorkspaceRequest( String workspaceName ) {
47 this.workspaceName = workspaceName;
48 }
49
50 /**
51 * Get the desired name for the workspace.
52 *
53 * @return the desired name for the workspace, or null if the source's default workspace is to be verified
54 */
55 public String workspaceName() {
56 return workspaceName;
57 }
58
59 /**
60 * Get the actual name of the workspace.
61 *
62 * @return the actual name of the workspace, or null if a workspace was not verified (yet)
63 */
64 public String getActualWorkspaceName() {
65 return actualWorkspaceName;
66 }
67
68 /**
69 * Set the actual name of the workspace.
70 *
71 * @param actualWorkspaceName the actual name of the workspace; never null
72 * @throws IllegalStateException if the request is frozen
73 */
74 public void setActualWorkspaceName( String actualWorkspaceName ) {
75 checkNotFrozen();
76 CheckArg.isNotNull(actualWorkspaceName, "actualWorkspaceName");
77 this.actualWorkspaceName = actualWorkspaceName;
78 }
79
80 /**
81 * Get the actual location of the root node in the new workspace, or null if the workspace was not (yet) created.
82 *
83 * @return the actual location of the root node in the new workspace, or null if the workspace was not (yet) created
84 */
85 public Location getActualLocationOfRoot() {
86 return actualLocationOfRoot;
87 }
88
89 /**
90 * Set the actual location of the root node in the new workspace.
91 *
92 * @param actualLocationOfRoot the actual location of the workspace's root node.
93 * @throws IllegalStateException if the request is frozen
94 */
95 public void setActualRootLocation( Location actualLocationOfRoot ) {
96 checkNotFrozen();
97 this.actualLocationOfRoot = actualLocationOfRoot;
98 }
99
100 /**
101 * {@inheritDoc}
102 *
103 * @see org.modeshape.graph.request.Request#isReadOnly()
104 */
105 @Override
106 public boolean isReadOnly() {
107 return false;
108 }
109
110 /**
111 * {@inheritDoc}
112 *
113 * @see org.modeshape.graph.request.Request#cancel()
114 */
115 @Override
116 public void cancel() {
117 super.cancel();
118 this.actualLocationOfRoot = null;
119 this.actualWorkspaceName = null;
120 }
121
122 /**
123 * {@inheritDoc}
124 *
125 * @see java.lang.Object#hashCode()
126 */
127 @Override
128 public int hashCode() {
129 return workspaceName.hashCode();
130 }
131
132 /**
133 * {@inheritDoc}
134 *
135 * @see java.lang.Object#equals(java.lang.Object)
136 */
137 @Override
138 public boolean equals( Object obj ) {
139 if (obj == this) return true;
140 if (this.getClass().isInstance(obj)) {
141 VerifyWorkspaceRequest that = (VerifyWorkspaceRequest)obj;
142 if (!this.workspaceName.equals(that.workspaceName())) return false;
143 return true;
144 }
145 return false;
146 }
147
148 /**
149 * {@inheritDoc}
150 *
151 * @see java.lang.Object#toString()
152 */
153 @Override
154 public String toString() {
155 return "verify workspace \"" + workspaceName() + "\"";
156 }
157
158 @Override
159 public RequestType getType() {
160 return RequestType.VERIFY_WORKSPACE;
161 }
162 }