Logo Search packages:      
Sourcecode: libloader version File versions  Download package

ResourceKey org::jfree::resourceloader::ResourceManager::deriveKey ( final ResourceKey  parent,
final String  path,
final Map  parameters 
) throws ResourceKeyCreationException [inline]

Derives a new key from the given resource-key. Only keys for a hierarchical storage system (like file-systems or URLs) can have derived keys. Since LibLoader 0.3.0 only hierarchical keys can be derived. For that, the deriving path must be given as String.

The optional parameter-map will be applied to the derived key after the parent's parameters have been copied to the new key.

Before trying to derive the key, the system tries to interpret the path as absolute key-value.

Parameters:
parent the parent key, or null to interpret the path as absolute key.
path the relative path, that is used to derive the key.
Returns:
the derived key.

Definition at line 175 of file ResourceManager.java.

References org::jfree::resourceloader::ResourceLoader::createKey(), createKey(), org::jfree::resourceloader::ResourceLoader::deriveKey(), and org::jfree::resourceloader::ResourceLoader::isSupportedKey().

  {
    if (path == null)
    {
      throw new NullPointerException("Key data must not be null.");
    }
    if (parent == null)
    {
      return createKey(path, parameters);
    }

    // First, try to derive the resource directly. This makes sure, that we preserve the parent's context.
    // If a file is derived, we assume that the result will be a file; and only if that fails we'll try to
    // query the other contexts. If the parent is an URL-context, the result is assumed to be an URL as well.
    ResourceKeyCreationException rce = null;
    for (int i = 0; i < resourceLoaders.size(); i++)
    {
      final ResourceLoader loader = (ResourceLoader) resourceLoaders.get(i);
      if (loader.isSupportedKey(parent) == false)
      {
        continue;
      }
      try
      {
        final ResourceKey key = loader.deriveKey(parent, path, parameters);
        if (key != null)
        {
          return key;
        }
      }
      catch (ResourceKeyCreationException rcke)
      {
        rce = rcke;
      }
    }

    // First, try to load the key as absolute value.
    // This assumes, that we have no catch-all implementation.
    for (int i = 0; i < resourceLoaders.size(); i++)
    {
      final ResourceLoader loader = (ResourceLoader) resourceLoaders.get(i);
      final ResourceKey key = loader.createKey(path, parameters);
      if (key != null)
      {
        return key;
      }
    }

    if (rce != null)
    {
      throw rce;
    }
    throw new ResourceKeyCreationException
        ("Unable to create key: No such schema or the key was not recognized.");
  }


Generated by  Doxygen 1.6.0   Back to index