javax.tools
Class SimpleJavaFileObject

java.lang.Object
  extended by javax.tools.SimpleJavaFileObject
All Implemented Interfaces:
FileObject, JavaFileObject
Direct Known Subclasses:
StringJavaFileObject

public class SimpleJavaFileObject
extends java.lang.Object
implements JavaFileObject

Provides simple implementations for most methods in JavaFileObject. This class is designed to be subclassed and used as a basis for JavaFileObject implementations. Subclasses can override the implementation and specification of any method of this class as long as the general contract of JavaFileObject is obeyed.

Since:
1.6

Nested Class Summary
 
Nested classes/interfaces inherited from interface javax.tools.JavaFileObject
JavaFileObject.Kind
 
Field Summary
protected  JavaFileObject.Kind kind
          The kind of this file object.
protected  java.net.URI uri
          A URI for this file object.
 
Constructor Summary
protected SimpleJavaFileObject(java.net.URI uri, JavaFileObject.Kind kind)
          Construct a SimpleJavaFileObject of the given kind and with the given URI.
 
Method Summary
 boolean delete()
          This implementation does nothing.
 Modifier getAccessLevel()
          This implementation returns null.
 java.lang.CharSequence getCharContent(boolean ignoreEncodingErrors)
          This implementation always throws UnsupportedOperationException.
 JavaFileObject.Kind getKind()
          Gets the kind of this file object.
 long getLastModified()
          This implementation returns 0L.
 java.lang.String getName()
          Gets a user-friendly name for this file object.
 NestingKind getNestingKind()
          This implementation returns null.
 boolean isNameCompatible(java.lang.String simpleName, JavaFileObject.Kind kind)
          This implementation compares the path of its URI to the given simple name.
 java.io.InputStream openInputStream()
          This implementation always throws UnsupportedOperationException.
 java.io.OutputStream openOutputStream()
          This implementation always throws UnsupportedOperationException.
 java.io.Reader openReader(boolean ignoreEncodingErrors)
          Wraps the result of getCharContent(boolean) in a Reader.
 java.io.Writer openWriter()
          Wraps the result of openOutputStream in a Writer.
 java.lang.String toString()
           
 java.net.URI toUri()
          Returns a URI identifying this file object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uri

protected final java.net.URI uri
A URI for this file object.


kind

protected final JavaFileObject.Kind kind
The kind of this file object.

Constructor Detail

SimpleJavaFileObject

protected SimpleJavaFileObject(java.net.URI uri,
                               JavaFileObject.Kind kind)
Construct a SimpleJavaFileObject of the given kind and with the given URI.

Parameters:
uri - the URI for this file object
kind - the kind of this file object
Method Detail

toUri

public java.net.URI toUri()
Description copied from interface: FileObject
Returns a URI identifying this file object.

Specified by:
toUri in interface FileObject
Returns:
a URI

getName

public java.lang.String getName()
Description copied from interface: FileObject
Gets a user-friendly name for this file object. The exact value returned is not specified but implementations should take care to preserve names as given by the user. For example, if the user writes the filename "BobsApp\Test.java" on the command line, this method should return "BobsApp\Test.java" whereas the toUri method might return file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java.

Specified by:
getName in interface FileObject
Returns:
a user-friendly name

openInputStream

public java.io.InputStream openInputStream()
                                    throws java.io.IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject is obeyed.

Specified by:
openInputStream in interface FileObject
Returns:
an InputStream
Throws:
java.io.IOException - if an I/O error occurred

openOutputStream

public java.io.OutputStream openOutputStream()
                                      throws java.io.IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject is obeyed.

Specified by:
openOutputStream in interface FileObject
Returns:
an OutputStream
Throws:
java.io.IOException - if an I/O error occurred

openReader

public java.io.Reader openReader(boolean ignoreEncodingErrors)
                          throws java.io.IOException
Wraps the result of getCharContent(boolean) in a Reader. Subclasses can change this behavior as long as the contract of FileObject is obeyed.

Specified by:
openReader in interface FileObject
Parameters:
ignoreEncodingErrors - ignore encoding errors if true
Returns:
a Reader wrapping the result of getCharContent
Throws:
java.lang.IllegalStateException - if this file object was opened for writing and does not support reading
java.lang.UnsupportedOperationException - if this kind of file object does not support character access
java.io.IOException - if an I/O error occurred

getCharContent

public java.lang.CharSequence getCharContent(boolean ignoreEncodingErrors)
                                      throws java.io.IOException
This implementation always throws UnsupportedOperationException. Subclasses can change this behavior as long as the contract of FileObject is obeyed.

Specified by:
getCharContent in interface FileObject
Parameters:
ignoreEncodingErrors - ignore encoding errors if true
Returns:
a CharSequence if available; null otherwise
Throws:
java.io.IOException - if an I/O error occurred

openWriter

public java.io.Writer openWriter()
                          throws java.io.IOException
Wraps the result of openOutputStream in a Writer. Subclasses can change this behavior as long as the contract of FileObject is obeyed.

Specified by:
openWriter in interface FileObject
Returns:
a Writer wrapping the result of openOutputStream
Throws:
java.lang.IllegalStateException - if this file object was opened for reading and does not support writing
java.lang.UnsupportedOperationException - if this kind of file object does not support character access
java.io.IOException - if an I/O error occurred

getLastModified

public long getLastModified()
This implementation returns 0L. Subclasses can change this behavior as long as the contract of FileObject is obeyed.

Specified by:
getLastModified in interface FileObject
Returns:
0L

delete

public boolean delete()
This implementation does nothing. Subclasses can change this behavior as long as the contract of FileObject is obeyed.

Specified by:
delete in interface FileObject
Returns:
false

getKind

public JavaFileObject.Kind getKind()
Description copied from interface: JavaFileObject
Gets the kind of this file object.

Specified by:
getKind in interface JavaFileObject
Returns:
this.kind

isNameCompatible

public boolean isNameCompatible(java.lang.String simpleName,
                                JavaFileObject.Kind kind)
This implementation compares the path of its URI to the given simple name. This method returns true if the given kind is equal to the kind of this object, and if the path is equal to simpleName + kind.extension or if it ends with "/" + simpleName + kind.extension.

This method calls getKind() and toUri() and does not access the fields uri and kind directly.

Subclasses can change this behavior as long as the contract of JavaFileObject is obeyed.

Specified by:
isNameCompatible in interface JavaFileObject
Parameters:
simpleName - a simple name of a class
kind - a kind
Returns:
true if this file object is compatible; false otherwise

getNestingKind

public NestingKind getNestingKind()
This implementation returns null. Subclasses can change this behavior as long as the contract of JavaFileObject is obeyed.

Specified by:
getNestingKind in interface JavaFileObject
Returns:
the nesting kind, or null if the nesting kind is not known

getAccessLevel

public Modifier getAccessLevel()
This implementation returns null. Subclasses can change this behavior as long as the contract of JavaFileObject is obeyed.

Specified by:
getAccessLevel in interface JavaFileObject
Returns:
the access level

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object