|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.instantreality.InstantIO.Namespace
public class Namespace
Container for InSlots and OutSlots.
Namespace object are used to automatically connect InSlots
and OutSlots
. InSlots and
OutSlots connect to each other when they
// Create the namespace Namespace namespace = new Namespace(); // Create the outslot and add it to the namespace OutSlot outSlot = new OutSlot(Integer.class); namespace.addOutSlot("out", outSlot); // Create the inslot and add it to the namespace InSlot inSlot = new InSlot(Integer.class); namespace.addInSlot("in", inSlot); // Create a route that maps "out" to "in" namespace.addRoute("out", "in"); // Enable the namespace namespace.enable();In this example, the OutSlot and the InSlot get connected when the namespace is enabled. A namespace is disabled by default. A namespace connects OutSlots and InSlots only when it is enabled. It is perfectly ok to enable the namespace before you add any OutSlots, InSlots and routes. In this case OutSlots and InSlots get connected as soon as all preconditions to connect them are fulfilled.
In the example above, we created a new Namespace object.
But when there are lots of different software components
that need to exchange data, it gets difficult to provide them
with the same namespace object. For this reason, a special
descendant of the Namespace class exists: The Root
singleton. Exactly one instance of this class exists
in an application. So all software components can obtain
this single instance and add their OutSlots and InSlots to
it. The following piece of code demonstrates how to do that:
// Get the root namespace Namespace root = Root.the(); // Add OutSlots and InSlots to the root namespace root.addOutSlot("out", outSlot); root.addInSlot("in", inSlot);The Root singleton is enabled by default.
Besides of adding slots and routes to namespaces, you can also add subnamespaces. Subnamespaces are normal Namespace objects, i.e. you can add slots and routes to them. By using so-called "external routes", you can export OutSlots and InSlots from subnamespaces to their parent namespace. The following piece of code demonstrates how to create a subnamespace, and how to export the slots in the subname to the parent namespace.
// Get the root namespace Namespace root = Root.the(); // Create a subnamespace and add it to the root namespace Namespace subnamespace = new Namespace(); root.addNamespace("label", subnamespace); // Create the outslot and add it to the subnamespace OutSlot outSlot = new OutSlot(Integer.class); subnamespace.addOutSlot("subout", outSlot); // Create the inslot and add it to the subnamespace InSlot inSlot = new InSlot(Integer.class); subnamespace.addInSlot("subin", inSlot); // Export the outslot as "out" to the root namespace subnamespace.addExternalRoute("subout", "out"); // Export the inslot as "in" to the root namespace subnamespace.addExternalRoute("subin", "in"); // Create a route that maps "out" to "in" in the root // namespace root.addRoute("out", "in");In the example above, the outslot and the inslot get connected, because there is a route from "out" to "in", and the outslot and the inslot are exported under these labels into the root namespace.
Subnamespaces inherit the enabled/disabled state of their parent namespace. I.e. when you add a namespace to an enabled namespace, it gets enabled, and when you add a namespace to a disabled namespace, it gets disabled. When you enabled or disable a parent namespace, the subnamespaces get enabled or disabled likewise.
OutSlot
,
InSlot
,
Root
Nested Class Summary | |
---|---|
static interface |
Namespace.Listener
Allows to receive information about the status of a Namespace. |
Constructor Summary | |
---|---|
Namespace()
Creates a new Namespace object. |
Method Summary | |
---|---|
void |
addExternalRoute(java.lang.String internal,
java.lang.String external)
Adds an external route to the Namespace. |
void |
addInSlot(java.lang.String label,
InSlot inSlot)
Adds an InSlot to the Namespace. |
void |
addListener(Namespace.Listener listener)
Adds a Listener to the Namespace. |
java.lang.String |
addNamespace(Namespace namespace)
Adds a Subnamespace to this Namespace. |
java.lang.String |
addNamespace(java.lang.String label,
Namespace namespace)
Adds a Subnamespace to this Namespace. |
void |
addOutSlot(java.lang.String label,
OutSlot outSlot)
Adds an OutSlot to the Namespace. |
void |
addRoute(java.lang.String from,
java.lang.String to)
Adds a route to the Namespace. |
void |
clear()
Removes all routes, external routes and subnamespaces from this Namespace. |
void |
clearExternalRoutes()
Removes all external routes from the Namespace. |
void |
clearNamespaces()
Removes all subnamespaces from the Namespace. |
void |
clearRoutes()
Removes all routes from the Namespace. |
boolean |
dirty()
Returns if this Namespaces has unsaved changes. |
void |
disable()
Disables the Namespace. |
void |
dispose()
Disposes a Namespace object. |
void |
enable()
Enables the Namespace. |
boolean |
enabled()
Returns if the Namespace is enabled or disabled. |
protected void |
finalize()
Destroys a Namespace object. |
java.net.URL |
getBaseURL()
Returns the base URL of the Namespace. |
java.util.Vector |
getFieldNames()
Returns the names of all fields. |
java.lang.String |
getFieldValue(java.lang.String name)
Returns the value of a field. |
java.lang.String |
getLabel()
Returns the label of the Namespace. |
protected void |
initialize()
Gets called when the Namespace is enabled. |
void |
removeExternalRoute(java.lang.String internal,
java.lang.String external)
Removes an external route from the Namespace. |
void |
removeInSlot(java.lang.String label,
InSlot inSlot)
Removes an InSlot from the Namespace. |
void |
removeListener(Namespace.Listener listener)
Removes a Listener from the Namespace. |
Namespace |
removeNamespace(java.lang.String label)
Removes a Subnamespace from the Namespace. |
void |
removeOutSlot(java.lang.String label,
OutSlot outSlot)
Removes an OutSlot from the Namespace. |
void |
removeRoute(java.lang.String from,
java.lang.String to)
Removes a route from the Namespace. |
boolean |
saveState()
Returns if the contents of this Namespace should be saved. |
void |
setBaseURL(java.net.URL url)
Sets the base URL of the Namespace. |
void |
setDirty(boolean dirty)
Sets the status of the dirty flag. |
void |
setFieldValue(java.lang.String name,
java.lang.String value)
Sets the value of a field. |
void |
setFieldValues(java.lang.String paramLine)
Sets the values of fields from a line of parameters. |
protected void |
shutdown()
Gets called when the Namespace is disabled. |
protected java.lang.String |
typeName()
Returns the type name of the Namespace. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Namespace()
The following example demonstrated how the create a new Namespace and how to enable it:
Namespace namespace = new Namespace(); namespace.enable();
Method Detail |
---|
protected void finalize() throws java.lang.Throwable
dispose
method.
finalize
in class java.lang.Object
java.lang.Throwable
dispose()
public void dispose()
OutSlots
,
InSlots
and routes, and remove this
namespace from its parent namespace (if any).
The following example demonstrates how to dispose a namespace when you do not need it anymore:
Namespace namespace = ...; namespace.dispose();
public final void addListener(Namespace.Listener listener)
listener
- The listener.removeListener(org.instantreality.InstantIO.Namespace.Listener)
public final void removeListener(Namespace.Listener listener)
listener
- The listener.addListener(org.instantreality.InstantIO.Namespace.Listener)
public void enable()
The following example demonstrates how to enable and later on disable a namespace:
Namespace namespace = ...; namespace.enable(); ... namespace.disable();
disable()
,
enabled()
public void disable()
The following example demonstrates how to enable and later on disable a namespace:
Namespace namespace = ...; namespace.enable(); ... namespace.disable();
enable()
,
enabled()
public final boolean enabled()
The following example demonstrates how to check if a namespace is enabled:
Namespace namespace = ...; if (namespace.enabled()) { // namespace is enabled } else { // namespace is not enabled }
enable()
,
disable()
public final java.lang.String getLabel()
The following example prints the label of a namespace to the console:
Namespace namespace = ...; System.out.println("Label = " + namespace.getLabel());
protected java.lang.String typeName()
Node
class which inherits from
the Namespace class, this method returns the
unique type name of the Node.
The following example prints the type name of a namespace to the console:
Namespace namespace = ...; System.out.println("Type name = " + namespace.typeName());
public final void clear()
The following example demonstrates how to clear a namespace:
Namespace namespace = ...; namespace.clear();
public boolean saveState()
Node
whoose contents should not be saved.
For example, the contents of the InlineNode
do
not get saved, because they are loaded from an URL when
instanciating the InlineNode.
The following example demonstrates how to check if the contents of a namespace should be saved:
Namespace namespace = ...; if (namespace.saveState() == true) { // save the state of the namespace } else { // do not save the state of the namespace }
public final boolean dirty()
public final void setDirty(boolean dirty)
dirty
- true when the Namespace needs to be saved,
false otherwise. When you set the dirty flag to true,
this method also sets the dirty flags of all parent
namespaces to true. When you set the dirty flag to false,
this method also sets the dirty flag of all children
namespaces to false.public void setBaseURL(java.net.URL url)
Nodes
to resolve relative URLs.
url
- The base URL.getBaseURL()
public java.net.URL getBaseURL()
Nodes
to resolve relative URLs.
Namespace namespace = ...; System.out.println("Base URL = " + namespace.getBaseURL());
setBaseURL(java.net.URL)
public void setFieldValues(java.lang.String paramLine)
paramLine
- A string consisting of key-value pairs.public void setFieldValue(java.lang.String name, java.lang.String value)
name
- The name of the field.value
- The new value of the field.public java.lang.String getFieldValue(java.lang.String name)
name
- The name of the field.
public java.util.Vector getFieldNames()
public void addOutSlot(java.lang.String label, OutSlot outSlot)
OutSlot
to the Namespace. When the Namespace
is enabled, the OutSlot automatically gets connected
to all InSlots
contained in the Namespace that
have
removeOutSlot
method.
It is perfectly ok to add an OutSlot under the same or
different labels to one or more namespaces. When you add
the OutSlot n times under the same label to a namespace,
you also have to call removeOutSlot
n times
to remove the OutSlot from that namespace.
The following example demonstrates how to add and later remove a boolean OutSlot that provides button press events:
Namespace namespace = ...; OutSlot outSlot = new OutSlot(Boolean.class); namespace.addOutSlot("Button", outSlot); ... namespace.removeOutSlot("Button", outSlot);
label
- The label of the OutSlot. The label is a string
that specifies what kind of data you want to send to
the OutSlot. It is used to automatically connect to InSlots
when you add an OutSlot to a Namespace
.
OutSlots connect to InSlots of the same data type
when they have the same label or when a route exists that maps
the label of the OutSlot to the label of the InSlot. Case does
not matter.outSlot
- The OutSlot.removeOutSlot(java.lang.String, org.instantreality.InstantIO.OutSlot)
public void removeOutSlot(java.lang.String label, OutSlot outSlot)
OutSlot
from the Namespace. The OutSlot
gets disconnected from all InSlots
contained
in the Namespace it is currently connected to.
The following example demonstrates how to add and later remove a boolean OutSlot that provides button press events:
Namespace namespace = ...; OutSlot outSlot = new OutSlot(Boolean.class); namespace.addOutSlot("Button", outSlot); ... namespace.removeOutSlot("Button", outSlot);
label
- The label of the OutSlot in this Namespace.outSlot
- The OutSlot.addOutSlot(java.lang.String, org.instantreality.InstantIO.OutSlot)
public void addInSlot(java.lang.String label, InSlot inSlot)
InSlot
to the Namespace. When the Namespace
is enabled, the InSlot automatically gets connected
to all OutSlots
contained in the Namespace
that have
removeInSlot
method.
It is perfectly ok to add an InSlot under the same or
different labels to one or more namespaces. When you add
the InSlot n times under the same label to a namespace,
you also have to call removeInSlot
n times
to remove the InSlot from that namespace.
The following example demonstrates how to add and later remove a boolean InSlot that receives button press events:
Namespace namespace = ...; InSlot inSlot = new InSlot(Boolean.class); namespace.addInSlot("Button", inSlot); ... namespace.removeInSlot("Button", inSlot);
label
- The label of the InSlot. The label is a string
that specifies what kind of data you want to receive from
the InSlot. It is used to automatically connect to OutSlots
when you add an InSlot to a Namespace
.
InSlots connect to OutSlots of the same data type
when they have the same label or when a route exists that maps
the label of the OutSlot to the label of the InSlot. Case does
not matter.inSlot
- The InSlot.removeInSlot(java.lang.String, org.instantreality.InstantIO.InSlot)
public void removeInSlot(java.lang.String label, InSlot inSlot)
The following example demonstrates how to add and later remove a boolean InSlot that receives button press events:
Namespace namespace = ...; InSlot inSlot = new InSlot(Boolean.class); namespace.addInSlot("Button", inSlot); ... namespace.removeInSlot("Button", inSlot);
label
- The label of the InSlot in this Namespace.inSlot
- The InSlot.addInSlot(java.lang.String, org.instantreality.InstantIO.InSlot)
public void addExternalRoute(java.lang.String internal, java.lang.String external)
The following example demonstrates how to add an OutSlot and an InSlot to a namespace, how to export them to the parent namespace, and how to remove them from the parent namespace later on:
Namespace namespace = ...; namespace.enable(); // Create the outslot and add it to the namespace OutSlot outSlot = new OutSlot(Integer.class); namespace.addOutSlot("out", outSlot); // Create the inslot and add it to the namespace InSlot inSlot = new InSlot(Integer.class); namespace.addInSlot("in", inSlot); // Export the outslot as "extern-out" to the parent namespace namespace.addExternalRoute("out", "extern-out"); // Export the inslot as "extern-in" to the parent namespace namespace.addExternalRoute("in", "extern-in"); ... // Remove the outslot from the parent namespace namespace.removeExternalRoute("out", "extern-out"); // Remove the inslot from the parent namespace namespace.removeExternalRoute("in", "extern-in");
internal
- The internal label. Case does not matter.
This label may contain the wildcards "?", "*" and "[]".
"?" stands for exactly one arbitrary character. "*" stands
for an arbitrary number of arbitrary characters. In square
brackets, you can specify the characters that are allowed
at that position. "[1-9]" means that the characters from
"1" to "9" are allowed at this position. "[aeiou]" means
that the characters "a", "e", "i", "o", and "u" are allowed
at this position. To use the wildcard characters without
their special meaning, escape them using the backslash
character "\".external
- The external label. Case does not matter.
This label may not contain wildcards. Instead, you can use
two variables that get replaced by their respective values:
"{SlotLabel}" gets replaced by the original name of the
slot in the namespace, and "{NamespaceLabel}" gets replaced
by the current label of the namespace.
To use the character "{" without its special meaning,
escape it using the backslash character "\".removeExternalRoute(java.lang.String, java.lang.String)
public void removeExternalRoute(java.lang.String internal, java.lang.String external)
The following example demonstrates how to add an OutSlot and an InSlot to a namespace, how to export them to the parent namespace, and how to remove them from the parent namespace later on:
Namespace namespace = ...; namespace.enable(); // Create the outslot and add it to the namespace OutSlot outSlot = new OutSlot(Integer.class); namespace.addOutSlot("out", outSlot); // Create the inslot and add it to the namespace InSlot inSlot = new InSlot(Integer.class); namespace.addInSlot("in", inSlot); // Export the outslot as "extern-out" to the parent namespace namespace.addExternalRoute("out", "extern-out"); // Export the inslot as "extern-in" to the parent namespace namespace.addExternalRoute("in", "extern-in"); ... // Remove the outslot from the parent namespace namespace.removeExternalRoute("out", "extern-out"); // Remove the inslot from the parent namespace namespace.removeExternalRoute("in", "extern-in");
internal
- The internal label.external
- The external label.addExternalRoute(java.lang.String, java.lang.String)
public final void clearExternalRoutes()
The following example demonstrates how to remove all external routes from a namespace:
Namespace namespace = ...; namespace.clearExternalRoutes();
public void addRoute(java.lang.String from, java.lang.String to)
OutSlots
in
the Namespace that match the "from" label of the route are
connected to all InSlots
in the Namespace that
match the "to" label and have the same data type. When you try
to add a route that already exists in the namespace, the call
gets silently ignored.
The following example demonstrates how to add an OutSlot and an InSlot to a namespace, how to connect them by a route, and how to remove the route later on:
Namespace namespace = ...; namespace.enable(); // Create the outslot and add it to the namespace OutSlot outSlot = new OutSlot(Integer.class); namespace.addOutSlot("out", outSlot); // Create the inslot and add it to the namespace InSlot inSlot = new InSlot(Integer.class); namespace.addInSlot("in", inSlot); // Add a route that maps "out" to "in". This // automatically connects the outslot and the // inslot added in the code above namespace.addRoute("out", "in"); ... // Remove the route. This automatically // disconnects the outslot and the inslot added in // the code above namespace.removeRoute("out", "in");
from
- The "from" label. Case does not matter.
This label may contain the wildcards "?", "*" and "[]".
"?" stands for exactly one arbitrary character. "*" stands
for an arbitrary number of arbitrary characters. In square
brackets, you can specify the characters that are allowed
at that position. "[1-9]" means that the characters from
"1" to "9" are allowed at this position. "[aeiou]" means
that the characters "a", "e", "i", "o", and "u" are allowed
at this position. To use the wildcard characters without
their special meaning, escape them using the backslash
character "\".to
- The "to" label. Case does not matter. This label
also may contain wildcard characters.removeRoute(java.lang.String, java.lang.String)
public void removeRoute(java.lang.String from, java.lang.String to)
OutSlots
and InSlots
that are connected by this route are
disconnected.
The following example demonstrates how to add an OutSlot and an InSlot to a namespace, how to connect them by a route, and how to remove the route later on:
Namespace namespace = ...; namespace.enable(); // Create the outslot and add it to the namespace OutSlot outSlot = new OutSlot(Integer.class); namespace.addOutSlot("out", outSlot); // Create the inslot and add it to the namespace InSlot inSlot = new InSlot(Integer.class); namespace.addInSlot("in", inSlot); // Add a route that maps "out" to "in". This // automatically connects the outslot and the // inslot added in the code above namespace.addRoute("out", "in"); ... // Remove the route. This automatically // disconnects the outslot and the inslot added in // the code above namespace.removeRoute("out", "in");
from
- The "from" label.to
- The "to" label.addRoute(java.lang.String, java.lang.String)
public final void clearRoutes()
The following example demonstrates how to remove all routes from a namespace:
Namespace namespace = ...; namespace.clearRoutes();
public java.lang.String addNamespace(Namespace namespace)
typeName
method and adding a number.
The following example demonstrates how to add a subnamespace to a parent namespace, and how to remove that subnamespace from the parent namespace later on:
Namespace namespace = ...; Namespace subnamespace = ...; // Add the subnamespace to the parent namespace String label = namespace.addNamespace(subnamespace); ... // Remove the subnamespace from the parent namespace namespace.removeNamespace(label);
namespace
- The child Namespace.
removeNamespace(java.lang.String)
public java.lang.String addNamespace(java.lang.String label, Namespace namespace)
The following example demonstrates how to add a subnamespace to a parent namespace, and how to remove that subnamespace from the parent namespace later on:
Namespace namespace = ...; Namespace subnamespace = ...; // Add the subnamespace to the parent namespace String label = namespace.addNamespace("macro", subnamespace); ... // Remove the subnamespace from the parent namespace namespace.removeNamespace(label);
label
- The label of the child Namespace.namespace
- The child Namespace.
removeNamespace(java.lang.String)
public Namespace removeNamespace(java.lang.String label)
The following example demonstrates how to add a subnamespace to a parent namespace, and how to remove that subnamespace from the parent namespace later on:
Namespace namespace = ...; Namespace subnamespace = ...; // Add the subnamespace to the parent namespace String label = namespace.addNamespace(subnamespace); ... // Remove the subnamespace from the parent namespace namespace.removeNamespace(label);
label
- The label of the child Namespace.
addNamespace(java.lang.String, org.instantreality.InstantIO.Namespace)
public final void clearNamespaces()
The following example demonstrates how to remove all subnamespaces from a namespace:
Namespace namespace = ...; namespace.clearNamespaces();
protected void initialize()
protected void shutdown()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |