Skip navigation links
_templates.javolution.lang

Class Configurable

    • Constructor Detail

      • Configurable

        public Configurable(Object defaultValue)
        Creates a new configurable having the specified default value.
        Parameters:
        defaultValue - the default value.
        Throws:
        IllegalArgumentException - if defaultValue is null.
    • Method Detail

      • get

        public Object get()
        Returns the current value for this configurable.
        Returns:
        the current value (always different from null).
      • getDefault

        public Object getDefault()
        Returns the default value for this configurable.
        Returns:
        the default value (always different from null).
      • getContainer

        public Class getContainer()
        Returns the container class of this configurable (the class where this configurable is defined as a public static field.
        Returns:
        the container class or null if unknown (e.g. J2ME).
      • getName

        public String getName()
        Returns the field name of this configurable (for example "javolution.context.ConcurrentContext#MAXIMUM_CONCURRENCY") for ConcurrentContext.MAXIMUM_CONCURRENCY.
        Returns:
        this configurable name or null if the name of this configurable is unknown (e.g. J2ME).
      • toString

        public String toString()
        Returns the string representation of the value of this configurable.
        Overrides:
        toString in class Object
        Returns:
        String.valueOf(this.get())
      • getInstance

        public static Configurable getInstance(String name)
        Returns the configurable instance having the specified name. For example:[code] Configurable cfg = Configurable.getInstance("javolution.context.ConcurrentContext#MAXIMUM_CONCURRENCY") [/code] returns ConcurrentContext.MAXIMUM_CONCURRENCY.

        Note: OSGI based framework should ensure that class loaders of configurable instances are known to the Reflection utility class.

        Parameters:
        name - the name of the configurable to retrieve.
        Returns:
        the corresponding configurable or null if it cannot be found.
      • read

        public static void read(Properties properties)
        Convenience method to read the specified properties and reconfigure accordingly. For example:[code] // Load configurables from system properties. Configurable.read(System.getProperties());[/code] Configurables are identified by their field names. The textual representation of their value is defined by TextFormat.getInstance(Class) text format}. For example:[code] javolution.util.FastComparator#REHASH_SYSTEM_HASHCODE = true javolution.context.ConcurrentContext#MAXIMUM_CONCURRENCY = 0 javolution.xml.stream.XMLInputFactory#CLASS = com.foo.bar.XMLInputFactoryImpl [/code] Conversion of String values to actual object is performed using TextFormat.getInstance(Class).

        Note: OSGI based framework should ensure that class loaders of configurable instances are known to the Reflection utility class.

        Parameters:
        properties - the properties.
      • read

        public static void read(InputStream inputStream)
        Convenience method to read configurable values from the specified XML stream. This method uses Javolution XML facility to perform the deserialization. Here is an example of XML configuration file.[code] [/code] It can be read directly with the following code:[code] FileInputStream xml = new FileInputStream("D:/configuration.xml"); Configurable.read(xml);[/code]

        Note: OSGI based framework should ensure that class loaders of configurable instances are known to the Reflection utility.

        Parameters:
        inputStream - the input stream holding the xml configuration.

Copyright © 2005–2015 Javolution. All rights reserved.