com.android.sdklib.internal.repository.sources
Class SdkSourceProperties

java.lang.Object
  extended by com.android.sdklib.internal.repository.sources.SdkSourceProperties

public class SdkSourceProperties
extends java.lang.Object

Properties for individual sources which are persisted by a local settings file.

All instances of SdkSourceProperties share the same singleton storage. The persisted setting file is loaded as necessary, however callers must persist it at some point by calling save().


Field Summary
static java.lang.String KEY_DISABLED
          A non-null string if the source is disabled.
static java.lang.String KEY_NAME
          The last known UI name of the source.
 
Constructor Summary
SdkSourceProperties()
           
 
Method Summary
protected  void clear()
          Empty current property list.
 java.lang.String getProperty(java.lang.String key, java.lang.String sourceUrl, java.lang.String defaultValue)
          Retrieves a property for the given source URL and the given key type.
protected  boolean loadProperties()
          Load properties from default file.
 void save()
           
protected  void saveLocked()
          Save file to disk.
 void setProperty(java.lang.String key, java.lang.String sourceUrl, java.lang.String value)
          Sets or remove a property for the given source URL and the given key type.
 java.lang.String toString()
          Returns an internal string representation of the underlying Properties map, sorted by ascending keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_NAME

public static final java.lang.String KEY_NAME
The last known UI name of the source.

See Also:
Constant Field Values

KEY_DISABLED

public static final java.lang.String KEY_DISABLED
A non-null string if the source is disabled. Null if the source is enabled.

See Also:
Constant Field Values
Constructor Detail

SdkSourceProperties

public SdkSourceProperties()
Method Detail

save

public void save()

getProperty

@Nullable
public java.lang.String getProperty(@NonNull
                                             java.lang.String key,
                                             @NonNull
                                             java.lang.String sourceUrl,
                                             @Nullable
                                             java.lang.String defaultValue)
Retrieves a property for the given source URL and the given key type.

Implementation detail: this loads the persistent settings file as needed.

Parameters:
key - The kind of property to retrieve for that source URL.
sourceUrl - The source URL.
defaultValue - The default value to return, if the property isn't found. Can be null.
Returns:
The non-null string property for the key/sourceUrl or the default value.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String sourceUrl,
                        java.lang.String value)
Sets or remove a property for the given source URL and the given key type.

Implementation detail: this does not save the persistent settings file. Somehow the caller will need to call the save() method later.

Parameters:
key - The kind of property to retrieve for that source URL.
sourceUrl - The source URL.
value - The new value to set (if non null) or null to remove an existing property.

toString

public java.lang.String toString()
Returns an internal string representation of the underlying Properties map, sorted by ascending keys. Useful for debugging and testing purposes only.

Overrides:
toString in class java.lang.Object

loadProperties

protected boolean loadProperties()
Load properties from default file. Extracted so that it can be mocked in tests.

Returns:
True if actually loaded the file. False if there was an IO error or no file and nothing was loaded.

saveLocked

protected void saveLocked()
Save file to disk. Expects sSourcesProperties to be synchronized. Made accessible for testing purposes. For public usage, please use save() instead.


clear

protected void clear()
Empty current property list. Made accessible for testing purposes.