001 /* 002 * Copyright 2002-2004 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.richclient.command; 017 018 019 /** 020 * Indicates that an object is not a valid member of a {@link CommandGroup}. 021 * 022 * <p> 023 * Usually, a command group member will be a subclass of {@link AbstractCommand}, however some 024 * command group implementations may define more specific rules about what types of members they 025 * will accept. 026 * </p> 027 * 028 * @author Kevin Stembridge 029 * @since 0.3 030 * 031 */ 032 public class InvalidGroupMemberException extends CommandException { 033 034 private static final long serialVersionUID = 7891614557214887191L; 035 036 private final Class invalidMemberClass; 037 private final Class commandGroupClass; 038 039 private static String createDefaultMessage(Class invalidMemberClass, Class commandGroupClass) { 040 041 return "An object of type [" 042 + invalidMemberClass 043 + "] is not a valid member for a group of type [" 044 + commandGroupClass 045 + "]"; 046 047 } 048 049 /** 050 * Creates a new {@code InvalidGroupMemberException}. 051 * 052 * @param invalidMemberClass The class of the invalid member. 053 * @param commandGroupClass The class of the command group that the member is not valid for. 054 */ 055 public InvalidGroupMemberException(Class invalidMemberClass, Class commandGroupClass) { 056 super(createDefaultMessage(invalidMemberClass, commandGroupClass)); 057 this.invalidMemberClass = invalidMemberClass; 058 this.commandGroupClass = commandGroupClass; 059 } 060 061 /** 062 * Creates a new {@code InvalidGroupMemberException}. 063 * 064 * @param message The detail message. 065 * @param invalidMemberClass The class of the invalid member. 066 * @param commandGroupClass The class of the command group that the member is invalid for. 067 */ 068 public InvalidGroupMemberException(String message, Class invalidMemberClass, Class commandGroupClass) { 069 this(message, invalidMemberClass, commandGroupClass, null); 070 } 071 072 /** 073 * Creates a new {@code InvalidGroupMemberException}. 074 * 075 * @param message The detail message. 076 * @param invalidMemberClass The class of the invalid member. 077 * @param commandGroupClass The class of the command group that the member is invalid for. 078 * @param cause The nested exception. 079 */ 080 public InvalidGroupMemberException(String message, 081 Class invalidMemberClass, 082 Class commandGroupClass, 083 Throwable cause) { 084 085 super(message, cause); 086 this.invalidMemberClass = invalidMemberClass; 087 this.commandGroupClass = commandGroupClass; 088 089 } 090 091 /** 092 * Returns the class of the command group that the member is invalid for. 093 * @return Returns the value of the commandGroupClass field, possibly null. 094 */ 095 public Class getCommandGroupClass() { 096 return this.commandGroupClass; 097 } 098 099 /** 100 * Returns the class of the invalid member. 101 * @return Returns the value of the invalidMemberClass field, possibly null. 102 */ 103 public Class getInvalidMemberClass() { 104 return this.invalidMemberClass; 105 } 106 107 }