Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

oracle.jdeveloper.java.provider
Class CachedFileProvider

java.lang.Object
  extended by oracle.jdeveloper.java.provider.BaseFileProvider
      extended by oracle.jdeveloper.java.provider.CachedFileProvider
All Implemented Interfaces:
JavaProvider, JavaProvider2, CacheSupport, JavaFileProvider, ProviderConstants
Direct Known Subclasses:
SimpleFileProvider

public abstract class CachedFileProvider
extends BaseFileProvider
implements CacheSupport

The CachedFileProvider is an abstract starting point for an implementation of the JavaFileProvider interface that adds cache support to the BaseFileProvider.


Nested Class Summary
protected  class CachedFileProvider.SourceFileTracker
          The SourceFileTracker just listens to SourceFile instances that we create/cache, expiring them from our cache when they get modified outside of a transaction.
 
Nested classes/interfaces inherited from class oracle.jdeveloper.java.provider.BaseFileProvider
BaseFileProvider.BaseClass, BaseFileProvider.BasePackage
 
Field Summary
protected  java.util.Map<java.lang.String,JavaType> _arrayCacheMap
          Our cache of array types.
protected  java.lang.Object _cacheLock
          Our cache lock for synchronization
protected  int _cacheRefCount
          The ref count of cache use calls.
protected  java.util.Map<java.lang.String,JavaClass> _classCacheMap
          Our cache of class instances.
protected  java.util.Map<java.net.URL,JavaFile> _classFileCacheMap
          Our cache of *.class JavaFile instances.
protected  java.lang.ClassLoader _defaultClassLoader
          The (cached) default class loader instance.
protected  long _lastCacheFlushedTime
           
protected  java.util.Map<java.net.URL,JavaFile> _lightSourceFileCacheMap
          Our cache of "light" SourceFiles
protected  java.lang.ClassLoader _nullClassLoader
          The (cached) null-parent class loader instance.
protected  java.util.Map<java.lang.String,JavaPackage> _packageCacheMap
          Our cache of packages.
protected  java.util.Map<java.net.URL,SourceFile> _sourceFileCacheMap
          Our cache of *.java SourceFile instances.
protected static JavaClass CLASS_NOT_FOUND
          Marker for class not found in the class cache
 
Fields inherited from class oracle.jdeveloper.java.provider.BaseFileProvider
context
 
Fields inherited from interface oracle.jdeveloper.java.provider.ProviderConstants
CLASS_TYPE, EMPTY_COLLECTION, SOURCE_TYPE, UNKNOWN_TYPE
 
Constructor Summary
CachedFileProvider(ProviderContext environment, java.lang.String scopeDescription)
           
 
Method Summary
 void beginCacheUse()
          Instructs the data provider to enable the cache support.
protected  void clearAllData()
          Instructs this data provider to clear all cached data, and stop all trackers.
protected  void clearArrayCache()
          Utility routine to clean out our package cache.
protected  void clearClassCache()
          Utility routine to clean out our class caches.
protected  void clearClassFileCache()
          Utility routine to clean out our class file caches.
protected  void clearClassLoader()
          Internal method to allow clearing of the class loader (for example, in case a subclass changes the class locator instance.)
protected  void clearCompiledInfo()
          Utility routine to clear all compiled info.
protected  void clearLightSourceFileCache()
          Utility routine to clean out our light source file caches.
protected  void clearPackageCache()
          Utility routine to clean out our package cache.
protected  void clearSourceFileCache()
          Utility routine to clean out our source file caches.
 SourceFile createSourceFile(java.net.URL url)
          Creates a new SourceFile for the given Java source URL (*.java).
 void endCacheUse()
          Instructs the data provider to release the cache support.
protected  void expireAllSourceFiles()
          Utility routine to expire all SourceFile instances that we have cached currently.
 void flushCache()
          Instructs the data provider to force a cache flush.
protected  void flushFoundCache()
          Instructs the data provider to flush the resolution part of the cache (i.e., the found or not found) part of the cache.
protected  JavaType getArrayTypeImpl(java.lang.String typeKey, JavaType component, int dimensions)
          Fetch the array type represented by the given type and dimensions.
protected  JavaClass getClassExactImpl(java.lang.String fqOuterClassName)
          Utility routine to try to locate the given outer class.
protected  JavaClass getClassExactImplInterruptibly(java.lang.String fqOuterClassName)
          Utility routine to try to locate the given outer class.
