View Javadoc

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  import org.modeshape.graph.property.Path;
29  
30  /**
31   * Request that an existing workspace with the supplied name be destroyed.
32   */
33  public final class DestroyWorkspaceRequest extends ChangeRequest {
34  
35      private static final long serialVersionUID = 1L;
36  
37      private final String workspaceName;
38      private Location actualLocationOfRoot;
39  
40      /**
41       * Create a request to destroy an existing workspace.
42       * 
43       * @param workspaceName the name of the workspace that is to be destroyed
44       * @throws IllegalArgumentException if the workspace name is null
45       */
46      public DestroyWorkspaceRequest( String workspaceName ) {
47          CheckArg.isNotNull(workspaceName, "workspaceName");
48          this.workspaceName = workspaceName;
49      }
50  
51      /**
52       * Get the name for the workspace that is to be destroyed.
53       * 
54       * @return the name for the workspace; never null
55       */
56      public String workspaceName() {
57          return workspaceName;
58      }
59  
60      /**
61       * Get the actual location of the root node in the new workspace, or null if the workspace was not (yet) created.
62       * 
63       * @return the actual location of the root node in the new workspace, or null if the workspace was not (yet) created
64       */
65      public Location getActualLocationOfRoot() {
66          return actualLocationOfRoot;
67      }
68  
69      /**
70       * Set the actual location of the root node in the new workspace.
71       * 
72       * @param actualLocationOfRoot the actual location of the workspace's root node.
73       * @throws IllegalStateException if the request is frozen
74       */
75      public void setActualRootLocation( Location actualLocationOfRoot ) {
76          checkNotFrozen();
77          this.actualLocationOfRoot = actualLocationOfRoot;
78      }
79  
80      /**
81       * {@inheritDoc}
82       * 
83       * @see org.modeshape.graph.request.Request#isReadOnly()
84       */
85      @Override
86      public boolean isReadOnly() {
87          return false;
88      }
89  
90      /**
91       * {@inheritDoc}
92       * 
93       * @see java.lang.Object#hashCode()
94       */
95      @Override
96      public int hashCode() {
97          return workspaceName.hashCode();
98      }
99  
100     /**
101      * {@inheritDoc}
102      * 
103      * @see java.lang.Object#equals(java.lang.Object)
104      */
105     @Override
106     public boolean equals( Object obj ) {
107         if (obj == this) return true;
108         if (this.getClass().isInstance(obj)) {
109             DestroyWorkspaceRequest that = (DestroyWorkspaceRequest)obj;
110             if (!this.workspaceName.equals(that.workspaceName())) return false;
111             return true;
112         }
113         return false;
114     }
115 
116     /**
117      * {@inheritDoc}
118      * 
119      * @see java.lang.Object#toString()
120      */
121     @Override
122     public String toString() {
123         return "destroy workspace \"" + workspaceName() + "\"";
124     }
125 
126     /**
127      * {@inheritDoc}
128      * 
129      * @see org.modeshape.graph.request.ChangeRequest#changedLocation()
130      */
131     @Override
132     public Location changedLocation() {
133         return actualLocationOfRoot;
134     }
135 
136     /**
137      * {@inheritDoc}
138      * 
139      * @see org.modeshape.graph.request.ChangeRequest#changedWorkspace()
140      */
141     @Override
142     public String changedWorkspace() {
143         return workspaceName;
144     }
145 
146     /**
147      * {@inheritDoc}
148      * 
149      * @see org.modeshape.graph.request.ChangeRequest#changes(java.lang.String, org.modeshape.graph.property.Path)
150      */
151     @Override
152     public boolean changes( String workspace,
153                             Path path ) {
154         return workspaceName().equals(workspace);
155     }
156 
157     /**
158      * {@inheritDoc}
159      * <p>
160      * This method does not clone the results.
161      * </p>
162      * 
163      * @see org.modeshape.graph.request.ChangeRequest#clone()
164      */
165     @Override
166     public DestroyWorkspaceRequest clone() {
167         return new DestroyWorkspaceRequest(workspaceName);
168     }
169 
170     @Override
171     public RequestType getType() {
172         return RequestType.DESTROY_WORKSPACE;
173     }
174 }