001 /* 002 * JBoss, Home of Professional Open Source. 003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors 004 * as indicated by the @author tags. See the copyright.txt file in the 005 * distribution for a full listing of individual contributors. 006 * 007 * This is free software; you can redistribute it and/or modify it 008 * under the terms of the GNU Lesser General Public License as 009 * published by the Free Software Foundation; either version 2.1 of 010 * the License, or (at your option) any later version. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022 package org.jboss.dna.graph.requests; 023 024 import org.jboss.dna.common.util.CheckArg; 025 import org.jboss.dna.graph.GraphI18n; 026 import org.jboss.dna.graph.Location; 027 028 /** 029 * Instruction that a branch be deleted. 030 * 031 * @author Randall Hauch 032 */ 033 public class DeleteBranchRequest extends Request { 034 035 private static final long serialVersionUID = 1L; 036 037 private final Location at; 038 private Location actualLocation; 039 040 /** 041 * Create a request to delete a branch. 042 * 043 * @param at the location of the top node in the existing branch that is to be deleted 044 * @throws IllegalArgumentException if the location is null 045 */ 046 public DeleteBranchRequest( Location at ) { 047 CheckArg.isNotNull(at, "at"); 048 this.at = at; 049 } 050 051 /** 052 * Get the location defining the top of the branch to be deleted 053 * 054 * @return the location of the branch; never null 055 */ 056 public Location at() { 057 return at; 058 } 059 060 /** 061 * {@inheritDoc} 062 * 063 * @see org.jboss.dna.graph.requests.Request#isReadOnly() 064 */ 065 @Override 066 public boolean isReadOnly() { 067 return false; 068 } 069 070 /** 071 * Sets the actual and complete location of the node being deleted. This method must be called when processing the request, 072 * and the actual location must have a {@link Location#getPath() path}. 073 * 074 * @param actual the actual location of the node being deleted, or null if the {@link #at() current location} should be used 075 * @throws IllegalArgumentException if the actual location does not represent the {@link Location#isSame(Location) same 076 * location} as the {@link #at() current location}, or if the actual location does not have a path. 077 */ 078 public void setActualLocationOfNode( Location actual ) { 079 if (!at.isSame(actual)) { // not same if actual is null 080 throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, at)); 081 } 082 assert actual != null; 083 if (!actual.hasPath()) { 084 throw new IllegalArgumentException(GraphI18n.actualLocationMustHavePath.text(actual)); 085 } 086 this.actualLocation = actual; 087 } 088 089 /** 090 * Get the actual location of the node that was deleted. 091 * 092 * @return the actual location, or null if the actual location was not set 093 */ 094 public Location getActualLocationOfNode() { 095 return actualLocation; 096 } 097 098 /** 099 * {@inheritDoc} 100 * 101 * @see java.lang.Object#equals(java.lang.Object) 102 */ 103 @Override 104 public boolean equals( Object obj ) { 105 if (this.getClass().isInstance(obj)) { 106 DeleteBranchRequest that = (DeleteBranchRequest)obj; 107 if (!this.at().equals(that.at())) return false; 108 return true; 109 } 110 return false; 111 } 112 113 /** 114 * {@inheritDoc} 115 * 116 * @see java.lang.Object#toString() 117 */ 118 @Override 119 public String toString() { 120 return "delete branch " + at(); 121 } 122 }