001    /**
002     * Copyright (c) 2000-2013 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.license.util;
016    
017    import com.liferay.portal.kernel.json.JSONObject;
018    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    import com.liferay.portal.license.LicenseInfo;
020    
021    import java.util.List;
022    import java.util.Map;
023    import java.util.Set;
024    
025    /**
026     * @author Amos Fong
027     */
028    public class LicenseManagerUtil {
029    
030            public static final int STATE_ABSENT = 1;
031    
032            public static final int STATE_EXPIRED = 2;
033    
034            public static final int STATE_GOOD = 3;
035    
036            public static final int STATE_INACTIVE = 4;
037    
038            public static final int STATE_INVALID = 5;
039    
040            public static final int STATE_OVERLOAD = 6;
041    
042            public static void checkLicense(String productId) {
043                    getLicenseManager().checkLicense(productId);
044            }
045    
046            public static List<Map<String, String>> getClusterLicenseProperties(
047                    String clusterNodeId) {
048    
049                    return getLicenseManager().getClusterLicenseProperties(clusterNodeId);
050            }
051    
052            public static String getHostName() {
053                    return getLicenseManager().getHostName();
054            }
055    
056            public static Set<String> getIpAddresses() {
057                    return getLicenseManager().getIpAddresses();
058            }
059    
060            public static LicenseInfo getLicenseInfo(String productId) {
061                    return getLicenseManager().getLicenseInfo(productId);
062            }
063    
064            public static LicenseManager getLicenseManager() {
065                    PortalRuntimePermission.checkGetBeanProperty(LicenseManagerUtil.class);
066    
067                    return _licenseManager;
068            }
069    
070            public static List<Map<String, String>> getLicenseProperties() {
071                    return getLicenseManager().getLicenseProperties();
072            }
073    
074            public static Map<String, String> getLicenseProperties(String productId) {
075                    return getLicenseManager().getLicenseProperties(productId);
076            }
077    
078            public static int getLicenseState(Map<String, String> licenseProperties) {
079                    return getLicenseManager().getLicenseState(licenseProperties);
080            }
081    
082            public static int getLicenseState(String productId) {
083                    return getLicenseManager().getLicenseState(productId);
084            }
085    
086            public static Set<String> getMacAddresses() {
087                    return getLicenseManager().getMacAddresses();
088            }
089    
090            public static void registerLicense(JSONObject jsonObject) throws Exception {
091                    getLicenseManager().registerLicense(jsonObject);
092            }
093    
094            public void setLicenseManager(LicenseManager licenseManager) {
095                    PortalRuntimePermission.checkSetBeanProperty(getClass());
096    
097                    _licenseManager = licenseManager;
098            }
099    
100            private static LicenseManager _licenseManager;
101    
102    }