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    
029    /**
030     * Verify that a workspace exists with the supplied name. This is useful to determine the name of the "default" workspace for a
031     * source.
032     */
033    public final class VerifyWorkspaceRequest extends Request {
034    
035        private static final long serialVersionUID = 1L;
036    
037        private final String workspaceName;
038        private Location actualLocationOfRoot;
039        private String actualWorkspaceName;
040    
041        /**
042         * Create a request to verify the existance of the named workspace.
043         * 
044         * @param workspaceName the desired name of the workspace, or null if the source's default workspace should be used
045         */
046        public VerifyWorkspaceRequest( String workspaceName ) {
047            this.workspaceName = workspaceName;
048        }
049    
050        /**
051         * Get the desired name for the workspace.
052         * 
053         * @return the desired name for the workspace, or null if the source's default workspace is to be verified
054         */
055        public String workspaceName() {
056            return workspaceName;
057        }
058    
059        /**
060         * Get the actual name of the workspace.
061         * 
062         * @return the actual name of the workspace, or null if a workspace was not verified (yet)
063         */
064        public String getActualWorkspaceName() {
065            return actualWorkspaceName;
066        }
067    
068        /**
069         * Set the actual name of the workspace.
070         * 
071         * @param actualWorkspaceName the actual name of the workspace; never null
072         * @throws IllegalStateException if the request is frozen
073         */
074        public void setActualWorkspaceName( String actualWorkspaceName ) {
075            checkNotFrozen();
076            CheckArg.isNotNull(actualWorkspaceName, "actualWorkspaceName");
077            this.actualWorkspaceName = actualWorkspaceName;
078        }
079    
080        /**
081         * Get the actual location of the root node in the new workspace, or null if the workspace was not (yet) created.
082         * 
083         * @return the actual location of the root node in the new workspace, or null if the workspace was not (yet) created
084         */
085        public Location getActualLocationOfRoot() {
086            return actualLocationOfRoot;
087        }
088    
089        /**
090         * Set the actual location of the root node in the new workspace.
091         * 
092         * @param actualLocationOfRoot the actual location of the workspace's root node.
093         * @throws IllegalStateException if the request is frozen
094         */
095        public void setActualRootLocation( Location actualLocationOfRoot ) {
096            checkNotFrozen();
097            this.actualLocationOfRoot = actualLocationOfRoot;
098        }
099    
100        /**
101         * {@inheritDoc}
102         * 
103         * @see org.jboss.dna.graph.request.Request#isReadOnly()
104         */
105        @Override
106        public boolean isReadOnly() {
107            return false;
108        }
109    
110        /**
111         * {@inheritDoc}
112         * 
113         * @see org.jboss.dna.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    }