KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > startup > layers > LayerCacheManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.startup.layers;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27 import org.openide.filesystems.FileSystem;
28 import org.openide.filesystems.XMLFileSystem;
29 import org.openide.util.NotImplementedException;
30
31 /** Interface for a manager which can handle XML layer caching.
32  * @see "#20168"
33  * @author Jesse Glick
34  */

35 public abstract class LayerCacheManager {
36
37     /** Local error manager for in-package use.
38      */

39     static final Logger JavaDoc err = Logger.getLogger("org.netbeans.core.projects.cache"); // NOI18N
40

41     private final File JavaDoc cacheDir;
42     
43     private static LayerCacheManager emptyManager = null;
44     /**
45      * Get a cache manager which does nothing.
46      */

47     public static LayerCacheManager emptyManager() {
48         if (emptyManager == null) {
49             emptyManager = new NonCacheManager();
50         }
51         return emptyManager;
52     }
53     
54     /** Create a cache manager (for subclass use).
55      */

56     protected LayerCacheManager(File JavaDoc cacheDir) {
57         this.cacheDir = cacheDir;
58     }
59     
60     /** The directory to use a working area for the cache.
61      * For informational purposes only.
62      * May be null, if the manager is not really caching.
63      */

64     public final File JavaDoc getCacheDirectory() {
65         return cacheDir;
66     }
67     
68     /** True if the cache already seems to exist in the cache dir, false if fresh.
69      */

70     public abstract boolean cacheExists();
71     
72     /** Clean up any cache files in the cache directory.
73      * @see "#20997"
74      */

75     public abstract void cleanupCache() throws IOException JavaDoc;
76     
77     /**
78      * If true, this manager supports in-place loading of a cache.
79      * If false, it can only load a cache or store it.
80      * The result affects which methods are considered effectively present and
81      * abstract on this manager.
82      * @return true by default
83      */

84     public boolean supportsLoad() {
85         return true;
86     }
87     
88     /** Create an empty cache filesystem, i.e. with no initial layers.
89      * Should only be called when the cache directory is clean.
90      * Should not be overridden if the manager does not support loading;
91      * otherwise must be overridden.
92      */

93     public FileSystem createEmptyFileSystem() throws IOException JavaDoc {
94         if (supportsLoad()) {
95             throw new NotImplementedException();
96         } else {
97             return new XMLFileSystem();
98         }
99     }
100     
101     /** Create a preloaded cache filesystem with some existing set of layers.
102      * Should only be called when the cache directory is prepared.
103      * The default implementation just creates an empty cache and then
104      * loads it, but subclasses may override to do this more efficiently.
105      * (Subclasses which do not support loading <b>must</b> override it.)
106      */

107     public FileSystem createLoadedFileSystem() throws IOException JavaDoc {
108         if (!supportsLoad()) throw new IOException JavaDoc("Does not support loading!"); // NOI18N
109
FileSystem fs = createEmptyFileSystem();
110         load(fs);
111         return fs;
112     }
113     
114     /** Load the cache from disk.
115      * Should only be called when the cache directory is prepared.
116      * The filesystem's contents should be modified.
117      * The filesystem must have been originally produced by
118      * {@link #createEmptyFileSystem} or {@link #createLoadedFileSystem}.
119      * Not called if the manager does not support loading;
120      * otherwise must be overridden.
121      */

122     public void load(FileSystem fs) throws IOException JavaDoc {
123         throw new NotImplementedException();
124     }
125     
126     /** Save a new cache to disk.
127      * Besides modifying the disk cache files, this should also
128      * change the contents of the existing filesystem.
129      * The filesystem must have been originally produced by
130      * {@link #createEmptyFileSystem} or {@link #createLoadedFileSystem}.
131      * This might be done simply by calling {@link #load}, or there
132      * might be a more efficient way.
133      * @param urls list of type URL; earlier layers can override later layers
134      * Not called if the manager does not support loading;
135      * otherwise must be overridden.
136      */

137     public void store(FileSystem fs, List JavaDoc<URL JavaDoc> urls) throws IOException JavaDoc {
138         throw new NotImplementedException();
139     }
140     
141     /**
142      * Save a new cache to disk, load it, and return that filesystem.
143      * @param urls list of type URL; earlier layers can override later layers
144      * @return a new filesystem with the specified contents
145      * Not called if the manager supports loading;
146      * otherwise must be overridden.
147      */

148     public FileSystem store(List JavaDoc<URL JavaDoc> urls) throws IOException JavaDoc {
149         throw new NotImplementedException();
150     }
151     
152 }
153
Popular Tags