2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.core.startup.layers;
45
import java.io.IOException;
47
import java.util.List;
48
import java.util.logging.Logger;
49
import org.openide.filesystems.FileSystem;
50
import org.openide.filesystems.XMLFileSystem;
51
import org.openide.util.NotImplementedException;
53
/** Interface for a manager which can handle XML layer caching.
57
public abstract class LayerCacheManager {
59
/** Local error manager for in-package use.
61
static final Logger err = Logger.getLogger("org.netbeans.core.projects.cache"); // NOI18N
63
private final File cacheDir;
65
private static LayerCacheManager emptyManager = null;
67
* Get a cache manager which does nothing.
69
public static LayerCacheManager emptyManager() {
70
if (emptyManager == null) {
71
emptyManager = new NonCacheManager();
76
/** Create a cache manager (for subclass use).
78
protected LayerCacheManager(File cacheDir) {
79
this.cacheDir = cacheDir;
82
/** The directory to use a working area for the cache.
83
* For informational purposes only.
84
* May be null, if the manager is not really caching.
86
public final File getCacheDirectory() {
90
/** True if the cache already seems to exist in the cache dir, false if fresh.
92
public abstract boolean cacheExists();
94
/** Clean up any cache files in the cache directory.
97
public abstract void cleanupCache() throws IOException;
100
* If true, this manager supports in-place loading of a cache.
101
* If false, it can only load a cache or store it.
102
* The result affects which methods are considered effectively present and
103
* abstract on this manager.
104
* @return true by default
106
public boolean supportsLoad() {
110
/** Create an empty cache filesystem, i.e. with no initial layers.
111
* Should only be called when the cache directory is clean.
112
* Should not be overridden if the manager does not support loading;
113
* otherwise must be overridden.
115
public FileSystem createEmptyFileSystem() throws IOException {
116
if (supportsLoad()) {
117
throw new NotImplementedException();
119
return new XMLFileSystem();
123
/** Create a preloaded cache filesystem with some existing set of layers.
124
* Should only be called when the cache directory is prepared.
125
* The default implementation just creates an empty cache and then
126
* loads it, but subclasses may override to do this more efficiently.
127
* (Subclasses which do not support loading <b>must</b> override it.)
129
public FileSystem createLoadedFileSystem() throws IOException {
130
if (!supportsLoad()) throw new IOException("Does not support loading!"); // NOI18N
131
FileSystem fs = createEmptyFileSystem();
136
/** Load the cache from disk.
137
* Should only be called when the cache directory is prepared.
138
* The filesystem's contents should be modified.
139
* The filesystem must have been originally produced by
140
* {@link #createEmptyFileSystem} or {@link #createLoadedFileSystem}.
141
* Not called if the manager does not support loading;
142
* otherwise must be overridden.
144
public void load(FileSystem fs) throws IOException {
145
throw new NotImplementedException();
148
/** Save a new cache to disk.
149
* Besides modifying the disk cache files, this should also
150
* change the contents of the existing filesystem.
151
* The filesystem must have been originally produced by
152
* {@link #createEmptyFileSystem} or {@link #createLoadedFileSystem}.
153
* This might be done simply by calling {@link #load}, or there
154
* might be a more efficient way.
155
* @param urls list of type URL; earlier layers can override later layers
156
* Not called if the manager does not support loading;
157
* otherwise must be overridden.
159
public void store(FileSystem fs, List<URL> urls) throws IOException {
160
throw new NotImplementedException();
164
* Save a new cache to disk, load it, and return that filesystem.
165
* @param urls list of type URL; earlier layers can override later layers
166
* @return a new filesystem with the specified contents
167
* Not called if the manager supports loading;
168
* otherwise must be overridden.
170
public FileSystem store(List<URL> urls) throws IOException {
171
throw new NotImplementedException();