Jalopy 1.0b10

de.hunsicker.jalopy.storage
Class Convention

java.lang.Object
  |
  +--de.hunsicker.jalopy.storage.Convention

public final class Convention
extends Object

Represents a code convention: the settings that describe the desired coding style for Java source files.

To ensure type-safety, valid key access, two accompanying classes are provided:

 Convention settings = Convention.getInstance();
 int numThreads = settings.getInt(ConventionKeys.THREAD_COUNT,
                                  ConventionDefaults.THREAD_COUNT));
 

Version:
$Revision: 1.5 $
Author:
Marco Hunsicker, Roman Sarychev
See Also:
ConventionKeys, ConventionDefaults

Inner Class Summary
static class Convention.Key
          A key for storing a value in a code convention.
 
Field Summary
static String EXTENSION_DAT
          The file extension for Jalopy local binary code convention files (".dat").
static String EXTENSION_JAL
          The file extension for Jalopy binary code convention files (".jal").
static String EXTENSION_XML
          The file extension for Jalopy XML code convention files (".xml").
 
Method Summary
static void addProject(Project project)
          Adds a new project.
 void exportSettings(File file)
          Exports the code convention to the given file.
 void exportSettings(OutputStream out, String extension)
          Emits the code convention in a format indicated by the given extension.
 void flush()
          Flushes the code convention to the persistent store.
 String get(Convention.Key key, String def)
          Returns the value associated with the given key.
static File getBackupDirectory()
          Returns the current project's backup directory path.
 boolean getBoolean(Convention.Key key, boolean def)
          Returns the boolean value associated with the given key.
static Project getDefaultProject()
          Returns the default project.
static File getHistoryFile()
          Returns the history backing store file.
static Convention getInstance()
          Returns the sole instance of this object.
 int getInt(Convention.Key key, int def)
          Returns the int value represented by the string associated with the specified key in this preference node.
 Locale getLocale()
          Returns the preferred locale.
static File getProjectSettingsDirectory()
          Returns the current project settings directory.
static File getRepositoryDirectory()
          Returns the current project's class repository directory.
static File getSettingsDirectory()
          Returns the base settings directory.
static File getSettingsFile()
          Returns the local code convention file.
static void importSettings(File file)
          Imports the code convention from the given file.
static void importSettings(InputStream in, String extension)
          Imports the code convention from the specified input stream.
static void importSettings(URL url)
          Imports the code convention from the specified url.
 void put(Convention.Key key, String value)
          Implements the put method as per the specification in put(Convention.Key,String).
 void putBoolean(Convention.Key key, boolean value)
          Implements the putBoolean method as per the specification in putBoolean(Convention.Key,boolean).
 void putInt(Convention.Key key, int value)
          Implements the putInt method as per the specification in putInt(Convention.Key,int).
static void removeProject(Project project)
          Removes the given project.
 void revert()
          Reverts the code convention to the state of the last snapshot.
static boolean setProject(Project project)
          Sets the currently active project.
 void snapshot()
          Creates an internal snapshot of the current code convention.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EXTENSION_JAL

public static final String EXTENSION_JAL
The file extension for Jalopy binary code convention files (".jal").

EXTENSION_XML

public static final String EXTENSION_XML
The file extension for Jalopy XML code convention files (".xml").

EXTENSION_DAT

public static final String EXTENSION_DAT
The file extension for Jalopy local binary code convention files (".dat").
Method Detail

getBackupDirectory

public static File getBackupDirectory()
Returns the current project's backup directory path.
Returns:
backup directory.
Since:
1.0b8

getDefaultProject

public static Project getDefaultProject()
Returns the default project.
Returns:
the default project.
Since:
1.0b8

getHistoryFile

public static File getHistoryFile()
Returns the history backing store file.
Returns:
history backing store file.

getInstance

public static Convention getInstance()
Returns the sole instance of this object.
Returns:
the sole instance of this object.

getLocale

public Locale getLocale()
Returns the preferred locale.
Returns:
the preferred locale.
Since:
1.0b9

setProject

public static boolean setProject(Project project)
Sets the currently active project.
Parameters:
project - the new active project.
Returns:
true if setting the project was successful.
Since:
1.0b8

getProjectSettingsDirectory

public static File getProjectSettingsDirectory()
Returns the current project settings directory.
Returns:
settings directory.
Since:
1.0b8

getRepositoryDirectory

public static File getRepositoryDirectory()
Returns the current project's class repository directory.
Returns:
class repository directory.
Since:
1.0b8

getSettingsDirectory

public static File getSettingsDirectory()
Returns the base settings directory.
Returns:
settings directory.
Since:
1.0b8

getSettingsFile

public static File getSettingsFile()
Returns the local code convention file.
Returns:
local code convention file.
Since:
1.0b8

addProject

public static void addProject(Project project)
                       throws IOException
Adds a new project. Adding a project means that the settings of the currently active project will be duplicated to the new project settings directory.
Parameters:
project - the project information.
Throws:
IOException - if an I/O error occured.
Since:
1.0b8

