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-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.
- Author:
- Alexander Verbraeck
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
destroySubContext
(ContextInterface parentContext, String name) Destroy a sub-context in the parentContext with the name as its path.static ContextInterface
lookupOrCreateSubContext
(ContextInterface parentContext, String name) Lookup or create a sub-context in the parentContext with the name as its path.static ContextInterface
lookupSubContext
(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 String
toText
(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, RemoteException 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
- ContextInterface; the parent contextname
- String; the name to register the new subcontext- Returns:
- ContextInterface; the newly created subcontext
- Throws:
NamingException
- when terminating key in the name is blank or contains "/" character(s)RemoteException
- on a network error when the Context is used over RMI
-
lookupSubContext
public static ContextInterface lookupSubContext(ContextInterface parentContext, String name) throws NamingException, RemoteException 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
- ContextInterface; the parent contextname
- String; the name to register the new subcontext- Returns:
- ContextInterface; the newly created subcontext
- Throws:
NamingException
- when terminating key in the name is blank or contains "/" character(s)RemoteException
- on a network error when the Context is used over RMI
-
destroySubContext
public static void destroySubContext(ContextInterface parentContext, String name) throws NamingException, RemoteException 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
- ContextInterface; the parent contextname
- String; the name to use to find the subcontext to remove- Throws:
NamingException
- when terminating key in the name is blank or contains "/" character(s)RemoteException
- on a network error when the Context is used over RMI
-
resolveKeys
public static List<String> resolveKeys(ContextInterface startContext, Object object) throws NamingException, RemoteException 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
- ContextInterface; the context to start the searchobject
- Object; the object to look up in the tree under the startContext- Returns:
- List<String>; 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 searchingRemoteException
- on a network error when the Context is used over RMI
-
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
-