001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.autoupdate.ui;
043:
044: import java.lang.ref.Reference;
045: import java.lang.ref.WeakReference;
046: import org.netbeans.api.autoupdate.InstallSupport;
047: import org.netbeans.api.autoupdate.OperationContainer;
048: import org.netbeans.api.autoupdate.OperationSupport;
049:
050: /**
051: *
052: * @author Radek Matous
053: */
054: public class Containers {
055: private static Reference<OperationContainer<InstallSupport>> INSTALL;
056: private static Reference<OperationContainer<InstallSupport>> UPDATE;
057: private static Reference<OperationContainer<InstallSupport>> INSTALL_FOR_NBMS;
058: private static Reference<OperationContainer<InstallSupport>> UPDATE_FOR_NBMS;
059: private static Reference<OperationContainer<OperationSupport>> UNINSTALL;
060: private static Reference<OperationContainer<OperationSupport>> ENABLE;
061: private static Reference<OperationContainer<OperationSupport>> DISABLE;
062: private static Reference<OperationContainer<OperationSupport>> CUSTOM_INSTALL;
063: private static Reference<OperationContainer<OperationSupport>> CUSTOM_UNINSTALL;
064:
065: private Containers() {
066: }
067:
068: public static void initNotify() {
069: forAvailableNbms().removeAll();
070: forUpdateNbms().removeAll();
071: forAvailable().removeAll();
072: forUninstall().removeAll();
073: forUpdate().removeAll();
074: forEnable().removeAll();
075: forDisable().removeAll();
076: }
077:
078: public static OperationContainer<InstallSupport> forAvailableNbms() {
079: synchronized (Containers.class) {
080: if (INSTALL_FOR_NBMS == null
081: || INSTALL_FOR_NBMS.get() == null) {
082: INSTALL_FOR_NBMS = new WeakReference<OperationContainer<InstallSupport>>(
083: OperationContainer.createForInstall());
084: }
085: return INSTALL_FOR_NBMS.get();
086: }
087: }
088:
089: public static OperationContainer<InstallSupport> forUpdateNbms() {
090: synchronized (Containers.class) {
091: if (UPDATE_FOR_NBMS == null
092: || UPDATE_FOR_NBMS.get() == null) {
093: UPDATE_FOR_NBMS = new WeakReference<OperationContainer<InstallSupport>>(
094: OperationContainer.createForUpdate());
095: }
096: return UPDATE_FOR_NBMS.get();
097: }
098: }
099:
100: public static OperationContainer<InstallSupport> forAvailable() {
101: synchronized (Containers.class) {
102: if (INSTALL == null || INSTALL.get() == null) {
103: INSTALL = new WeakReference<OperationContainer<InstallSupport>>(
104: OperationContainer.createForInstall());
105: }
106: return INSTALL.get();
107: }
108: }
109:
110: public static OperationContainer<InstallSupport> forUpdate() {
111: synchronized (Containers.class) {
112: if (UPDATE == null || UPDATE.get() == null) {
113: UPDATE = new WeakReference<OperationContainer<InstallSupport>>(
114: OperationContainer.createForUpdate());
115: }
116: return UPDATE.get();
117: }
118: }
119:
120: public static OperationContainer<OperationSupport> forUninstall() {
121: synchronized (Containers.class) {
122: if (UNINSTALL == null || UNINSTALL.get() == null) {
123: UNINSTALL = new WeakReference<OperationContainer<OperationSupport>>(
124: OperationContainer.createForUninstall());
125: }
126: return UNINSTALL.get();
127: }
128: }
129:
130: public static OperationContainer<OperationSupport> forEnable() {
131: synchronized (Containers.class) {
132: if (ENABLE == null || ENABLE.get() == null) {
133: ENABLE = new WeakReference<OperationContainer<OperationSupport>>(
134: OperationContainer.createForEnable());
135: }
136: return ENABLE.get();
137: }
138: }
139:
140: public static OperationContainer<OperationSupport> forDisable() {
141: synchronized (Containers.class) {
142: if (DISABLE == null || DISABLE.get() == null) {
143: DISABLE = new WeakReference<OperationContainer<OperationSupport>>(
144: OperationContainer.createForDisable());
145: }
146: return DISABLE.get();
147: }
148: }
149:
150: public static OperationContainer<OperationSupport> forCustomInstall() {
151: synchronized (Containers.class) {
152: if (CUSTOM_INSTALL == null || CUSTOM_INSTALL.get() == null) {
153: CUSTOM_INSTALL = new WeakReference<OperationContainer<OperationSupport>>(
154: OperationContainer
155: .createForCustomInstallComponent());
156: }
157: return CUSTOM_INSTALL.get();
158: }
159: }
160:
161: public static OperationContainer<OperationSupport> forCustomUninstall() {
162: synchronized (Containers.class) {
163: if (CUSTOM_UNINSTALL == null
164: || CUSTOM_UNINSTALL.get() == null) {
165: CUSTOM_UNINSTALL = new WeakReference<OperationContainer<OperationSupport>>(
166: OperationContainer
167: .createForCustomUninstallComponent());
168: }
169: return CUSTOM_UNINSTALL.get();
170: }
171: }
172: }
|