importSettings

public static void importSettings(InputStream in,
                                  String extension)
                           throws IOException
Imports the code convention from the specified input stream.
Parameters:
in - the input stream from which to read the code convention.
extension - file extension indicating the format of the saved code convention.
Throws:
IOException - if an I/O error occured.
IllegalArgumentException - if an invalid extension was specified.

importSettings

public static void importSettings(URL url)
                           throws IOException
Imports the code convention from the specified url.
Parameters:
url - url to import the code convention from.
Throws:
IOException - an I/O error occured.
ChainingRuntimeException - DOCUMENT ME!

importSettings

public static void importSettings(File file)
                           throws IOException
Imports the code convention from the given file.
Parameters:
file - code convention file.
Throws:
IOException - if an I/O error occured.
FileNotFoundException - DOCUMENT ME!
IllegalArgumentException - DOCUMENT ME!

removeProject

public static void removeProject(Project project)
                          throws IOException
Removes the given project.
Parameters:
project - a project.
Throws:
IOException - if an I/O error occured.
Since:
1.0b8

getBoolean

public boolean getBoolean(Convention.Key key,
                          boolean def)
Returns the boolean value associated with the given key.

This implementation invokes get(key, null). If the return value is non-null, it is compared with "true" using String.equalsIgnoreCase(String). If the comparison returns true, this invocation returns true. Otherwise, the original return value is compared with "false", again using String.equalsIgnoreCase(String). If the comparison returns true, this invocation returns false. Otherwise, this invocation returns def.

Parameters:
key - key whose associated value is to be returned as a boolean.
def - the value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as a boolean.
Returns:
the boolean value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as a boolean.

getInt

public int getInt(Convention.Key key,
                  int def)
Returns the int value represented by the string associated with the specified key in this preference node. The string is converted to an integer as by Integer.parseInt(String). Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if Integer.parseInt(String) would throw a NumberFormatException if the associated value were passed. This method is intended for use in conjunction with putInt(de.hunsicker.jalopy.storage.Convention.Key, int).
Parameters:
key - key whose associated value is to be returned as an int.
def - the value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as an int, or the backing store is inaccessible.
Returns:
the int value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as an int.
See Also:
putInt(Convention.Key,int), get(Convention.Key,String)

exportSettings

public void exportSettings(File file)
                    throws IOException
Exports the code convention to the given file. The file extension determines the format in which the code convention will be written.
Parameters:
file - file to export the code convention to.
Throws:
IOException - if writing to the specified output stream failed.

exportSettings

public void exportSettings(OutputStream out,
                           String extension)
                    throws IOException
Emits the code convention in a format indicated by the given extension. If no extension is given, the default format will be used (the binary .jal format).
Parameters:
out - the output stream on which to emit the code convention.
extension - output format to use. Either EXTENSION_JAL or EXTENSION_XML.
Throws:
IOException - if an I/O error occured.
IllegalArgumentException - if extension is no valid file extension.

flush

public void flush()
           throws IOException
Flushes the code convention to the persistent store.
Throws:
IOException - if an I/O error occured.

get

public String get(Convention.Key key,
                  String def)
Returns the value associated with the given key.

This implementation first checks to see if key is null throwing a NullPointerException if this is the case.

Parameters:
key - key whose associated value is to be returned.
def - the value to be returned in the event that this preference node has no value associated with key.
Returns:
the value associated with key, or def if no value is associated with key.
Throws:
NullPointerException - if key is null. (A null default is permitted.)

put

public void put(Convention.Key key,
                String value)
Implements the put method as per the specification in put(Convention.Key,String).
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Throws:
NullPointerException - if key or value is null.

putBoolean

public void putBoolean(Convention.Key key,
                       boolean value)
Implements the putBoolean method as per the specification in putBoolean(Convention.Key,boolean).

This implementation translates value to a string with String.valueOf(boolean) and invokes put(Convention.Key,String) on the result.

Parameters:
key - key with which the string form of value is to be associated.
value - value whose string form is to be associated with key.

putInt

public void putInt(Convention.Key key,
                   int value)
Implements the putInt method as per the specification in putInt(Convention.Key,int).

This implementation translates value to a string with Integer.toString(int) and invokes put(Convention.Key,String) on the result.

Parameters:
key - key with which the string form of value is to be associated.
value - value whose string form is to be associated with key.

revert

public void revert()
Reverts the code convention to the state of the last snapshot. If no snapshots exists, the call will be ignored.
Since:
1.0b8
See Also:
snapshot()

snapshot

public void snapshot()
Creates an internal snapshot of the current code convention. You can then use revert() at any time to revert the code convention to the state of the last snapshot.
Since:
1.0b8
See Also:
revert()

toString

public String toString()
Returns a string representation of this object.
Overrides:
toString in class Object
Returns:
a string representation of this object.

Jalopy 1.0b10

Submit a bug or feature.

For further information and documentation, visit the official Jalopy website.
This page generated: November 14 2002