|
org.netbeans.modules.registry/1 1.8 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.netbeans.api.registry.Context
public final class Context
This API class is representing a context which consists of a set of name-to-object bindings. It contains methods for examining and updating these bindings. The contexts are composed into hierarchical collection which form configuration system. The configuration system allows applicatioRootns to store and retrieve data. How data are stored is not specified by the Registry API. It is up to provided implementation of Registry SPI to properly document it and that documentation must be consulted.
The hierarchical collection of contexts is similar to folders in a hierarchical file system. There exist a root context containing all the contexts. The name of this context is "/" and it is also absolute name of the context. The names of individual contexts cannot be empty, but does not have to be unique. However, absolute name of the context must be unique. Children of the root context have absolute names of "/" + context name. All other contexts have absolute names of parent's context absolute name + "/" + context name.
The context can contain the subcontext and binding with the same name and they will coexist.
The context has getters and setters for all primitive data types, for a few basic object types (eg. Color, URL, etc.) and for Object. As was said above the storage format is specific per Registry SPI implementation, but following is valid for all backends:
Getters do not throw exceptions. They accept default value parameter which is returned if value does not exist or it could not be read. The exceptions are logged.
Putting null value removes the binding.
Rename of binding is not supported because no useful usecase was found.
All methods are properly synchronized and can be accessed from multiple threads without any synchronization on the client side. During the modification is whole hierarchy of contexts exclusively locked.
TBD: Names restrictions: length, valid characters, etc. The context name nor binding name cannot contain "/" character.
Method Summary | |
---|---|
void |
addContextListener(ContextListener l)
Add listener for receiving events about context and all its descendant subcontexts changes. |
Context |
createSubcontext(String subcontextName)
Create subcontext of the given name. |
void |
destroySubcontext(String subcontextName)
Destroy subcontext of the given name. |
String |
getAbsoluteContextName()
Getter for the absolute name of the context, eg. |
String |
getAttribute(String bindingName,
String attributeName,
String defaultValue)
Retrieve value of the attribute. |
Collection |
getAttributeNames(String bindingName)
Retrieve names of all attributes in this context. |
Collection |
getBindingNames()
Retrieve names of all bindings in this context. |
boolean |
getBoolean(String bindingName,
boolean defaultValue)
Retrieve boolean value. |
Color |
getColor(String bindingName,
Color defaultValue)
Retrieve color value. |
String |
getContextName()
Name of the context. |
static Context |
getDefault()
Getter for default instance of registry. |
double |
getDouble(String bindingName,
double defaultValue)
Retrieve double value. |
float |
getFloat(String bindingName,
float defaultValue)
Retrieve float value. |
Font |
getFont(String bindingName,
Font defaultValue)
Retrieve font value. |
int |
getInt(String bindingName,
int defaultValue)
Retrieve integer value. |
long |
getLong(String bindingName,
long defaultValue)
Retrieve long value. |
static Mutex |
getMutex()
Shared Mutex on which all contexts are synchronized. |
Object |
getObject(String bindingName,
Object defaultValue)
Retrieve named object from the context. |
List |
getOrderedNames()
Method listing ordered names of the context items. |
List |
getOrderedObjects()
Method for listing items of the context ordered. |
Context |
getParentContext()
Retrieve parent context. |
ObjectRef |
getRef(String bindingName)
Retrieve directly the bounded ObjectRef instance. |
Context |
getRootContext()
Gets root context. |
String |
getString(String bindingName,
String defaultValue)
Retrieve String value. |
String[] |
getStringArray(String bindingName,
char separator,
String[] defaultValue)
Retrieve string array by reading stored string and splitting it by the given separator into array of Strings. |
Context |
getSubcontext(String subcontextName)
Retrieve subcontext of the given name. |
Collection |
getSubcontextNames()
Retrieve names of all subcontexts of this context. |
URL |
getURL(String bindingName,
URL defaultValue)
Retrieve URL value. |
boolean |
hasDefault(String bindingName)
Exist a default value for this binding or context? |
boolean |
isModified(String bindingName)
Check whether the value of this binding or context is modified. |
static Context |
merge(Context[] delegates)
Returns context, that merges all its delegates. |
void |
orderContext(List names)
Store full order of the context content. |
void |
putBoolean(String bindingName,
boolean value)
This method converts the passed boolean to Boolean object and binds it into context. |
void |
putColor(String bindingName,
Color value)
This is just convenient method. |
void |
putDouble(String bindingName,
double value)
This method converts the passed double to Double object and binds it into context. |
void |
putFloat(String bindingName,
float value)
This method converts the passed float to Float object and binds it into context. |
void |
putFont(String bindingName,
Font value)
This is just convenient method. |
void |
putInt(String bindingName,
int value)
This method converts the passed integer to Integer object and binds it into context. |
void |
putLong(String bindingName,
long value)
This method converts the passed long to Long object and binds it into context. |
void |
putObject(String bindingName,
Object value)
Binds a name to an object and store the object in context. |
void |
putString(String bindingName,
String value)
Binds a name to the String and store it in the context. |
void |
putStringArray(String bindingName,
char separator,
String[] value)
Store array of strings. |
void |
putURL(String bindingName,
URL value)
This is just convenient method. |
void |
removeContextListener(ContextListener l)
Remove listener for receiving events about context and all its descendant subcontexts changes. |
void |
revert(String bindingName)
Revert modification of this binding or context. |
void |
setAttribute(String bindingName,
String attributeName,
String value)
Modify value of the attribute. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static Context getDefault()
Application specific documentation must be consulted to learn which exact implementation will be returned by this method. For example for NetBeans it can be implementation working on top of the root of SystemFileSystem.
public static Context merge(Context[] delegates)
delegates
- array of contexts that should be merged
public String getContextName()
public Context getRootContext()
public String getAbsoluteContextName()
public Context getSubcontext(String subcontextName)
subcontextName
- multi-level subcontext name to retrieve
public Context getParentContext()
public Context createSubcontext(String subcontextName) throws ContextException
subcontextName
- multi-level subcontext name to create
ContextException
- thrown when subcontext cannot be createdpublic void destroySubcontext(String subcontextName) throws ContextException
subcontextName
- multi-level name of existing subcontext
ContextException
- thrown when subcontext cannot be deletedpublic Collection getSubcontextNames()
public Collection getBindingNames()
public Collection getAttributeNames(String bindingName)
public void orderContext(List names)
names
- full order of the objects in the context; see above for
expected values in the listpublic List getOrderedObjects()
See Javadoc overview for how the context items are sorted.
If context content was ordered by orderContext(java.util.List)
method
then the items will be listed in this order (order of items which were
not specified in the full order is undefined).
public List getOrderedNames()
See the JavaDoc for getOrderedObjects()
method for
more details about ordering itself.
public Object getObject(String bindingName, Object defaultValue)
If retrieved object is instance of ObjectRef
it is recursively
dereferenced and the value of ObjectRef instance if returned instead.
If dereferenced value is null or ObjectRef is invalid then the ObjectRef
instance is returned. See getRef(java.lang.String)
if you need to retrieve
ObjectRef directly.
bindingName
- the name of the object to retrieve; cannot be emptydefaultValue
- default value returned in case the binding does not
exist.
public ObjectRef getRef(String bindingName)
getObject(java.lang.String, java.lang.Object)
does recursive traversal of ObjectRef and returns directly the referenced value.
bindingName
- the name of the object to retrieve; cannot be empty
public void putObject(String bindingName, Object value)
See class overview JavaDoc for more details about how the objects are stored and which object types are supported.
bindingName
- the name to bind; cannot be emptyvalue
- the object to bind; null is allowed and means
deletion of the bindingpublic String getString(String bindingName, String defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putString(String bindingName, String value)
bindingName
- binding namevalue
- valuepublic int getInt(String bindingName, int defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putInt(String bindingName, int value)
putObject(java.lang.String, java.lang.Object)
with null value to remove binding.
bindingName
- binding namevalue
- valuepublic long getLong(String bindingName, long defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putLong(String bindingName, long value)
putObject(java.lang.String, java.lang.Object)
with null value to remove binding.
bindingName
- binding namevalue
- valuepublic boolean getBoolean(String bindingName, boolean defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putBoolean(String bindingName, boolean value)
putObject(java.lang.String, java.lang.Object)
with null value to remove binding.
bindingName
- binding namevalue
- valuepublic float getFloat(String bindingName, float defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putFloat(String bindingName, float value)
putObject(java.lang.String, java.lang.Object)
with null value to remove binding.
bindingName
- binding namevalue
- valuepublic double getDouble(String bindingName, double defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putDouble(String bindingName, double value)
putObject(java.lang.String, java.lang.Object)
with null value to remove binding.
bindingName
- binding namevalue
- valuepublic Font getFont(String bindingName, Font defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putFont(String bindingName, Font value)
putObject(java.lang.String, java.lang.Object)
. Use null value to remove binding.
bindingName
- binding namevalue
- valuepublic Color getColor(String bindingName, Color defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putColor(String bindingName, Color value)
putObject(java.lang.String, java.lang.Object)
. Use null value to remove binding.
bindingName
- binding namevalue
- valuepublic URL getURL(String bindingName, URL defaultValue)
bindingName
- binding namedefaultValue
- default value returned if this binding does not exist
public void putURL(String bindingName, URL value)
putObject(java.lang.String, java.lang.Object)
. Use null value to remove binding.
bindingName
- binding namevalue
- valuepublic String[] getStringArray(String bindingName, char separator, String[] defaultValue)
bindingName
- binding nameseparator
- separtor characterdefaultValue
- default value returned if this binding does not exist
public void putStringArray(String bindingName, char separator, String[] value)
bindingName
- binding namevalue
- valueseparator
- separator characterpublic String getAttribute(String bindingName, String attributeName, String defaultValue)
bindingName
- name of the binding for binding attribute
or null for context attributeattributeName
- name of the attribute to retrieve; cannot be nulldefaultValue
- default value returned when attribute does not exist
public void setAttribute(String bindingName, String attributeName, String value)
bindingName
- name of the binding for binding attribute
or null for context attributeattributeName
- name of the attribute to modify; cannot be nullvalue
- new value of the attribute; null is allowed and means
deletion of attributepublic void addContextListener(ContextListener l)
ContextEvent.getContext()
must be consulted to learn in which
context the change really happened.
l
- listener to addpublic void removeContextListener(ContextListener l)
l
- listener to removepublic boolean hasDefault(String bindingName)
bindingName
- the binding name or null for the context examination
public boolean isModified(String bindingName)
hasDefault(java.lang.String)
is false.
bindingName
- the binding name or null for the context
public void revert(String bindingName) throws ContextException
isModified(java.lang.String)
returns true). If there is no default
value (ie. hasDefault(java.lang.String)
returns false) the revert operation
is identical to unbinding of object or destroying of content of context.
bindingName
- the binding name or null for the context
ContextException
- can throw exception if there were problems
during removal of modified valuespublic static Mutex getMutex()
public String toString()
|
org.netbeans.modules.registry/1 1.8 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |