001    /*
002     * JBoss DNA (http://www.jboss.org/dna)
003     * See the COPYRIGHT.txt file distributed with this work for information
004     * regarding copyright ownership.  Some portions may be licensed
005     * to Red Hat, Inc. under one or more contributor license agreements.
006     * See the AUTHORS.txt file in the distribution for a full listing of 
007     * individual contributors.
008     *
009     * Unless otherwise indicated, all code in JBoss DNA is licensed
010     * to you under the terms of the GNU Lesser General Public License as
011     * published by the Free Software Foundation; either version 2.1 of
012     * the License, or (at your option) any later version.
013     * 
014     * JBoss DNA is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     * Lesser General Public License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this software; if not, write to the Free
021     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023     */
024    package org.jboss.dna.graph.request;
025    
026    import org.jboss.dna.common.util.CheckArg;
027    import org.jboss.dna.graph.Location;
028    import org.jboss.dna.graph.property.Path;
029    
030    /**
031     * Request that an existing workspace with the supplied name be destroyed.
032     */
033    public final class DestroyWorkspaceRequest extends ChangeRequest {
034    
035        private static final long serialVersionUID = 1L;
036    
037        private final String workspaceName;
038        private Location actualLocationOfRoot;
039    
040        /**
041         * Create a request to destroy an existing workspace.
042         * 
043         * @param workspaceName the name of the workspace that is to be destroyed
044         * @throws IllegalArgumentException if the workspace name is null
045         */
046        public DestroyWorkspaceRequest( String workspaceName ) {
047            CheckArg.isNotNull(workspaceName, "workspaceName");
048            this.workspaceName = workspaceName;
049        }
050    
051        /**
052         * Get the name for the workspace that is to be destroyed.
053         * 
054         * @return the name for the workspace; never null
055         */
056        public String workspaceName() {
057            return workspaceName;
058        }
059    
060        /**
061         * Get the actual location of the root node in the new workspace, or null if the workspace was not (yet) created.
062         * 
063         * @return the actual location of the root node in the new workspace, or null if the workspace was not (yet) created
064         */
065        public Location getActualLocationOfRoot() {
066            return actualLocationOfRoot;
067        }
068    
069        /**
070         * Set the actual location of the root node in the new workspace.
071         * 
072         * @param actualLocationOfRoot the actual location of the workspace's root node.
073         * @throws IllegalStateException if the request is frozen
074         */
075        public void setActualRootLocation( Location actualLocationOfRoot ) {
076            checkNotFrozen();
077            this.actualLocationOfRoot = actualLocationOfRoot;
078        }
079    
080        /**
081         * {@inheritDoc}
082         * 
083         * @see org.jboss.dna.graph.request.Request#isReadOnly()
084         */
085        @Override
086        public boolean isReadOnly() {
087            return false;
088        }
089    
090        /**
091         * {@inheritDoc}
092         * 
093         * @see java.lang.Object#hashCode()
094         */
095        @Override
096        public int hashCode() {
097            return workspaceName.hashCode();
098        }
099    
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.jboss.dna.graph.request.ChangeRequest#changedLocation()
130         */
131        @Override
132        public Location changedLocation() {
133            return actualLocationOfRoot;
134        }
135    
136        /**
137         * {@inheritDoc}
138         * 
139         * @see org.jboss.dna.graph.request.ChangeRequest#changedWorkspace()
140         */
141        @Override
142        public String changedWorkspace() {
143            return workspaceName;
144        }
145    
146        /**
147         * {@inheritDoc}
148         * 
149         * @see org.jboss.dna.graph.request.ChangeRequest#changes(java.lang.String, org.jboss.dna.graph.property.Path)
150         */
151        @Override
152        public boolean changes( String workspace,
153                                Path path ) {
154            return workspaceName().equals(workspace);
155        }
156    }