FileDocCategorySizeDatePackage
GenericCfg.javaAPI DocAndroid 1.5 API5094Wed May 06 22:41:16 BST 2009com.vladium.emma.ant

GenericCfg

public class GenericCfg extends Object
GenericCfg is a simple container for 'generic' properties, i.e., properties that are set via generic 'properties=<file>' attribute and <property> nested elements. This class makes no decision about relative priorities for propertie set in an external file or via nested elements, leaving this up to the parent.
author
Vlad Roubtsov, (C) 2003

Fields Summary
private final org.apache.tools.ant.Task
m_task
private final List
m_genericPropertyElements
private File
m_settingsFile
private transient com.vladium.util.IProperties
m_fileSettings
private transient com.vladium.util.IProperties
m_genericSettings
Constructors Summary
public GenericCfg(org.apache.tools.ant.Task task)

        if (task == null) throw new IllegalArgumentException ("null input: task");
        
        m_task = task;
        m_genericPropertyElements = new ArrayList ();
    
Methods Summary
public PropertyElementcreateProperty()

        m_genericSettings = null;
        
        final PropertyElement property = new PropertyElement ();
        m_genericPropertyElements.add (property);
        
        return property;
    
public com.vladium.util.IPropertiesgetFileSettings()

        IProperties fileSettings = m_fileSettings;
        if ((fileSettings == null) && (m_settingsFile != null))
        {
            try
            {
                fileSettings = EMMAProperties.wrap (Property.getPropertiesFromFile (m_settingsFile));
            }
            catch (IOException ioe)
            {
                throw (BuildException) SuppressableTask.newBuildException (m_task.getTaskName ()
                    + ": property file [" + m_settingsFile.getAbsolutePath () + "] could not be read" , ioe, m_task.getLocation ()).fillInStackTrace ();
            }
            
            m_fileSettings = fileSettings;
            
            return fileSettings;
        }
        
        return fileSettings;
    
public com.vladium.util.IPropertiesgetGenericSettings()

        IProperties genericSettings = m_genericSettings;
        if (genericSettings == null)
        {
            genericSettings = EMMAProperties.wrap (new Properties ());
            
            for (Iterator i = m_genericPropertyElements.iterator (); i.hasNext (); )
            {
                final PropertyElement property = (PropertyElement) i.next ();
                
                final String name = property.getName ();
                String value = property.getValue ();
                if (value == null) value = "";
                
                if (name != null)
                {
                    // [assertion: name != null, value != null]
                    
                    final String currentValue = genericSettings.getProperty (name);  
                    if ((currentValue != null) && ! value.equals (currentValue))
                    {
                        throw (BuildException) SuppressableTask.newBuildException (m_task.getTaskName ()
                            + ": conflicting settings for property [" + name + "]: [" + value + "]" , m_task.getLocation ()).fillInStackTrace ();
                    }
                    else
                    {
                        genericSettings.setProperty (name, value);
                    }
                }
            }
            
            m_genericSettings = genericSettings;
            
            return genericSettings;
        }
        
        return genericSettings;
    
public voidsetProperties(java.io.File file)

        m_settingsFile = file; // actual file I/O is done in getFileSettings()