All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gxt-2.1.1-sources.com.extjs.gxt.ui.client.Registry Maven / Gradle / Ivy

There is a newer version: 2.3.1-gwt22
Show newest version
/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * [email protected]
 * 
 * http://extjs.com/license
 */
package com.extjs.gxt.ui.client;

import java.util.Map;

import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.event.BaseObservable;

/**
 * A local storage of objects stored by id.
 */
public final class Registry extends BaseObservable {

  protected static Map map = new FastMap();

  /**
   * Returns the object with the given id.
   * 
   * @param id the identifier
   * @return the object or null if no match
   */
  @SuppressWarnings("unchecked")
  public static  X get(String id) {
    return (X) map.get(id);
  }

  /**
   * Returns a map of all registered objects.
   * 
   * @return the object map
   */
  public static Map getAll() {
    return map;
  }

  /**
   * Registers an object.
   * 
   * @param id the identifier
   * @param obj the object to be registered
   */
  public static void register(String id, Object obj) {
    map.put(id, obj);
  }

  /**
   * Unregisters an object.
   * 
   * @param id the identifier
   */
  public static void unregister(String id) {
    map.remove(id);
  }

  /**
   * Unregisters all registered objects.
   */
  public static void unregisterAll() {
    map.clear();
  }

  private Registry() {
  }

}