new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / ElementCache.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IOpenable;
14 import net.sourceforge.phpdt.core.JavaModelException;
15 import net.sourceforge.phpdt.internal.core.util.LRUCache;
16
17 /**
18  * An LRU cache of <code>JavaElements</code>.
19  */
20 public class ElementCache extends OverflowingLRUCache {
21 /**
22  * Constructs a new element cache of the given size.
23  */
24 public ElementCache(int size) {
25         super(size);
26 }
27 /**
28  * Constructs a new element cache of the given size.
29  */
30 public ElementCache(int size, int overflow) {
31         super(size, overflow);
32 }
33 /**
34  * Returns true if the element is successfully closed and
35  * removed from the cache, otherwise false.
36  *
37  * <p>NOTE: this triggers an external removal of this element
38  * by closing the element.
39  */
40 protected boolean close(LRUCacheEntry entry) {
41         IOpenable element = (IOpenable) entry._fKey;
42         try {
43                 if (element.hasUnsavedChanges()) {
44                         return false;
45                 } else {
46                         // We must close an entire JarPackageFragmentRoot at once.
47 //                      if (element instanceof JarPackageFragment) {
48 //                              JarPackageFragment packageFragment= (JarPackageFragment) element;
49 //                              JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent();
50 //                              root.close();
51 //                      } else {
52                                 element.close();
53 //                      }
54                         return true;
55                 }
56         } catch (JavaModelException npe) {
57                 return false;
58         }
59 }
60         /**
61          * Returns a new instance of the reciever.
62          */
63         protected LRUCache newInstance(int size, int overflow) {
64                 return new ElementCache(size, overflow);
65         }
66 }