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 Apache.CLI; 018 019/** Thrown when more than one option in an option group has been provided. */ 020@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="LICENSE") 021public class AlreadySelectedException extends ParseException 022{ 023 // <EMBED CLASS='external-html' DATA-FILE-ID=SVUID 024 private static final long serialVersionUID = 1; 025 026 /** The option group selected. */ 027 private final OptionGroup group; 028 029 /** The option that triggered the exception. */ 030 private final Option option; 031 032 /** 033 * Constructs a new {@code AlreadySelectedException} for the specified option group. 034 * @param group the option group already selected 035 * @param option the option that triggered the exception 036 */ 037 public AlreadySelectedException(final OptionGroup group, final Option option) 038 { 039 this( 040 "The option '" + option.getKey() + "' was specified but an option from this group " + 041 "has already been selected: '" + group.getSelected() + "'", 042 group, option 043 ); 044 } 045 046 /** 047 * Constructs a new {@code AlreadySelectedException} with the specified detail message. 048 * @param message the detail message 049 */ 050 public AlreadySelectedException(final String message) 051 { this(message, null, null); } 052 053 private AlreadySelectedException 054 (final String message, final OptionGroup group, final Option option) 055 { 056 super(message); 057 058 this.group = group; 059 this.option = option; 060 } 061 062 /** 063 * Gets the option that was added to the group and triggered the exception. 064 * @return the related option 065 */ 066 public Option getOption() 067 { return option; } 068 069 /** 070 * Gets the option group where another option has been selected. 071 * @return the related option group 072 */ 073 public OptionGroup getOptionGroup() 074 { return group; } 075}