/**
   * Indicate if the extension as been installed as a dependency of another one.
   *
   * @param extension the extension
   * @param namespace the namespace to look at, null indicate the root namespace
   * @return true if the the extension has been installed only because it was a dependency of
   *     another extension
   * @see InstalledExtension#isDependency(String)
   * @since 8.2RC1
   */
  public static boolean isDependency(Extension extension, String namespace) {
    boolean isDependency = false;

    if (namespace == null) {
      isDependency = extension.getProperty(PKEY_DEPENDENCY, false);
    } else {
      Object namespacesObject = extension.getProperty(PKEY_NAMESPACES);

      // RETRO-COMPATIBILITY: used to be a String collection with just the actual namespaces
      if (namespacesObject instanceof Map) {
        Map<String, Object> installedNamespace =
            ((Map<String, Map<String, Object>>) namespacesObject).get(namespace);

        isDependency =
            installedNamespace != null
                ? (installedNamespace.get(PKEY_NAMESPACES_DEPENDENCY) == Boolean.TRUE)
                : isDependency(extension, null);
      } else {
        isDependency = isDependency(extension, null);
      }
    }

    return isDependency;
  }
  /**
   * @param extension the extension
   * @return the namespaces in which this extension is enabled. Null means root namespace (i.e all
   *     namespaces).
   */
  public static Collection<String> getNamespaces(Extension extension) {
    Collection<String> namespaces;

    Object namespacesObject = extension.getProperty(PKEY_NAMESPACES);

    // RETRO-COMPATIBILITY: used to be a String collection with just the actual namespaces
    if (namespacesObject == null) {
      namespaces = null;
    } else if (namespacesObject instanceof Collection) {
      namespaces = (Collection<String>) namespacesObject;
    } else {
      namespaces = ((Map<String, Map<String, Object>>) namespacesObject).keySet();
    }

    return namespaces;
  }
 /**
  * @param extension the extension
  * @return true if the extension is installed
  * @see InstalledExtension#isInstalled()
  */
 public static boolean isInstalled(Extension extension) {
   return extension.getProperty(PKEY_INSTALLED, false);
 }