Class ContextUtil
java.lang.Object
nl.tudelft.simulation.naming.context.util.ContextUtil
ContextUtil contains a few helper methods to deal with an InitialEventContext.
Copyright (c) 2020-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information DSOL Manual. The DSOL project is distributed under a three-clause BSD-style license, which can be found at DSOL License.
- Author:
- Alexander Verbraeck
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddestroySubContext(ContextInterface parentContext, String name) Destroy a sub-context in the parentContext with the name as its path.static ContextInterfacelookupOrCreateSubContext(ContextInterface parentContext, String name) Lookup or create a sub-context in the parentContext with the name as its path.static ContextInterfacelookupSubContext(ContextInterface parentContext, String name) Lookup a sub-context in the parentContext with the name as its path.resolveKeys(ContextInterface startContext, Object object) Resolve the key(s) for an object for a given context.static StringtoText(ContextInterface ctx) recursively print the context in human-readable format to a String.
-
Constructor Details
-
ContextUtil
public ContextUtil()
-
-
Method Details
-
lookupOrCreateSubContext
public static ContextInterface lookupOrCreateSubContext(ContextInterface parentContext, String name) throws NamingException Lookup or create a sub-context in the parentContext with the name as its path. The path can be absolute or relative. The terminating part of the name will be used as the key under which the created subcontext will be registered.- Parameters:
parentContext- the parent contextname- the name to register the new subcontext- Returns:
- the newly created subcontext
- Throws:
NamingException- when terminating key in the name is blank or contains "/" character(s)
-
lookupSubContext
public static ContextInterface lookupSubContext(ContextInterface parentContext, String name) throws NamingException Lookup a sub-context in the parentContext with the name as its path. The path can be absolute or relative. The terminating part of the name will be used as the key under which the created subcontext will be registered.- Parameters:
parentContext- the parent contextname- the name to register the new subcontext- Returns:
- the newly created subcontext
- Throws:
NamingException- when terminating key in the name is blank or contains "/" character(s)
-
destroySubContext
public static void destroySubContext(ContextInterface parentContext, String name) throws NamingException Destroy a sub-context in the parentContext with the name as its path. The path can be absolute or relative. The terminating part of the name will be used as the key under for the subcontext to be removed.- Parameters:
parentContext- the parent contextname- the name to use to find the subcontext to remove- Throws:
NamingException- when terminating key in the name is blank or contains "/" character(s)
-
resolveKeys
public static List<String> resolveKeys(ContextInterface startContext, Object object) throws NamingException Resolve the key(s) for an object for a given context. This can be an expensive operation if the context is large. An object can be registered zero or more times in the context, so a List of keys under which the object is registered will be returned. The keys are relative to the startContext. The method starts with the given context. It is possible to look up null objects in the Context.- Parameters:
startContext- the context to start the searchobject- the object to look up in the tree under the startContext- Returns:
- the list of keys that are bound to the object, or an empty list if no bindings for the object were found
- Throws:
NamingException- when an error occurs during searching
-
toText
recursively print the context in human-readable format to a String.- Parameters:
ctx- the context to print- Returns:
- a human-readable String with the context tree
-