protected  JavaFile getClassFileImpl(java.net.URL classURL)
          Fetch the JavaFile for the given Java class URL (*.class).
 java.lang.ClassLoader getClassLoader()
          Fetch a ClassLoader instance that can load classes based on the same class locator as this file provider instance.
 java.lang.ClassLoader getClassLoader(java.lang.ClassLoader parentLoader)
          Fetch a ClassLoader instance that can load classes based on the same class locator as this file provider instance.
protected  JavaFile getLightSourceFileImpl(java.net.URL sourceURL)
          Fetch a "light" SourceFile for the given Java source URL (*.java), packaged as a JavaFile.
protected  BaseFileProvider.BasePackage getPackageImpl(java.lang.String fqName)
          Fetch the JavaPackage instance for the given package.
 java.lang.String getScopeDescription()
           
protected  SourceFile getSourceFileImpl(java.net.URL sourceURL)
          Fetch the SourceFile for the given Java source URL (*.java).
 long lastCacheFlushed()
           
protected  JavaFile lookupCachedLightSourceFile(java.net.URL sourceURL)
          Utility routine which looks up the cached LightSourceFile entry in our cache map, which uses SoftReference values.
protected  SourceFile lookupCachedSourceFile(java.net.URL sourceURL)
          Utility routine which looks up the cached SourceFile entry in our cache map, which uses SoftReference values.
 void notifyOfChange(java.net.URL url)
          Called by the ProviderEnvironment when a change has happened to an URL that we were tracking.
protected  JavaFile removeCachedLightSourceFile(java.net.URL sourceURL, JavaFile javaFile)
          Utility routine which removes the cached LightSourceFile (if any) from our cache map.
protected  void removeCachedSourceFile(java.net.URL sourceURL)
          Deprecated. use removeCachedSourceFile( URL, SourceFile ) instead
protected  void removeCachedSourceFile(java.net.URL sourceURL, SourceFile sourceFile)
          Utility routine which removes the cached SourceFile from our cache map.
protected  void storeCachedLightSourceFile(java.net.URL sourceURL, JavaFile sourceFile)
          Utility routine which stores the given sourcefile into our cache using SoftReferences.
protected  void storeCachedSourceFile(java.net.URL sourceURL, SourceFile sourceFile)
          Utility routine which stores the given sourcefile into our cache using SoftReferences.
 
Methods inherited from class oracle.jdeveloper.java.provider.BaseFileProvider
checkInterrupt, getArrayType, getClass, getClass, getClassByVMName, getClassByVMNameImpl, getClassByVMNameInterruptibly, getClassImpl, getClassImpl, getClassInterruptibly, getClassInterruptibly, getClassLeftToRight, getClassLeftToRightImpl, getClassLeftToRightInterruptibly, getClassLocator, getClassLocatorInterruptibly, getConteXt, getFile, getFileType, getInnerClassByVMName, getJavaFile, getPackage, getPackage, getPrimitiveClass, getSourceClass, getSourceClassByHint, getSourceClassImpl, getSourceClassInterruptibly, getSourceFile, getSourceFile, getTargetJdkVersion, getTextBuffer, locateClass, locateClass, locateClassByVMName, locateSourceClass, locateSourceClass, setConteXt, setTargetJdkVersion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_cacheLock

protected final java.lang.Object _cacheLock
Our cache lock for synchronization


_nullClassLoader

protected java.lang.ClassLoader _nullClassLoader
The (cached) null-parent class loader instance.


_defaultClassLoader

protected java.lang.ClassLoader _defaultClassLoader
The (cached) default class loader instance.


_lastCacheFlushedTime

protected long _lastCacheFlushedTime

_packageCacheMap

protected java.util.Map<java.lang.String,JavaPackage> _packageCacheMap
Our cache of packages. This stores the JavaPackage instances.


_sourceFileCacheMap

protected java.util.Map<java.net.URL,SourceFile> _sourceFileCacheMap
Our cache of *.java SourceFile instances. The values are weak references of SourceFile instances.


_arrayCacheMap

protected java.util.Map<java.lang.String,JavaType> _arrayCacheMap
Our cache of array types. This stores the JavaClass (JavaType) instances for the array types.


_classCacheMap

protected java.util.Map<java.lang.String,JavaClass> _classCacheMap
Our cache of class instances. Our class cache stores the JavaClass instances of just outer classes, if the class is found, or a marker value if not. This probably could use a more tailored cache, that does LRU but distinguishes class files from source files.


_classFileCacheMap

protected java.util.Map<java.net.URL,JavaFile> _classFileCacheMap
Our cache of *.class JavaFile instances.


_lightSourceFileCacheMap

