Java Doc for AbstractFileConfiguration.java in  » Library » Apache-commons-configuration-1.4-src » org » apache » commons » configuration » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons configuration 1.4 src » org.apache.commons.configuration 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.apache.commons.configuration.AbstractConfiguration
   org.apache.commons.configuration.BaseConfiguration
      org.apache.commons.configuration.AbstractFileConfiguration

All known Subclasses:   org.apache.commons.configuration.INIConfiguration,  org.apache.commons.configuration.PropertiesConfiguration,
AbstractFileConfiguration
abstract public class AbstractFileConfiguration extends BaseConfiguration implements FileConfiguration(Code)

Partial implementation of the FileConfiguration interface. Developpers of file based configuration may want to extend this class, the two methods left to implement are FileConfiguration.load(Reader) and FileConfiguration.save(Writer) .

This base class already implements a couple of ways to specify the location of the file this configuration is based on. The following possibilities exist:

  • URLs: With the method setURL() a full URL to the configuration source can be specified. This is the most flexible way. Note that the save() methods support only file: URLs.
  • Files: The setFile() method allows to specify the configuration source as a file. This can be either a relative or an absolute file. In the former case the file is resolved based on the current directory.
  • As file paths in string form: With the setPath() method a full path to a configuration file can be provided as a string.
  • Separated as base path and file name: This is the native form in which the location is stored. The base path is a string defining either a local directory or a URL. It can be set using the setBasePath() method. The file name, non surprisingly, defines the name of the configuration file.

Note that the load() methods do not wipe out the configuration's content before the new configuration file is loaded. Thus it is very easy to construct a union configuration by simply loading multiple configuration files, e.g.

 config.load(configFile1);
 config.load(configFile2);
 

After executing this code fragment, the resulting configuration will contain both the properties of configFile1 and configFile2. On the other hand, if the current configuration file is to be reloaded, clear() should be called first. Otherwise the properties are doubled. This behavior is analogous to the behavior of the load(InputStream) method in java.util.Properties.


author:
   Emmanuel Bourg
version:
   $Revision: 497574 $, $Date: 2007-01-18 22:02:55 +0100 (Do, 18 Jan 2007) $
since:
   1.0-rc2


Field Summary
final public static  intEVENT_RELOAD
     Constant for the configuration reload event.
protected  booleanautoSave
     The auto save flag.
protected  StringbasePath
     Stores the base path.
protected  StringfileName
     Stores the file name.
protected  ReloadingStrategystrategy
     Holds a reference to the reloading strategy.

Constructor Summary
public  AbstractFileConfiguration()
    
public  AbstractFileConfiguration(String fileName)
     Creates and loads the configuration from the specified file.
public  AbstractFileConfiguration(File file)
     Creates and loads the configuration from the specified file.
public  AbstractFileConfiguration(URL url)
     Creates and loads the configuration from the specified URL.

Method Summary
public  voidaddProperty(String key, Object value)
     Adds a new property to this configuration.
public  voidclearProperty(String key)
    
public  Objectclone()
     Creates a copy of this configuration.
public  booleancontainsKey(String key)
    
protected  voidenterNoReload()
     Enters the "No reloading mode".
protected  voidexitNoReload()
     Leaves the "No reloading mode".
protected  voidfireEvent(int type, String propName, Object propValue, boolean before)
     Sends an event to all registered listeners.
public  StringgetBasePath()
     Return the base path.
public  StringgetEncoding()
    
public  FilegetFile()
     Return the file where the configuration is stored.
public  StringgetFileName()
     Return the name of the file.
public  IteratorgetKeys()
    
public  StringgetPath()
     Returns the full path to the file this configuration is based on.
public  ObjectgetProperty(String key)
    
public  ReloadingStrategygetReloadingStrategy()
    
public  URLgetURL()
     Return the URL where the configuration is stored.
public  booleanisAutoSave()
    
public  booleanisEmpty()
    
public  voidload()
     Load the configuration from the underlying location.
public  voidload(String fileName)
     Locate the specified file and load the configuration.
public  voidload(File file)
     Load the configuration from the specified file.
public  voidload(URL url)
     Load the configuration from the specified URL.
public  voidload(InputStream in)
     Load the configuration from the specified stream, using the encoding returned by AbstractFileConfiguration.getEncoding() .
