Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.6.0)

E13403-07

oracle.jdeveloper.java
Class JavaModel

java.lang.Object
  extended by oracle.jdeveloper.java.JavaModel
All Implemented Interfaces:
JavaProvider, JavaFileProvider
Direct Known Subclasses:
JavaManager

public class JavaModel
extends java.lang.Object
implements JavaFileProvider

The JavaModel is an implementation of the JavaFileProvider interface. It provides structured access to the contents of Java class and source files visible through a set of source and classpaths.

There is also access to a JavaClassLocator instance for searching for the classes and subpackages contained in a package, and for finding an URL associated with a Java source or class file.

By default, the JavaFile and JavaClass (as well as SourceFile and SourceClass) instances retrieved through this API saved in a cache. Clients are encouraged to use the provided CacheSupport API to provide indication as to when the cache is used, and when it is no longer in use (and can be flushed). Clients can also force a cache flush to occur.


Nested Class Summary
protected  class JavaModel.CacheTracker
          The CacheTracker just helps track where begin/end cache use calls are being made, and to ensure that they are matched properly.
 
Field Summary
protected  CacheSupport _cacheSupport
          The cache support for this manager.
protected  JavaClassLocator _classLocator
          The class locator for this manager.
protected  CachedFileProvider _fileProvider
          The cached JavaFileProvider instance that does the real work.
 
Constructor Summary
protected JavaModel(CachedFileProvider provider)
          Protected constructor purposely.
 
Method Summary
 SourceFile createSourceFile(java.net.URL sourceURL)
          Creates a new SourceFile for the given Java source URL (*.java).
protected  void finalize()
          In the finalizer for this JavaManager, hint to the underlying provider that it should perhaps clear its cache.
 JavaType getArrayType(JavaType javaType, int dimensions)
          Fetch the JavaType instance that will represent the given type and array dimensions.
 CacheSupport getCacheSupport()
          Fetch the CacheSupport instance for managing the cache use for this JavaManager instance.
 JavaClass getClass(java.lang.String fqName)
          Fetch the JavaClass instance for the given fully-qualified type name.
 JavaClass getClass(java.lang.String fqPrefix, java.lang.String name)
          Deprecated. use getClass(String) instead
 JavaClass getClassByVMName(java.lang.String fqVMName)
          Fetch the JavaClass instance for the given fully-qualified type name in VM notation.
 java.lang.ClassLoader getClassLoader()
          Fetch a ClassLoader instance that can load classes from the paths of this JavaManager instance.
 java.lang.ClassLoader getClassLoader(java.lang.ClassLoader parentLoader)
          Fetch a ClassLoader instance that can load classes from the paths of this JavaManager instance.
 JavaFile getFile(java.net.URL url)
          Fetch the JavaFile for the given URL.
static JavaModel getInstance(URLPath sourcepath, URLPath classpath)
          Fetch a JavaManager instance for the given project.
 JavaClassLocator getJavaClassLocator()
          Fetch a JavaClassLocator instance for fetching package and class information.
 JavaPackage getPackage(java.lang.String fqName)
          Fetch the JavaPackage instance for the given fully-qualified package name.
 SourceClass getSourceClass(java.lang.String fqName)
          Fetch the SourceClass instance for the given fully-qualified class name.
 SourceFile getSourceFile(TextBuffer textBuffer)
          Creates a new SourceFile from the input TextBuffer but NOT tied any particular Java source URL.
 SourceFile getSourceFile(java.net.URL sourceURL)
          Fetch the SourceFile for the given Java source URL (*.java).
 TextBuffer getTextBuffer(java.net.URL url)
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_fileProvider

protected CachedFileProvider _fileProvider
The cached JavaFileProvider instance that does the real work.


_classLocator

protected JavaClassLocator _classLocator
The class locator for this manager.


_cacheSupport

protected CacheSupport _cacheSupport
The cache support for this manager.

Constructor Detail

JavaModel

protected JavaModel(CachedFileProvider provider)
Protected constructor purposely. Clients are forced to use the static factory methods in case this class becomes abstract in the future.

Parameters:
provider - the provider that we wrap
Method Detail

getInstance

public static JavaModel getInstance(URLPath sourcepath,
                                    URLPath classpath)
Fetch a JavaManager instance for the given project.

Note: Jdk paths are NOT implied. They must be explicitly included on sourcepath and classpath.

Parameters:
sourcepath - An URLPath specifying the sourcepath.
classpath - An URLPath specifying the classpath.
Returns:
a JavaModel instance for the specified sourcepath/classpath

finalize

protected void finalize()
In the finalizer for this JavaManager, hint to the underlying provider that it should perhaps clear its cache.

Overrides:
finalize in class java.lang.Object

getClassLoader

