## org.eclipse.emf.ecore.resource.impl
Class URIConverterImpl

    java.lang.Object
      org.eclipse.emf.ecore.resource.impl.URIConverterImpl

All Implemented Interfaces:
  URIConverter

    public class URIConverterImpl

extends java.lang.Object
implements URIConverter

A highly functional and extensible URI converter implementation.

This implementation provides seamless transparent Eclipse integration by supporting the `platform:/resource` mechanism both inside of Eclipse and outside of Eclipse. Furthermore, although the implementation imports both `org.eclipse.core.runtime` and `org.eclipse.core.resources`, and hence requires the Eclipse libraries at development time, the implementation does not require them at runtime. Clients of this implementation must be cautious if they wish to maintain this platform neutral behaviour.

Nested Class Summary
`protected class` `URIConverterImpl.Archive` A specialized class for reading from an archive.
`static class` `URIConverterImpl.PlatformResourceOutputStream` An output stream that transfers its contents to an `IFile` upon closing.
`static interface` `URIConverterImpl.URIMap` A map that remaps URIs.
`static class` `URIConverterImpl.WorkbenchHelper` Isolated Eclipse workbench utilities.

Nested classes/interfaces inherited from interface org.eclipse.emf.ecore.resource.URIConverter
`URIConverter.Cipher, URIConverter.Readable, URIConverter.ReadableInputStream, URIConverter.Writeable, URIConverter.WriteableOutputStream`

Field Summary
`protected URIConverterImpl.URIMap` `uriMap` The URI map.
`protected static IWorkspaceRoot` `workspaceRoot` The cached Eclipse workspace.

Fields inherited from interface org.eclipse.emf.ecore.resource.URIConverter
`URI_MAP`

Constructor Summary
`URIConverterImpl()` Creates an instance.

Method Summary
`protected URIConverterImpl.Archive` `createArchive(URI uri)`
`protected java.io.InputStream` `createArchiveInputStream(URI archiveURI)` Creates an input stream for the archive paths and returns it.
`protected java.io.OutputStream` `createArchiveOutputStream(URI archiveURI)` Creates an output stream for the archive access.
`protected java.io.InputStream` `createEFSInputStream(URI uri)` Creates an input stream for the URI, assuming it's a URI recognized by the Eclipse File System, and returns it.
`protected java.io.OutputStream` `createEFSOutputStream(URI uri)` Creates an output stream for the URI, assuming it's a URI recognized by the Eclipse File System, and returns it.
`protected java.io.InputStream` `createFileInputStream(java.lang.String filePath)` Creates an input stream for the file path and returns it.
`protected java.io.OutputStream` `createFileOutputStream(java.lang.String filePath)` Creates an output stream for the file path and returns it.
`java.io.InputStream` `createInputStream(URI uri)` Creates an input stream for the URI and returns it.
`java.io.OutputStream` `createOutputStream(URI uri)` Creates an output stream for the URI and returns it.
`protected java.io.InputStream` `createPlatformResourceInputStream(java.lang.String platformResourcePath)` Creates an input stream for the platform resource path and returns it.
`protected java.io.OutputStream` `createPlatformResourceOutputStream(java.lang.String platformResourcePath)` Creates an output stream for the platform resource path and returns it.
`protected java.io.InputStream` `createURLInputStream(URI uri)` Creates an input stream for the URI, assuming it's a URL, and returns it.
`protected java.io.OutputStream` `createURLOutputStream(URI uri)` Creates an output stream for the URI, assuming it's a URL, and returns it.
`protected URIConverterImpl.URIMap` `getInternalURIMap()` Returns the internal version of the URI map.
`java.util.Map<URI,URI>` `getURIMap()` Returns the map used for remapping a logical URI to a physical URI when `normalizing`.
`protected boolean` `isArchiveScheme(java.lang.String scheme)` Returns whether the scheme is one that this implementation should treat as an archive.
`protected boolean` `isEFSScheme(java.lang.String scheme)` Returns whether the scheme is one that this implementation should treat as a supported Eclipse File System scheme.
`URI` `normalize(URI uri)` Returns the normalized form of the URI.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### workspaceRoot

    protected static IWorkspaceRoot workspaceRoot

  The cached Eclipse workspace.