public  voidload(InputStream in, String encoding)
     Load the configuration from the specified stream, using the specified encoding.
protected  voidpossiblySave()
     Save the configuration if the automatic persistence is enabled and if a file is specified.
public  voidreload()
     Performs a reload operation if necessary.
public  voidsave()
     Save the configuration.
public  voidsave(String fileName)
     Save the configuration to the specified file.
public  voidsave(URL url)
     Save the configuration to the specified URL if it's a file URL.
public  voidsave(File file)
     Save the configuration to the specified file.
public  voidsave(OutputStream out)
     Save the configuration to the specified stream, using the encoding returned by AbstractFileConfiguration.getEncoding() .
public  voidsave(OutputStream out, String encoding)
     Save the configuration to the specified stream, using the specified encoding.
public  voidsetAutoSave(boolean autoSave)
    
public  voidsetBasePath(String basePath)
     Sets the base path.
public  voidsetEncoding(String encoding)
    
public  voidsetFile(File file)
     Set the file where the configuration is stored.
public  voidsetFileName(String fileName)
     Set the name of the file.
public  voidsetPath(String path)
     Sets the location of this configuration as a full or relative path name.
public  voidsetProperty(String key, Object value)
     Sets a new value for the specified property.
public  voidsetReloadingStrategy(ReloadingStrategy strategy)
    
public  voidsetURL(URL url)
     Set the location of this configuration as a URL.

Field Detail
EVENT_RELOAD
final public static int EVENT_RELOAD(Code)
Constant for the configuration reload event.



autoSave
protected boolean autoSave(Code)
The auto save flag.



basePath
protected String basePath(Code)
Stores the base path.



fileName
protected String fileName(Code)
Stores the file name.



strategy
protected ReloadingStrategy strategy(Code)
Holds a reference to the reloading strategy.




Constructor Detail
AbstractFileConfiguration
public AbstractFileConfiguration()(Code)
Default constructor
since:
   1.1



AbstractFileConfiguration
public AbstractFileConfiguration(String fileName) throws ConfigurationException(Code)
Creates and loads the configuration from the specified file. The passed in string must be a valid file name, either absolute or relativ.
Parameters:
  fileName - The name of the file to load.
throws:
  ConfigurationException - Error while loading the file
since:
   1.1



AbstractFileConfiguration
public AbstractFileConfiguration(File file) throws ConfigurationException(Code)
Creates and loads the configuration from the specified file.
Parameters:
  file - The file to load.
throws:
  ConfigurationException - Error while loading the file
since:
   1.1



AbstractFileConfiguration
public AbstractFileConfiguration(URL url) throws ConfigurationException(Code)
Creates and loads the configuration from the specified URL.
Parameters:
  url - The location of the file to load.
throws:
  ConfigurationException - Error while loading the file
since:
   1.1




Method Detail
addProperty
public void addProperty(String key, Object value)(Code)
Adds a new property to this configuration. This implementation checks if the auto save mode is enabled and saves the configuration if necessary.
Parameters:
  key - the key of the new property
Parameters:
  value - the value



clearProperty
public void clearProperty(String key)(Code)



clone
public Object clone()(Code)
Creates a copy of this configuration. The new configuration object will contain the same properties as the original, but it will lose any connection to a source file (if one exists); this includes setting the source URL, base path, and file name to null. This is done to avoid race conditions if both the original and the copy are modified and then saved. the copy
since:
   1.3



containsKey
public boolean containsKey(String key)(Code)



