~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to core/startup/src/org/netbeans/core/startup/layers/LayerCacheManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
 
 
42
package org.netbeans.core.startup.layers;
 
43
 
 
44
import java.io.File;
 
45
import java.io.IOException;
 
46
import java.net.URL;
 
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;
 
52
 
 
53
/** Interface for a manager which can handle XML layer caching.
 
54
 * @see "#20168"
 
55
 * @author Jesse Glick
 
56
 */
 
57
public abstract class LayerCacheManager {
 
58
 
 
59
    /** Local error manager for in-package use.
 
60
     */
 
61
    static final Logger err = Logger.getLogger("org.netbeans.core.projects.cache"); // NOI18N
 
62
    
 
63
    private final File cacheDir;
 
64
    
 
65
    private static LayerCacheManager emptyManager = null;
 
66
    /**
 
67
     * Get a cache manager which does nothing.
 
68
     */
 
69
    public static LayerCacheManager emptyManager() {
 
70
        if (emptyManager == null) {
 
71
            emptyManager = new NonCacheManager();
 
72
        }
 
73
        return emptyManager;
 
74
    }
 
75
    
 
76
    /** Create a cache manager (for subclass use).
 
77
     */
 
78
    protected LayerCacheManager(File cacheDir) {
 
79
        this.cacheDir = cacheDir;
 
80
    }
 
81
    
 
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.
 
85
     */
 
86
    public final File getCacheDirectory() {
 
87
        return cacheDir;
 
88
    }
 
89
    
 
90
    /** True if the cache already seems to exist in the cache dir, false if fresh.
 
91
     */
 
92
    public abstract boolean cacheExists();
 
93
    
 
94
    /** Clean up any cache files in the cache directory.
 
95
     * @see "#20997"
 
96
     */
 
97
    public abstract void cleanupCache() throws IOException;
 
98
    
 
99
    /**
 
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
 
105
     */
 
106
    public boolean supportsLoad() {
 
107
        return true;
 
108
    }
 
109
    
 
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.
 
114
     */
 
115
    public FileSystem createEmptyFileSystem() throws IOException {
 
116
        if (supportsLoad()) {
 
117
            throw new NotImplementedException();
 
118
        } else {
 
119
            return new XMLFileSystem();
 
120
        }
 
121
    }
 
122
    
 
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.)
 
128
     */
 
129
    public FileSystem createLoadedFileSystem() throws IOException {
 
130
        if (!supportsLoad()) throw new IOException("Does not support loading!"); // NOI18N
 
131
        FileSystem fs = createEmptyFileSystem();
 
132
        load(fs);
 
133
        return fs;
 
134
    }
 
135
    
 
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.
 
143
     */
 
144
    public void load(FileSystem fs) throws IOException {
 
145
        throw new NotImplementedException();
 
146
    }
 
147
    
 
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.
 
158
     */
 
159
    public void store(FileSystem fs, List<URL> urls) throws IOException {
 
160
        throw new NotImplementedException();
 
161
    }
 
162
    
 
163
    /**
 
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.
 
169
     */
 
170
    public FileSystem store(List<URL> urls) throws IOException {
 
171
        throw new NotImplementedException();
 
172
    }
 
173
    
 
174
}