fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * The contents of this file are subject to the terms
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * of the Common Development and Distribution License
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * (the License). You may not use this file except in
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * compliance with the License.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * You can obtain a copy of the License at
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * https://opensso.dev.java.net/public/CDDLv1.0.html or
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * See the License for the specific language governing
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * permission and limitations under the License.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * When distributing Covered Code, include this CDDL
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * Header Notice in each file and include the License file
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * If applicable, add the following below the CDDL Header,
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * with the fields enclosed by brackets [] replaced by
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * your own identifying information:
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * "Portions Copyrighted [year] [name of copyright owner]"
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * $Id: UserResponseInteraction.java,v 1.2 2008/06/25 05:51:25 qcheng Exp $
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Majorpackage com.sun.identity.install.tools.configurator;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Majorimport com.sun.identity.install.tools.util.Console;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Majorimport com.sun.identity.install.tools.util.LocalizedMessage;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Majorabstract public class UserResponseInteraction extends BaseInteraction {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * Method that needs to be implemented by the sub-classes to intialize the
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * result status Map. The map should be constructed with key = display item
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * of a UserOption with value of InteractionResultStatus object that
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * corresponds to that UserOption.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * @return a Map constructed with <UserOption' display Item,
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * InteractionResultStatus>.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major abstract LocalizedMessage getDisplayMessagesHeader();
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major abstract LocalizedMessage getUserOptionsHeader();
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public InteractionResultStatus interact(IStateAccess state)
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Display the interaction messages
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Now display available options
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Display the prompt
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Now read user inpu
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major UserOptionItem defaultOption = getUserOptions(state)
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major if (userInput != null && userInput.trim().length() > 0) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major selectedOption = getUserOptions(state).getSelectedOption(
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major } else if (defaultOption != null) { // Choose default if present
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // At this point if the selectedOption is still null, print an
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // invalid option message
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major } else { // Display confirmation if status is Abort or Exit
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major String displayItem = selectedOption.getDisplayItem();
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major status = (InteractionResultStatus) getResultStatusMap().get(
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Display the header if present
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Display header only if there are messages to display
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major protected InteractionResultStatus confirmOnExitStatus(
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major InteractionResultStatus status, IStateAccess state)
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major if (status.getIntValue() == InteractionResultStatus.INT_STATUS_ABORT) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Confirm Once again!!
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major ConfirmInteraction confirm = new ConfirmInteraction();
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major InteractionResultStatus newStatus = confirm.interact(state);
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Set it to null, so the we can continue the caller's loop.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public String getPromptValue(IStateAccess state) throws InstallException {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major if (getUserOptions(state).getDefaultOption() != null) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major promptValue = getUserOptions(state).getDefaultOption()
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private LocalizedMessage getInvalidOptionMessage() {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private static final String LOC_IN_ERR_INVALID_OPTION =
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major "IN_ERR_INVALID_OPTION";
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private LocalizedMessage invalidOptionMessage = LocalizedMessage
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private static final String STR_DISPLAY_HEADER_MARKER =
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major "-----------------------------------------------";