public java.lang.ClassLoader getClassLoader(java.lang.ClassLoader parentLoader)
Fetch a ClassLoader instance that can load classes from the paths of this JavaManager 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 from the paths of this JavaManager instance.


getJavaClassLocator

public JavaClassLocator getJavaClassLocator()
Fetch a JavaClassLocator instance for fetching package and class information.


getCacheSupport

public CacheSupport getCacheSupport()
Fetch the CacheSupport instance for managing the cache use for this JavaManager instance.


getFile

public JavaFile getFile(java.net.URL url)
Fetch the JavaFile for the given URL. The URL can be either a Java class file (*.class) or a Java source file (*.java). The classes contained in that file represented by the URL can be fetched from the JavaFile.

Specified by:
getFile in interface JavaFileProvider
Parameters:
url - the URL to get the Java file for
Returns:
the Java file for that URL.

getSourceFile

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

Specified by:
getSourceFile in interface JavaFileProvider
Parameters:
sourceURL - the source URL to get the Java file for
Returns:
the source file for the source URL

createSourceFile

public SourceFile createSourceFile(java.net.URL sourceURL)
                            throws java.io.IOException,
                                   java.lang.IllegalArgumentException
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
Parameters:
sourceURL - 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

getSourceFile

public SourceFile getSourceFile(TextBuffer textBuffer)
Creates a new SourceFile from the input TextBuffer but NOT tied any particular Java source URL. In particular, that means that the contents of this SourceFile are NOT fetchable and therefore this SourceFile cannot be referenced by any other.

Specified by:
getSourceFile in interface JavaFileProvider
Returns:
a newly created SourceFile based on the input TextBuffer.

getClass

public JavaClass getClass(java.lang.String fqName)
Fetch the JavaClass instance for the given fully-qualified type name. The type name specified can be either a primitive type, or a fully-qualified class name (including inner classes). Note that this may not return the same JavaClass instance every time.

Specified by:
getClass in interface JavaProvider
Parameters:
fqName - the fully-qualified name in dotted notation, such as "java.lang.Object" or "java.util.Map.Entry"
Returns:
the JavaClass instance for the given qualified type name, or null if not found

getClass

@Deprecated
public JavaClass getClass(java.lang.String fqPrefix,
                                     java.lang.String name)
Deprecated. use getClass(String) instead

Fetch the JavaClass instance for the given package prefix and class name. This is effectively the same as getClass( String fqName ) above. This is scheduled for removal.

Specified by:
getClass in interface JavaProvider
Parameters:
fqPrefix - the fully-qualified package prefix
name - the class name
Returns:
the JavaClass instance for the given class, or null if not found

getClassByVMName

public JavaClass getClassByVMName(java.lang.String fqVMName)
Fetch the JavaClass instance for the given fully-qualified type name in VM notation. The type name specified can be an array type, a primitive type, or a fully-qualified class (including inner classes). For example, "java.util.Map.Entry" is represented in VM notation as "java/util/Map$Entry". In VM notation, the '$' can be either a literal char, or class delimiter.

Specified by:
getClassByVMName in interface JavaProvider
Parameters:
fqVMName - the fully-qualified type name in VM notation, such as "java/util/Map$Entry"
Returns:
the JavaClass instance for the given name, or null if not found

getSourceClass

public SourceClass getSourceClass(java.lang.String fqName)
Fetch the SourceClass instance for the given fully-qualified class name. The type name specified should be a fully-qualified class (inner classes supported).

Specified by:
getSourceClass in interface JavaProvider
Parameters:
fqName - the fully-qualified class name in dotted notation, such as "java.lang.Object" or "java.util.Map.Entry"
Returns:
the SourceClass instance for the given name, or null if the source for the given class cannot be found

getArrayType

public JavaType getArrayType(JavaType javaType,
                             int dimensions)
Fetch the JavaType instance that will represent the given type and array dimensions.

Specified by:
getArrayType in interface JavaProvider
Parameters:
javaType - the JavaType instance to fetch an array type for
dimensions - the array dimensions to fetch
Returns:
the JavaType instance for the requested array type.
Throws:
java.lang.IllegalArgumentException - if dimensions is invalid (negative)

getPackage

public JavaPackage getPackage(java.lang.String fqName)
Fetch the JavaPackage instance for the given fully-qualified package name. An empty String, "", means the root package.

Specified by:
getPackage in interface JavaProvider
Parameters:
fqName - the fully-qualified package name, such as "java.io"
Returns:
the JavaPackage instance requested

getTextBuffer

@Deprecated
public TextBuffer getTextBuffer(java.net.URL url)
Deprecated. 

Fetch the TextBuffer instance for the given URL. This is scheduled for removal.

Specified by:
getTextBuffer in interface JavaProvider
Parameters:
url - the URL to get the buffer for
Returns:
the TextBuffer for the URL

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.6.0)

E13403-07

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