001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.bi.reporting;
016    
017    import java.util.HashMap;
018    import java.util.Map;
019    
020    /**
021     * @author Gavin Wan
022     */
023    public enum ReportDataSourceType {
024    
025            CSV("csv"), EMPTY("empty"), JDBC("jdbc"), PORTAL("portal"), XLS("xls"),
026            XML("xml");
027    
028            public static ReportDataSourceType parse(String value) {
029                    ReportDataSourceType reportDataSourceType = _reportDataSourceTypes.get(
030                            value);
031    
032                    if (reportDataSourceType != null) {
033                            return reportDataSourceType;
034                    }
035    
036                    if (CSV.toString().equalsIgnoreCase(value)) {
037                            return CSV;
038                    }
039                    else if (EMPTY.toString().equalsIgnoreCase(value)) {
040                            return EMPTY;
041                    }
042                    else if (JDBC.toString().equalsIgnoreCase(value)) {
043                            return JDBC;
044                    }
045                    else if (PORTAL.toString().equalsIgnoreCase(value)) {
046                            return PORTAL;
047                    }
048                    else if (XLS.toString().equalsIgnoreCase(value)) {
049                            return XLS;
050                    }
051                    else if (XML.toString().equalsIgnoreCase(value)) {
052                            return XML;
053                    }
054                    else {
055                            throw new IllegalArgumentException(
056                                    "Invalid data source type " + value);
057                    }
058            }
059    
060            public String toString() {
061                    return _value;
062            }
063    
064            private ReportDataSourceType(String value) {
065                    _value = value;
066            }
067    
068            private static final Map<String, ReportDataSourceType>
069                    _reportDataSourceTypes = new HashMap<String, ReportDataSourceType>();
070    
071            static {
072                    _reportDataSourceTypes.put(CSV.toString(), CSV);
073                    _reportDataSourceTypes.put(EMPTY.toString(), EMPTY);
074                    _reportDataSourceTypes.put(JDBC.toString(), JDBC);
075                    _reportDataSourceTypes.put(PORTAL.toString(), PORTAL);
076                    _reportDataSourceTypes.put(XLS.toString(), XLS);
077                    _reportDataSourceTypes.put(XML.toString(), XML);
078            }
079    
080            private String _value;
081    
082    }