code: public static void registerExtension(String key, Extension extension) {
          if (key == null || extension == null) {
              throw new IllegalArgumentException(
                              "Neither 'key' nor 'extension' parameter can be null.");
          }
          w.lock();
          try {
              if (extensionMap.containsKey(key)) {
                  throw new IllegalArgumentException("Extension with the key "
                                                     + key + " is registered already");
              }
              extensionMap.put(key, new WeakReference<Extension>(extension));
          } finally {
              w.unlock();
          }
      }
docs: Registers new context extension. To avoid memory leaks Extensions are
  stored as weak references. It means that caller need to keep strong
  reference (a static field for example) to keep that extension in the
  registration map.
  
  @param key
  String key to associate with the registered extension
  @param extension
  {@link Extension} implementation returning extension runtime
  values
  @throws IllegalArgumentException
  if parameter <code>key</code> or <code>extension</code> are
  <code>null</code>; or if <code>key</code> already has
  extension associated with it.