001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.lar;
016    
017    /**
018     * @author Raymond Augé
019     */
020    public class PortletDataHandlerChoice extends PortletDataHandlerControl {
021    
022            public PortletDataHandlerChoice(String namespace, String controlName) {
023                    this(namespace, controlName, 0, _DEFAULT_CHOICES);
024            }
025    
026            public PortletDataHandlerChoice(
027                    String namespace, String controlName, int defaultChoice) {
028    
029                    this(namespace, controlName, defaultChoice, _DEFAULT_CHOICES);
030            }
031    
032            public PortletDataHandlerChoice(
033                    String namespace, String controlName, int defaultChoice,
034                    String[] choices) {
035    
036                    super(namespace, controlName);
037    
038                    _choices = choices;
039                    _defaultChoice = defaultChoice;
040            }
041    
042            public String[] getChoices() {
043                    if ((_choices == null) || (_choices.length < 1)) {
044                            return _DEFAULT_CHOICES;
045                    }
046                    else {
047                            return _choices;
048                    }
049            }
050    
051            public String getDefaultChoice() {
052                    return getChoices()[getDefaultChoiceIndex()];
053            }
054    
055            public int getDefaultChoiceIndex() {
056                    if ((_defaultChoice < 0) || (_defaultChoice >= _choices.length)) {
057                            return 0;
058                    }
059                    else {
060                            return _defaultChoice;
061                    }
062            }
063    
064            private static final String[] _DEFAULT_CHOICES = new String[] {
065                    "false", "true"
066            };
067    
068            private String[] _choices;
069            private int _defaultChoice;
070    
071    }