### uriMap

    protected URIConverterImpl.URIMap uriMap

  The URI map.

Constructor Detail

### URIConverterImpl

    public URIConverterImpl()

  Creates an instance.

Method Detail

### isArchiveScheme

    protected boolean isArchiveScheme(java.lang.String scheme)

  Returns whether the scheme is one that this implementation should treat as an archive. This implementation returns `true` when the scheme is `"archive"`.

  Parameters:
    `scheme` - the scheme to consider.
  Returns:
    whether the scheme is one that this implementation treats as an archive.

### isEFSScheme

    protected boolean isEFSScheme(java.lang.String scheme)

  Returns whether the scheme is one that this implementation should treat as a supported Eclipse File System scheme. This implementation uses Java reflection to check whether there is an Eclipse File System available and if so whether it supports this scheme.

  Parameters:
    `scheme` - the scheme to consider.
  Returns:
    whether the scheme is one that this implementation treats as an Eclipse File System scheme.

### createOutputStream

    public java.io.OutputStream createOutputStream(URI uri)
                                            throws java.io.IOException

  Creates an output stream for the URI and returns it.

  This implementation `normalizes` the URI and uses that as the basis for further processing. A `file-based` URI is `converted` to a file path, e.g.,

        file:///C:/directory/file
          ->
         C:/directory/file

  and is delegated to `createFileOutputStream`. An `archive-based` URI is delegated to `createArchiveOutputStream`. A `platform-based` URI is `converted` to a platform path by trimming the leading `platform:/resource`, e.g.,

        platform:/resource/project/directory/file
          ->
        /project/directory/file

  and is delegated to `createPlatformResourceOutputStream`. An `EFS-based` URI is delegated to `createEFSOutputStream`. And all other cases are handled as standard URLs by `createURLOutputStream`.

  Specified by:
    `createOutputStream` in interface `URIConverter`
  Returns:
    an open output stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open output stream.

### createFileOutputStream

    protected java.io.OutputStream createFileOutputStream(java.lang.String filePath)
                                                   throws java.io.IOException

  Creates an output stream for the file path and returns it.

  This implementation allocates a `FileOutputStream` and creates subdirectories as necessary.

  Returns:
    an open output stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open output stream.

### createArchiveOutputStream

    protected java.io.OutputStream createArchiveOutputStream(URI archiveURI)
                                                      throws java.io.IOException

  Creates an output stream for the archive access.

  Returns:
    an open output stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open output stream.

### createPlatformResourceOutputStream

    protected java.io.OutputStream createPlatformResourceOutputStream(java.lang.String platformResourcePath)
                                                               throws java.io.IOException

  Creates an output stream for the platform resource path and returns it.

  This implementation does one of two things, depending on the runtime environment. If there is an Eclipse workspace, it delegates to `WorkbenchHelper.createPlatformResourceOutputStream`, which gives the expected Eclipse behaviour. Otherwise, the `resolved` URI is delegated to `createOutputStream` for recursive processing.

  Returns:
    an open output stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open output stream or a valid interpretation of the path.
  See Also:
    `EcorePlugin.resolvePlatformResourcePath(String)`

### createEFSOutputStream

    protected java.io.OutputStream createEFSOutputStream(URI uri)
                                                  throws java.io.IOException

  Creates an output stream for the URI, assuming it's a URI recognized by the Eclipse File System, and returns it.

  Returns:
    an open output stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open output stream.

### createURLOutputStream

    protected java.io.OutputStream createURLOutputStream(URI uri)
                                                  throws java.io.IOException

  Creates an output stream for the URI, assuming it's a URL, and returns it.

  Returns:
    an open output stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open output stream.

