001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.chain.generic; 018 019import org.apache.commons.chain.Command; 020import org.apache.commons.chain.Context; 021 022/** 023 * Remove any context attribute stored under the {@code fromKey}. 024 * 025 * @param <C> Type of the context associated with this command 026 * 027 * @author Craig R. McClanahan 028 * @version $Revision$ $Date$ 029 */ 030public class RemoveCommand<C extends Context> implements Command<C> { 031 032 // -------------------------------------------------------------- Properties 033 034 private String fromKey = null; 035 036 /** 037 * Return the context attribute key for the attribute. 038 * 039 * @return The context attribute key. 040 */ 041 public String getFromKey() { 042 return this.fromKey; 043 } 044 045 /** 046 * Set the context attribute key for the attribute. 047 * 048 * @param fromKey The new key 049 */ 050 public void setFromKey(String fromKey) { 051 this.fromKey = fromKey; 052 } 053 054 // ------------------------------------------------------------ Constructors 055 056 /** 057 * The Default-Constructor for this class. 058 */ 059 public RemoveCommand() { 060 } 061 062 // ---------------------------------------------------------- Filter Methods 063 064 /** 065 * Copy the specified source attribute to the specified destination 066 * attribute. 067 * 068 * @param context {@link Context} in which we are operating 069 * 070 * @return {@code false} so that processing will continue 071 * 072 * @throws Exception if and error occurs. 073 */ 074 @Override 075 public boolean execute(C context) throws Exception { 076 context.remove(getFromKey()); 077 return false; 078 } 079}