protected java.util.Map<java.net.URL,JavaFile> _lightSourceFileCacheMap
Our cache of "light" SourceFiles


CLASS_NOT_FOUND

protected static final JavaClass CLASS_NOT_FOUND
Marker for class not found in the class cache


_cacheRefCount

protected int _cacheRefCount
The ref count of cache use calls.

Constructor Detail

CachedFileProvider

public CachedFileProvider(ProviderContext environment,
                          java.lang.String scopeDescription)
Method Detail

getClassLoader

public java.lang.ClassLoader getClassLoader(java.lang.ClassLoader parentLoader)
Fetch a ClassLoader instance that can load classes based on the same class locator as this file provider instance.

Only one null-parent class loader will be created per cached file provider. For non-null parent loaders, this always creates a new instance.

Parameters:
parentLoader - The ClassLoader to use as the parent. May be null.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Fetch a ClassLoader instance that can load classes based on the same class locator as this file provider instance.


clearClassLoader

protected void clearClassLoader()
Internal method to allow clearing of the class loader (for example, in case a subclass changes the class locator instance.)


createSourceFile

public SourceFile createSourceFile(java.net.URL url)
                            throws java.io.IOException,
                                   java.lang.IllegalArgumentException
Description copied from class: BaseFileProvider
Creates a new SourceFile for the given Java source URL (*.java). This will create a new empty file for the given URL, and return a SourceFile instance for it. If the file already exists on disk, then this will return null.

Specified by:
createSourceFile in interface JavaFileProvider
Overrides:
createSourceFile in class BaseFileProvider
Parameters:
url - the source URL to create a new Java file for
Returns:
the new source file for the source URL, or null if the file could not be created because it exists
Throws:
java.io.IOException - if the new file cannot be created
java.lang.IllegalArgumentException - if the URL is not recognized as a Java source file

getSourceFileImpl

protected SourceFile getSourceFileImpl(java.net.URL sourceURL)
Fetch the SourceFile for the given Java source URL (*.java). This is a source-version of getClassFileImpl().

Overrides:
getSourceFileImpl in class BaseFileProvider
Parameters:
sourceURL - the source URL to get the SourceFile for
Returns:
the source file for the source URL

getLightSourceFileImpl

protected JavaFile getLightSourceFileImpl(java.net.URL sourceURL)
Description copied from class: BaseFileProvider
Fetch a "light" SourceFile for the given Java source URL (*.java), packaged as a JavaFile. This is the preferred way to get class and member information from a source IFF the caller doesn't care about the code inside method bodies, since this call triggers a fast parse that skips method bodies. Use getSourceFileImpl to trigger a full parse that also collects information from method bodies.

Overrides:
getLightSourceFileImpl in class BaseFileProvider
Parameters:
sourceURL - the source URL from which to get the source
Returns:
the "light" SourceFile for the source URL

beginCacheUse

public void beginCacheUse()
Instructs the data provider to enable the cache support. Since multiple clients may be using the data provider at the same time with cachesupport enabled, each client needs to make sure to call endCacheUse() when finished to ensure that the cache can be freed when it is no longer needed.

Specified by:
beginCacheUse in interface CacheSupport

endCacheUse

public void endCacheUse()
Instructs the data provider to release the cache support.

Specified by:
endCacheUse in interface CacheSupport

lastCacheFlushed

public long lastCacheFlushed()

flushCache

public void flushCache()
Instructs the data provider to force a cache flush.

Specified by:
flushCache in interface CacheSupport

flushFoundCache

protected void flushFoundCache()
Instructs the data provider to flush the resolution part of the cache (i.e., the found or not found) part of the cache.


clearAllData

protected void clearAllData()
Instructs this data provider to clear all cached data, and stop all trackers. This can be used for example if the Project is being closed, and we want to shut this down.


getClassFileImpl

protected JavaFile getClassFileImpl(java.net.URL classURL)
Fetch the JavaFile for the given Java class URL (*.class). The classes contained in the file represented by the URL can be fetched from the class file. If the URL does not represent a valid Java class file, or if the URL points to a non-existing file, then null will be returned.

Overrides:
getClassFileImpl in class BaseFileProvider
Parameters:
classURL - the class URL to get the Java file for
Returns:
the class file for the class URL

clearClassFileCache

protected void clearClassFileCache()
Utility routine to clean out our class file caches.


lookupCachedSourceFile

protected SourceFile lookupCachedSourceFile(java.net.URL sourceURL)
Utility routine which looks up the cached SourceFile entry in our cache map, which uses SoftReference values.


removeCachedSourceFile

@Deprecated
protected void removeCachedSourceFile(java.net.URL sourceURL)
Deprecated. use removeCachedSourceFile( URL, SourceFile ) instead

Utility routine which removes the cached SourceFile (if any) from our cache map.


removeCachedSourceFile

protected void removeCachedSourceFile(java.net.URL sourceURL,
                                      SourceFile sourceFile)
Utility routine which removes the cached SourceFile from our cache map. Optionally it can check and ONLY remove the SourceFile, if it is actually mapped to the URL.

Parameters:
sourceURL - - the URL used as the key to find the SourceFile
sourceFile - - if null, the key/value pair is always removed if it exists; if not null, the key/value pair is ONLY removed if the value is equal to the incoming sourceFile

storeCachedSourceFile

protected void storeCachedSourceFile(java.net.URL sourceURL,
                                     SourceFile sourceFile)
Utility routine which stores the given sourcefile into our cache using SoftReferences.


expireAllSourceFiles

protected void expireAllSourceFiles()
Utility routine to expire all SourceFile instances that we have cached currently.


clearSourceFileCache

protected void clearSourceFileCache()
Utility routine to clean out our source file caches.


clearCompiledInfo

protected void clearCompiledInfo()
Utility routine to clear all compiled info. When a SourceFile is expired, it is necessary to clear compiled info in case there are any references to the expired file.


notifyOfChange

public void notifyOfChange(java.net.URL url)
Description copied from class: BaseFileProvider
Called by the ProviderEnvironment when a change has happened to an URL that we were tracking.

Overrides:
notifyOfChange in class BaseFileProvider

lookupCachedLightSourceFile

protected JavaFile lookupCachedLightSourceFile(java.net.URL sourceURL)
Utility routine which looks up the cached LightSourceFile entry in our cache map, which uses SoftReference values.


removeCachedLightSourceFile

protected JavaFile removeCachedLightSourceFile(java.net.URL sourceURL,
                                               JavaFile javaFile)
Utility routine which removes the cached LightSourceFile (if any) from our cache map.

Parameters:
sourceURL - - The source URL used as a key to find the LightSourceFile
javaFile - - if null, the key/value pair stored using the sourceURL is removed without any checks; if not null, the key/value pair is ONLY removed if the value matches the incoming javaFile
Returns:
the removed value is anything was removed

storeCachedLightSourceFile

protected void storeCachedLightSourceFile(java.net.URL sourceURL,
                                          JavaFile sourceFile)
Utility routine which stores the given sourcefile into our cache using SoftReferences.


clearLightSourceFileCache

protected void clearLightSourceFileCache()
Utility routine to clean out our light source file caches.


getClassExactImpl

protected JavaClass getClassExactImpl(java.lang.String fqOuterClassName)
Utility routine to try to locate the given outer class.

Overrides:
getClassExactImpl in class BaseFileProvider
Parameters:
fqOuterClassName - the name of the fully-qualified outer class name we are searching for
Returns:
the class we are trying to find, or null if it cannot be found

getClassExactImplInterruptibly

protected JavaClass getClassExactImplInterruptibly(java.lang.String fqOuterClassName)
                                            throws java.lang.InterruptedException
Utility routine to try to locate the given outer class.

Overrides:
getClassExactImplInterruptibly in class BaseFileProvider
Parameters:
fqOuterClassName - the name of the fully-qualified outer class name we are searching for
Returns:
the class we are trying to find, or null if it cannot be found
Throws:
java.lang.InterruptedException - if the search was interrupted

clearClassCache

protected void clearClassCache()
Utility routine to clean out our class caches.


getArrayTypeImpl

protected JavaType getArrayTypeImpl(java.lang.String typeKey,
                                    JavaType component,
                                    int dimensions)
Fetch the array type represented by the given type and dimensions.

Overrides:
getArrayTypeImpl in class BaseFileProvider
Parameters:
typeKey - the qualified name of the type followed by the '[]'s for the dimension
component - the java type
dimensions - the array dimension
Returns:
the array type for the given java type and dimensions

clearArrayCache

protected void clearArrayCache()
Utility routine to clean out our package cache.


getPackageImpl

protected BaseFileProvider.BasePackage getPackageImpl(java.lang.String fqName)
Fetch the JavaPackage instance for the given package.

Overrides:
getPackageImpl in class BaseFileProvider

clearPackageCache

protected void clearPackageCache()
Utility routine to clean out our package cache.


getScopeDescription

public java.lang.String getScopeDescription()

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

Copyright © 1997, 2011, Oracle. All rights reserved.