com.atomikos.util.IntraVmObjectRegistry Maven / Gradle / Ivy
/**
* Copyright (C) 2000-2023 Atomikos
*
* LICENSE CONDITIONS
*
* See http://www.atomikos.com/Main/WhichLicenseApplies for details.
*/
package com.atomikos.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameNotFoundException;
/**
* An intra-VM object registry for reconstructing Objects from references.
*
*/
public class IntraVmObjectRegistry {
private final static Map resourcesMap = new HashMap();
public synchronized static void addResource(String resourceName, Object resource) throws NameAlreadyBoundException
{
if (resourcesMap.containsKey(resourceName))
throw new NameAlreadyBoundException("resource with name '" + resourceName + "' already registered");
resourcesMap.put(resourceName, resource);
}
public synchronized static Object getResource(String resourceName) throws NameNotFoundException
{
if (!resourcesMap.containsKey(resourceName))
throw new NameNotFoundException("no resource with name '" + resourceName + "' has been registered yet");
return resourcesMap.get(resourceName);
}
public synchronized static void removeResource(String resourceName) throws NameNotFoundException
{
if (!resourcesMap.containsKey(resourceName))
throw new NameNotFoundException("no resource with name '" + resourceName + "' has been registered yet");
resourcesMap.remove(resourceName);
}
public synchronized static List