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