001    /**
002     * Copyright (c) 2000-present 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.module.framework;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.util.ClassLoaderUtil;
019    
020    import java.io.InputStream;
021    
022    /**
023     * This class is a simple wrapper in order to make the framework module running
024     * under its own class loader.
025     *
026     * @author Miguel Pastor
027     * @author Raymond Aug??
028     * @see    ModuleFrameworkClassLoader
029     */
030    public class ModuleFrameworkUtilAdapter {
031    
032            public static long addBundle(String location) throws PortalException {
033                    return _moduleFramework.addBundle(location);
034            }
035    
036            public static long addBundle(String location, InputStream inputStream)
037                    throws PortalException {
038    
039                    return _moduleFramework.addBundle(location, inputStream);
040            }
041    
042            public static Object getFramework() {
043                    return _moduleFramework.getFramework();
044            }
045    
046            public static String getState(long bundleId) throws PortalException {
047                    return _moduleFramework.getState(bundleId);
048            }
049    
050            public static void initFramework() throws Exception {
051                    ClassLoader classLoader = ClassLoaderUtil.getContextClassLoader();
052    
053                    ClassLoaderUtil.setContextClassLoader(
054                            ModuleFrameworkAdapterHelper.getClassLoader());
055    
056                    try {
057                            _moduleFramework.initFramework();
058                    }
059                    finally {
060                            ClassLoaderUtil.setContextClassLoader(classLoader);
061                    }
062            }
063    
064            public static void registerContext(Object context) {
065                    _moduleFramework.registerContext(context);
066            }
067    
068            public static void setBundleStartLevel(long bundleId, int startLevel)
069                    throws PortalException {
070    
071                    _moduleFramework.setBundleStartLevel(bundleId, startLevel);
072            }
073    
074            public static void setModuleFramework(ModuleFramework moduleFramework) {
075                    _moduleFramework = moduleFramework;
076    
077                    _moduleFrameworkAdapterHelper.exec(
078                            "setModuleFramework", new Class[] {ModuleFramework.class},
079                            _moduleFramework);
080            }
081    
082            public static void startBundle(long bundleId) throws PortalException {
083                    _moduleFramework.startBundle(bundleId);
084            }
085    
086            public static void startBundle(long bundleId, int options)
087                    throws PortalException {
088    
089                    _moduleFramework.startBundle(bundleId, options);
090            }
091    
092            public static void startFramework() throws Exception {
093                    _moduleFramework.startFramework();
094            }
095    
096            public static void startRuntime() throws Exception {
097                    _moduleFramework.startRuntime();
098            }
099    
100            public static void stopBundle(long bundleId) throws PortalException {
101                    _moduleFramework.stopBundle(bundleId);
102            }
103    
104            public static void stopBundle(long bundleId, int options)
105                    throws PortalException {
106    
107                    _moduleFramework.stopBundle(bundleId, options);
108            }
109    
110            public static void stopFramework(long timeout) throws Exception {
111                    _moduleFramework.stopFramework(timeout);
112            }
113    
114            public static void stopRuntime() throws Exception {
115                    _moduleFramework.stopRuntime();
116            }
117    
118            public static void uninstallBundle(long bundleId) throws PortalException {
119                    _moduleFramework.uninstallBundle(bundleId);
120            }
121    
122            public static void updateBundle(long bundleId) throws PortalException {
123                    _moduleFramework.updateBundle(bundleId);
124            }
125    
126            public static void updateBundle(long bundleId, InputStream inputStream)
127                    throws PortalException {
128    
129                    _moduleFramework.updateBundle(bundleId, inputStream);
130            }
131    
132            private static ModuleFramework _moduleFramework;
133            private static final ModuleFrameworkAdapterHelper
134                    _moduleFrameworkAdapterHelper = new ModuleFrameworkAdapterHelper(
135                            "com.liferay.portal.bootstrap.ModuleFrameworkUtil");
136    
137            static {
138                    _moduleFramework =
139                            (ModuleFramework)_moduleFrameworkAdapterHelper.execute(
140                                    "getModuleFramework");
141            }
142    
143    }