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 */
017
018 package org.apache.commons.cli;
019
020 /**
021 * Thrown when more than one option in an option group
022 * has been provided.
023 *
024 * @author John Keyes ( john at integralsource.com )
025 * @version $Revision: 680644 $, $Date: 2008-07-29 01:13:48 -0700 (Tue, 29 Jul 2008) $
026 */
027 public class AlreadySelectedException extends ParseException
028 {
029 /** The option group selected. */
030 private OptionGroup group;
031
032 /** The option that triggered the exception. */
033 private Option option;
034
035 /**
036 * Construct a new <code>AlreadySelectedException</code>
037 * with the specified detail message.
038 *
039 * @param message the detail message
040 */
041 public AlreadySelectedException(String message)
042 {
043 super(message);
044 }
045
046 /**
047 * Construct a new <code>AlreadySelectedException</code>
048 * for the specified option group.
049 *
050 * @param group the option group already selected
051 * @param option the option that triggered the exception
052 * @since 1.2
053 */
054 public AlreadySelectedException(OptionGroup group, Option option)
055 {
056 this("The option '" + option.getKey() + "' was specified but an option from this group "
057 + "has already been selected: '" + group.getSelected() + "'");
058 this.group = group;
059 this.option = option;
060 }
061
062 /**
063 * Returns the option group where another option has been selected.
064 *
065 * @return the related option group
066 * @since 1.2
067 */
068 public OptionGroup getOptionGroup()
069 {
070 return group;
071 }
072
073 /**
074 * Returns the option that was added to the group and triggered the exception.
075 *
076 * @return the related option
077 * @since 1.2
078 */
079 public Option getOption()
080 {
081 return option;
082 }
083 }