enterNoReload
protected void enterNoReload()(Code)
Enters the "No reloading mode". As long as this mode is active no reloading will be performed. This is necessary for some implementations of save() in derived classes, which may cause a reload while accessing the properties to save. This may cause the whole configuration to be erased. To avoid this, this method can be called first. After a call to this method there always must be a corresponding call of AbstractFileConfiguration.exitNoReload() later! (If necessary, finally blocks must be used to ensure this.



exitNoReload
protected void exitNoReload()(Code)
Leaves the "No reloading mode".
See Also:   AbstractFileConfiguration.enterNoReload()



fireEvent
protected void fireEvent(int type, String propName, Object propValue, boolean before)(Code)
Sends an event to all registered listeners. This implementation ensures that no reloads are performed while the listeners are invoked. So infinite loops can be avoided that can be caused by event listeners accessing the configuration's properties when they are invoked.
Parameters:
  type - the event type
Parameters:
  propName - the name of the property
Parameters:
  propValue - the value of the property
Parameters:
  before - the before update flag



getBasePath
public String getBasePath()(Code)
Return the base path. the base path
See Also:   FileConfiguration.getBasePath



getEncoding
public String getEncoding()(Code)



getFile
public File getFile()(Code)
Return the file where the configuration is stored. If the base path is a URL with a protocol different than "file", or the configuration file is within a compressed archive, the return value will not point to a valid file object. the file where the configuration is stored; this can be null



getFileName
public String getFileName()(Code)
Return the name of the file. the file name



getKeys
public Iterator getKeys()(Code)



getPath
public String getPath()(Code)
Returns the full path to the file this configuration is based on. The return value is a valid File path only if this configuration is based on a file on the local disk. If the configuration was loaded from a packed archive the returned value is the string form of the URL from which the configuration was loaded. the full path to the configuration file



getProperty
public Object getProperty(String key)(Code)



getReloadingStrategy
public ReloadingStrategy getReloadingStrategy()(Code)



getURL
public URL getURL()(Code)
Return the URL where the configuration is stored. the configuration's location as URL



isAutoSave
public boolean isAutoSave()(Code)



isEmpty
public boolean isEmpty()(Code)



load
public void load() throws ConfigurationException(Code)
Load the configuration from the underlying location.
throws:
  ConfigurationException - if loading of the configuration fails



load
public void load(String fileName) throws ConfigurationException(Code)
Locate the specified file and load the configuration. This does not change the source of the configuration (i.e. the internally maintained file name). Use one of the setter methods for this purpose.
Parameters:
  fileName - the name of the file to be loaded
throws:
  ConfigurationException - if an error occurs



load
public void load(File file) throws ConfigurationException(Code)
Load the configuration from the specified file. This does not change the source of the configuration (i.e. the internally maintained file name). Use one of the setter methods for this purpose.
Parameters:
  file - the file to load
throws:
  ConfigurationException - if an error occurs



load
public void load(URL url) throws ConfigurationException(Code)
Load the configuration from the specified URL. This does not change the source of the configuration (i.e. the internally maintained file name). Use on of the setter methods for this purpose.
Parameters:
  url - the URL of the file to be loaded
throws:
  ConfigurationException - if an error occurs



load
public void load(InputStream in) throws ConfigurationException(Code)
Load the configuration from the specified stream, using the encoding returned by AbstractFileConfiguration.getEncoding() .
Parameters:
  in - the input stream
throws:
  ConfigurationException - if an error occurs during the load operation



load
public void load(InputStream in, String encoding) throws ConfigurationException(Code)
Load the configuration from the specified stream, using the specified encoding. If the encoding is null the default encoding is used.
Parameters:
  in - the input stream
Parameters:
  encoding - the encoding used. null to use the default encoding
throws:
  ConfigurationException - if an error occurs during the load operation



possiblySave
protected void possiblySave()(Code)
Save the configuration if the automatic persistence is enabled and if a file is specified.



reload
public void reload()(Code)
Performs a reload operation if necessary. This method is called on each access of this configuration. It asks the associated reloading strategy whether a reload should be performed. If this is the case, the configuration is cleared and loaded again from its source. If this operation causes an exception, the registered error listeners will be notified. The error event passed to the listeners is of type EVENT_RELOAD and contains the exception that caused the event.



save
public void save() throws ConfigurationException(Code)
Save the configuration. Before this method can be called a valid file name must have been set.
throws:
  ConfigurationException - if an error occurs or no file name hasbeen set yet



save
public void save(String fileName) throws ConfigurationException(Code)
Save the configuration to the specified file. This doesn't change the source of the configuration, use setFileName() if you need it.
Parameters:
  fileName - the file name
throws:
  ConfigurationException - if an error occurs during the save operation



save
public void save(URL url) throws ConfigurationException(Code)
Save the configuration to the specified URL if it's a file URL. This doesn't change the source of the configuration, use setURL() if you need it.
Parameters:
  url - the URL
throws:
  ConfigurationException - if an error occurs during the save operation



save
public void save(File file) throws ConfigurationException(Code)
Save the configuration to the specified file. The file is created automatically if it doesn't exist. This doesn't change the source of the configuration, use AbstractFileConfiguration.setFile if you need it.
Parameters:
  file - the target file
throws:
  ConfigurationException - if an error occurs during the save operation



save
public void save(OutputStream out) throws ConfigurationException(Code)
Save the configuration to the specified stream, using the encoding returned by AbstractFileConfiguration.getEncoding() .
Parameters:
  out - the output stream
throws:
  ConfigurationException - if an error occurs during the save operation



save
public void save(OutputStream out, String encoding) throws ConfigurationException(Code)
Save the configuration to the specified stream, using the specified encoding. If the encoding is null the default encoding is used.
Parameters:
  out - the output stream
Parameters:
  encoding - the encoding to use
throws:
  ConfigurationException - if an error occurs during the save operation



setAutoSave
public void setAutoSave(boolean autoSave)(Code)



setBasePath
public void setBasePath(String basePath)(Code)
Sets the base path. The base path is typically either a path to a directory or a URL. Together with the value passed to the setFileName() method it defines the location of the configuration file to be loaded. The strategies for locating the file are quite tolerant. For instance if the file name is already an absolute path or a fully defined URL, the base path will be ignored. The base path can also be a URL, in which case the file name is interpreted in this URL's context. Because the base path is used by some of the derived classes for resolving relative file names it should contain a meaningful value. If other methods are used for determining the location of the configuration file (e.g. setFile() or setURL()), the base path is automatically set.
Parameters:
  basePath - the base path.



setEncoding
public void setEncoding(String encoding)(Code)



setFile
public void setFile(File file)(Code)
Set the file where the configuration is stored. The passed in file is made absolute if it is not yet. Then the file's path component becomes the base path and its name component becomes the file name.
Parameters:
  file - the file where the configuration is stored



setFileName
public void setFileName(String fileName)(Code)
Set the name of the file. The passed in file name can contain a relative path. It must be used when referring files with relative paths from classpath. Use AbstractFileConfiguration.setPath(String)setPath() to set a full qualified file name.
Parameters:
  fileName - the name of the file



setPath
public void setPath(String path)(Code)
Sets the location of this configuration as a full or relative path name. The passed in path should represent a valid file name on the file system. It must not be used to specify relative paths for files that exist in classpath, either plain file system or compressed archive, because this method expands any relative path to an absolute one which may end in an invalid absolute path for classpath references.
Parameters:
  path - the full path name of the configuration file



setProperty
public void setProperty(String key, Object value)(Code)
Sets a new value for the specified property. This implementation checks if the auto save mode is enabled and saves the configuration if necessary.
Parameters:
  key - the key of the affected property
Parameters:
  value - the value



setReloadingStrategy
public void setReloadingStrategy(ReloadingStrategy strategy)(Code)



setURL
public void setURL(URL url)(Code)
Set the location of this configuration as a URL. For loading this can be an arbitrary URL with a supported protocol. If the configuration is to be saved, too, a URL with the "file" protocol should be provided.
Parameters:
  url - the location of this configuration as URL



Methods inherited from org.apache.commons.configuration.BaseConfiguration
protected void addPropertyDirect(String key, Object value)(Code)(Java Doc)
public void clear()(Code)(Java Doc)
protected void clearPropertyDirect(String key)(Code)(Java Doc)
public Object clone()(Code)(Java Doc)
public boolean containsKey(String key)(Code)(Java Doc)
public Iterator getKeys()(Code)(Java Doc)
public Object getProperty(String key)(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)

Fields inherited from org.apache.commons.configuration.AbstractConfiguration
final protected static String END_TOKEN(Code)(Java Doc)
final public static int EVENT_ADD_PROPERTY(Code)(Java Doc)
final public static int EVENT_CLEAR(Code)(Java Doc)
final public static int EVENT_CLEAR_PROPERTY(Code)(Java Doc)
final public static int EVENT_READ_PROPERTY(Code)(Java Doc)
final public static int EVENT_SET_PROPERTY(Code)(Java Doc)
final protected static String START_TOKEN(Code)(Java Doc)

Methods inherited from org.apache.commons.configuration.AbstractConfiguration
public void addErrorLogListener()(Code)(Java Doc)
public void addProperty(String key, Object value)(Code)(Java Doc)
abstract protected void addPropertyDirect(String key, Object value)(Code)(Java Doc)
public void clear()(Code)(Java Doc)
public void clearProperty(String key)(Code)(Java Doc)
protected void clearPropertyDirect(String key)(Code)(Java Doc)
abstract public boolean containsKey(String key)(Code)(Java Doc)
protected ConfigurationInterpolator createInterpolator()(Code)(Java Doc)
public BigDecimal getBigDecimal(String key)(Code)(Java Doc)
public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)(Code)(Java Doc)
public BigInteger getBigInteger(String key)(Code)(Java Doc)
public BigInteger getBigInteger(String key, BigInteger defaultValue)(Code)(Java Doc)
public boolean getBoolean(String key)(Code)(Java Doc)
public boolean getBoolean(String key, boolean defaultValue)(Code)(Java Doc)
public Boolean getBoolean(String key, Boolean defaultValue)(Code)(Java Doc)
public byte getByte(String key)(Code)(Java Doc)
public byte getByte(String key, byte defaultValue)(Code)(Java Doc)
public Byte getByte(String key, Byte defaultValue)(Code)(Java Doc)
public static char getDefaultListDelimiter()(Code)(Java Doc)
public static char getDelimiter()(Code)(Java Doc)
public double getDouble(String key)(Code)(Java Doc)
public double getDouble(String key, double defaultValue)(Code)(Java Doc)
public Double getDouble(String key, Double defaultValue)(Code)(Java Doc)
public float getFloat(String key)(Code)(Java Doc)
public float getFloat(String key, float defaultValue)(Code)(Java Doc)
public Float getFloat(String key, Float defaultValue)(Code)(Java Doc)
public int getInt(String key)(Code)(Java Doc)
public int getInt(String key, int defaultValue)(Code)(Java Doc)
public Integer getInteger(String key, Integer defaultValue)(Code)(Java Doc)
public ConfigurationInterpolator getInterpolator()(Code)(Java Doc)
abstract public Iterator getKeys()(Code)(Java Doc)
public Iterator getKeys(String prefix)(Code)(Java Doc)
public List getList(String key)(Code)(Java Doc)
public List getList(String key, List defaultValue)(Code)(Java Doc)
public char getListDelimiter()(Code)(Java Doc)
public Log getLogger()(Code)(Java Doc)
public long getLong(String key)(Code)(Java Doc)
public long getLong(String key, long defaultValue)(Code)(Java Doc)
public Long getLong(String key, Long defaultValue)(Code)(Java Doc)
public Properties getProperties(String key)(Code)(Java Doc)
public Properties getProperties(String key, Properties defaults)(Code)(Java Doc)
public short getShort(String key)(Code)(Java Doc)
public short getShort(String key, short defaultValue)(Code)(Java Doc)
public Short getShort(String key, Short defaultValue)(Code)(Java Doc)
public String getString(String key)(Code)(Java Doc)
public String getString(String key, String defaultValue)(Code)(Java Doc)
public String[] getStringArray(String key)(Code)(Java Doc)
public synchronized StrSubstitutor getSubstitutor()(Code)(Java Doc)
protected String interpolate(String base)(Code)(Java Doc)
protected Object interpolate(Object value)(Code)(Java Doc)
protected String interpolateHelper(String base, List priorVariables)(Code)(Java Doc)
public boolean isDelimiterParsingDisabled()(Code)(Java Doc)
abstract public boolean isEmpty()(Code)(Java Doc)
public boolean isThrowExceptionOnMissing()(Code)(Java Doc)
protected Object resolveContainerStore(String key)(Code)(Java Doc)
public static void setDefaultListDelimiter(char delimiter)(Code)(Java Doc)
public static void setDelimiter(char delimiter)(Code)(Java Doc)
public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)(Code)(Java Doc)
public void setListDelimiter(char listDelimiter)(Code)(Java Doc)
public void setLogger(Log log)(Code)(Java Doc)
public void setProperty(String key, Object value)(Code)(Java Doc)
public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)(Code)(Java Doc)
public Configuration subset(String prefix)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.