|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.api.convertor; import java.io.File; import org.netbeans.core.NbTopManager; import org.netbeans.core.modules.*; import org.openide.util.Mutex; import org.openide.util.MutexException; /** * * @author Jesse Glick, David Konecny */ public class ModuleUtils { public static ModuleUtils DEFAULT = new ModuleUtils(); private ModuleManager mgr; private Module bookConvertorModule; private Module dvdConvertorModule; private Module shoppingCartConvertorModule; private Module storeConvertorModule; private ModuleUtils() { mgr = NbTopManager.get().getModuleSystem().getManager(); } public void install() throws Exception { try { mgr.mutex().writeAccess(new Mutex.ExceptionAction() { public Object run() throws Exception { File jar1 = new File(ModuleUtils.class.getResource("data/bookconvertor.jar").getPath()); bookConvertorModule = mgr.create(jar1, new ModuleHistory(), false, false, false); File jar2 = new File(ModuleUtils.class.getResource("data/dvdconvertor.jar").getPath()); dvdConvertorModule = mgr.create(jar2, new ModuleHistory(), false, false, false); File jar3 = new File(ModuleUtils.class.getResource("data/shoppingcartconvertor.jar").getPath()); shoppingCartConvertorModule = mgr.create(jar3, new ModuleHistory(), false, false, false); File jar4 = new File(ModuleUtils.class.getResource("data/storeconvertor.jar").getPath()); storeConvertorModule = mgr.create(jar4, new ModuleHistory(), false, false, false); return null; } }); } catch (MutexException me) { throw me.getException(); } } protected void uninstall() throws Exception { try { mgr.mutex().writeAccess(new Mutex.ExceptionAction() { public Object run() throws Exception { if (bookConvertorModule.isEnabled()) mgr.disable(bookConvertorModule); mgr.delete(bookConvertorModule); if (dvdConvertorModule.isEnabled()) mgr.disable(dvdConvertorModule); mgr.delete(dvdConvertorModule); if (shoppingCartConvertorModule.isEnabled()) mgr.disable(shoppingCartConvertorModule); mgr.delete(shoppingCartConvertorModule); if (storeConvertorModule.isEnabled()) mgr.disable(storeConvertorModule); mgr.delete(storeConvertorModule); return null; } }); } catch (MutexException me) { throw me.getException(); } bookConvertorModule = null; dvdConvertorModule = null; shoppingCartConvertorModule = null; storeConvertorModule = null; mgr = null; } protected static final int TWIDDLE_ENABLE = 0; protected static final int TWIDDLE_DISABLE = 1; private void twiddle(final Module m, final int action) throws Exception { try { mgr.mutex().writeAccess(new Mutex.ExceptionAction() { public Object run() throws Exception { switch (action) { case TWIDDLE_ENABLE: mgr.enable(m); break; case TWIDDLE_DISABLE: mgr.disable(m); break; default: throw new IllegalArgumentException("bad action: " + action); } return null; } }); } catch (MutexException me) { throw me.getException(); } } public void enableBookModule(boolean enable) throws Exception { twiddle(bookConvertorModule, enable ? TWIDDLE_ENABLE : TWIDDLE_DISABLE); } public void enableDVDConvertorModule(boolean enable) throws Exception { twiddle(dvdConvertorModule, enable ? TWIDDLE_ENABLE : TWIDDLE_DISABLE); } public void enableShoppingCartConvertorModule(boolean enable) throws Exception { twiddle(shoppingCartConvertorModule, enable ? TWIDDLE_ENABLE : TWIDDLE_DISABLE); } public void enableStoreConvertorModule(boolean enable) throws Exception { twiddle(storeConvertorModule, enable ? TWIDDLE_ENABLE : TWIDDLE_DISABLE); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.