de.hunsicker.jalopy.storage
Class Convention

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

public final class Convention
extends java.lang.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.2.7 $
Author:
Marco Hunsicker, Roman Sarychev
See Also:
ConventionKeys, ConventionDefaults

Nested Class Summary
static class Convention.Key
          A key for storing a value in a code convention.
 
Field Summary
static java.lang.String EXTENSION_DAT
          The file extension for Jalopy local binary code convention files (".dat").
static java.lang.String EXTENSION_JAL
          The file extension for Jalopy binary code convention files (".jal").
static java.lang.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(java.io.File file)
          Exports the code convention to the given file.
 void exportSettings(java.io.OutputStream out, java.lang.String extension)
          Emits the code convention in a format indicated by the given extension.
 void flush()
          Flushes the code convention to the persistent store.
 java.lang.String get(Convention.Key key, java.lang.String def)
          Returns the value associated with the given key.
static java.io.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 java.io.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.
 java.util.Locale getLocale()
          Returns the preferred locale.
static java.io.File getProjectSettingsDirectory()
          Returns the current project settings directory.
static java.io.File getRepositoryDirectory()
          Returns the current project's class repository directory.
static java.io.File getSettingsDirectory()
          Returns the base settings directory.
static java.io.File getSettingsFile()
          Returns the local code convention file.
static void importSettings(java.io.File file)
          Imports the code convention from the given file.
static void importSettings(java.io.InputStream in, java.lang.String extension)
          Imports the code convention from the specified input stream.
static void importSettings(java.net.URL url)
          Imports the code convention from the specified url.
 void put(Convention.Key key, java.lang.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.
 java.lang.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 java.lang.String EXTENSION_JAL
The file extension for Jalopy binary code convention files (".jal").

See Also:
Constant Field Values

EXTENSION_XML

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

See Also:
Constant Field Values

EXTENSION_DAT

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

See Also:
Constant Field Values
Method Detail

getBackupDirectory

public static java.io.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 java.io.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 java.util.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 java.io.File getProjectSettingsDirectory()
Returns the current project settings directory.

Returns:
settings directory.
Since:
1.0b8

getRepositoryDirectory

public static java.io.File getRepositoryDirectory()
Returns the current project's class repository directory.

Returns:
class repository directory.
Since:
1.0b8

getSettingsDirectory

public static java.io.File getSettingsDirectory()
Returns the base settings directory.

Returns:
settings directory.
Since:
1.0b8

getSettingsFile

public static java.io.File getSettingsFile()
Returns the local code convention file.

Returns:
local code convention file.
Since:
1.0b8

addProject

public static void addProject(Project project)
                       throws java.io.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:
java.io.IOException - if an I/O error occured.
Since:
1.0b8

importSettings

public static void importSettings(java.io.InputStream in,
                                  java.lang.String extension)
                           throws java.io.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:
java.io.IOException - if an I/O error occured.
java.lang.IllegalArgumentException - if an invalid extension was specified.

importSettings

public static void importSettings(java.net.URL url)
                           throws java.io.IOException
Imports the code convention from the specified url.

Parameters:
url - url to import the code convention from.
Throws:
java.io.IOException - an I/O error occured.
ChainingRuntimeException - If an error occurs

importSettings

public static void importSettings(java.io.File file)
                           throws java.io.IOException
Imports the code convention from the given file.

Parameters:
file - code convention file.
Throws:
java.io.IOException - if an I/O error occured.
java.io.FileNotFoundException - File not found
java.lang.IllegalArgumentException - Illegal arg

removeProject

public static void removeProject(Project project)
                          throws java.io.IOException
Removes the given project.

Parameters:
project - a project.
Throws:
java.io.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(java.io.File file)
                    throws java.io.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:
java.io.IOException - if writing to the specified output stream failed.

exportSettings

public void exportSettings(java.io.OutputStream out,
                           java.lang.String extension)
                    throws java.io.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:
java.io.IOException - if an I/O error occured.
java.lang.IllegalArgumentException - if extension is no valid file extension.

flush

public void flush()
           throws java.io.IOException
Flushes the code convention to the persistent store.

Throws:
java.io.IOException - if an I/O error occured.

get

public java.lang.String get(Convention.Key key,
                            java.lang.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:
java.lang.NullPointerException - if key is null. (A null default is permitted.)

put

public void put(Convention.Key key,
                java.lang.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:
java.lang.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 java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object.


Copyright © 1997-2005 Jalopy. All Rights Reserved.