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-2006 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.spring.api.beans;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.util.List;
047: import javax.swing.event.ChangeListener;
048: import org.netbeans.modules.spring.beans.ConfigFileManagerAccessor;
049: import org.netbeans.modules.spring.beans.ConfigFileManagerImplementation;
050: import org.openide.util.Mutex;
051: import org.openide.util.Parameters;
052:
053: /**
054: * Manages all config file groups in a {@link SpringScope Spring scope}.
055: *
056: * @author Andrei Badea
057: */
058: public final class ConfigFileManager {
059:
060: private final ConfigFileManagerImplementation impl;
061:
062: static {
063: ConfigFileManagerAccessor.DEFAULT = new ConfigFileManagerAccessor() {
064: @Override
065: public ConfigFileManager createConfigFileManager(
066: ConfigFileManagerImplementation impl) {
067: return new ConfigFileManager(impl);
068: }
069: };
070: }
071:
072: private ConfigFileManager(ConfigFileManagerImplementation impl) {
073: this .impl = impl;
074: }
075:
076: /**
077: * Returns the mutex which protectes the access to this ConfigFileManager.
078: *
079: * @return the mutex; never null.
080: */
081: public Mutex mutex() {
082: return impl.mutex();
083: }
084:
085: /**
086: * Returns the list of config files in this manager. The list is
087: * modifiable and not live, therefore changes to the list do not
088: * modify the contents of the manager.
089: *
090: * @return the list; never null.
091: */
092: public List<File> getConfigFiles() {
093: return impl.getConfigFiles();
094: }
095:
096: /**
097: * Returns the list of config file groups in this manger. The list is
098: * modifiable and not live, therefore changes to the list do not
099: * modify the contents of the manager.
100: *
101: * @return the list; never null.
102: */
103: public List<ConfigFileGroup> getConfigFileGroups() {
104: return impl.getConfigFileGroups();
105: }
106:
107: /**
108: * Modifies the list of config file groups. This method needs to be called
109: * under {@code mutex()} write access.
110: *
111: * @param files the files to add; never null.
112: * @param groups the groups to add; never null.
113: * @throws IllegalStateException if the called does not hold {@code mutex()}
114: * write access.
115: */
116: public void putConfigFilesAndGroups(List<File> files,
117: List<ConfigFileGroup> groups) {
118: Parameters.notNull("files", files);
119: Parameters.notNull("groups", groups);
120: if (!mutex().isWriteAccess()) {
121: throw new IllegalStateException(
122: "The putConfigFilesAndGroups() method should be called under mutex() write access");
123: }
124: impl.putConfigFilesAndGroups(files, groups);
125: }
126:
127: /**
128: * Saves the list of config file groups, for example to a persistent storage.
129: * This method needs to be called under {@code mutex()} write access.
130: *
131: * @throws IOException if an error occured.
132: */
133: public void save() throws IOException {
134: if (!mutex().isWriteAccess()) {
135: throw new IllegalStateException(
136: "The save() method should be called under mutex() write access");
137: }
138: impl.save();
139: }
140:
141: /**
142: * Adds a change listener which will be notified of changes to the
143: * list of config file groups.
144: *
145: * @param listener a listener.
146: */
147: void addChangeListener(ChangeListener listener) {
148: impl.addChangeListener(listener);
149: }
150: }
|