### createInputStream

    public java.io.InputStream createInputStream(URI uri)
                                          throws java.io.IOException

  Creates an input stream for the URI and returns it.

  This implementation `normalizes` the URI and uses that as the basis for further processing. A `file-based` URI is `converted` to a file path, e.g.,

        file:///C:/directory/file
          ->
         C:/directory/file

  and is delegated to `createFileInputStream`. An `archive-based` URI is delegated to `createArchiveInputStream`. A `platform-based` URI is `converted` to a platform path by trimming the leading `platform:/resource`, e.g.,

        platform:/resource/project/directory/file
          ->
        /project/directory/file

  and is delegated to `createPlatformResourceInputStream`. An `EFS-based` URI is delegated to `createEFSInputStream`. And all other cases are handled as standard URLs by `createURLInputStream`.

  Specified by:
    `createInputStream` in interface `URIConverter`
  Returns:
    an open input stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open input stream.

### createFileInputStream

    protected java.io.InputStream createFileInputStream(java.lang.String filePath)
                                                 throws java.io.IOException

  Creates an input stream for the file path and returns it.

  This implementation allocates a `FileInputStream`.

  Returns:
    an open input stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open input stream.

### createArchive

    protected URIConverterImpl.Archive createArchive(URI uri)

### createArchiveInputStream

    protected java.io.InputStream createArchiveInputStream(URI archiveURI)
                                                    throws java.io.IOException

  Creates an input stream for the archive paths and returns it. It uses `URIConverterImpl.Archive` to implement read access.

  Returns:
    an open input stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open input stream.

### createPlatformResourceInputStream

    protected java.io.InputStream createPlatformResourceInputStream(java.lang.String platformResourcePath)
                                                             throws java.io.IOException

  Creates an input stream for the platform resource path and returns it.

  This implementation does one of two things, depending on the runtime environment. If there is an Eclipse workspace, it delegates to `WorkbenchHelper.createPlatformResourceInputStream`, which gives the expected Eclipse behaviour. Otherwise, the `resolved` URI is delegated to `createInputStream` for recursive processing.

  Returns:
    an open input stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open input stream or a valid interpretation of the path.
  See Also:
    `EcorePlugin.resolvePlatformResourcePath(String)`

### createEFSInputStream

    protected java.io.InputStream createEFSInputStream(URI uri)
                                                throws java.io.IOException

  Creates an input stream for the URI, assuming it's a URI recognized by the Eclipse File System, and returns it.

  Returns:
    an open input stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open input stream.

### createURLInputStream

    protected java.io.InputStream createURLInputStream(URI uri)
                                                throws java.io.IOException

  Creates an input stream for the URI, assuming it's a URL, and returns it.

  Returns:
    an open input stream.
  Throws:
    `java.io.IOException` - if there is a problem obtaining an open input stream.

### normalize

    public URI normalize(URI uri)

  Returns the normalized form of the URI.

  This implementation does precisely and only the `typical` thing. It calls itself recursively so that mapped chains are followed.

  Specified by:
    `normalize` in interface `URIConverter`
  Parameters:
    `uri` - the URI to normalize.
  Returns:
    the normalized form.
  See Also:
    `EcorePlugin.getPlatformResourceMap()`

### getURIMap

    public java.util.Map<URI,URI> getURIMap()

  Description copied from interface: `URIConverter`
  Returns the map used for remapping a logical URI to a physical URI when `normalizing`.

  An implementation will typically also delegate to the `global` map, so registrations made in this map are local to this URI converter, i.e., they augment or override those of the global map.

  The map generally specifies instance to instance mapping, except for the case that both the key URI and the value URI end with "/", which specifies a folder to folder mapping. A folder mapping will remap any URI that has the key as its `prefix`, e.g., if the map contains:

        http://www.example.com/ -> platform:/resource/example/

  then the URI

        http://www.example.com/a/b/c.d

  will map to

        platform:/resource/example/a/b/c.d

  A matching instance mapping is considered first. If there isn't one, the folder mappings are considered starting with the `longest` prefix.

  Specified by:
    `getURIMap` in interface `URIConverter`
  Returns:
    the map used for remapping a logical URI to a physical URI.
  See Also:
    `URIConverter.normalize(URI)`, `URIConverter.URI_MAP`

### getInternalURIMap

    protected URIConverterImpl.URIMap getInternalURIMap()

  Returns the internal version of the URI map.

  Returns:
    the internal version of the URI map.

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.