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

java.lang.Object
  extended byorg.eclipse.emf.ecore.resource.impl.URIConverterImpl
All Implemented Interfaces:
URIConverter

public class URIConverterImpl
extends 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 inherited from class 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  InputStream createArchiveInputStream(URI archiveURI)
          Creates an input stream for the archive paths and returns it.
protected  OutputStream createArchiveOutputStream(URI archiveURI)
          Creates an output stream for the archive access.
protected  InputStream createFileInputStream(String filePath)
          Creates an input stream for the file path and returns it.
protected  OutputStream createFileOutputStream(String filePath)
          Creates an output stream for the file path and returns it.
 InputStream createInputStream(URI uri)
          Creates an input stream for the URI and returns it.
 OutputStream createOutputStream(URI uri)
          Creates an output stream for the URI and returns it.
protected  InputStream createPlatformResourceInputStream(String platformResourcePath)
          Creates an input stream for the platform resource path and returns it.
protected  OutputStream createPlatformResourceOutputStream(String platformResourcePath)
          Creates an output stream for the platform resource path and returns it.
protected  InputStream createURLInputStream(URI uri)
          Creates an input stream for the URI, assuming it's a URL, and returns it.
protected  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.
 Map getURIMap()
          Returns the map used for remapping a logical URI to a physical URI when normalizing.
protected  boolean isArchiveScheme(String scheme)
          Returns whether the scheme is one that this implementation should treat as an archive.
 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(String scheme)
Returns whether the scheme is one that this implementation should treat as an archive. This implementation returns true which the schem is "archive".

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

createOutputStream

public OutputStream createOutputStream(URI uri)
                                throws 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. It factors out the URI schemes file and platform (with leading resource segment) for special processing by createFileOutputStream and createPlatformResourceOutputStream, respectively. The file-based URI is converted to a file path, e.g.,

  file:///C:/directory/file
    ->
   C:/directory/file
and the 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 
All other cases are handled as standard URLs by createURLOutputStream.

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

createFileOutputStream

protected OutputStream createFileOutputStream(String filePath)
                                       throws 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:
IOException - if there is a problem obtaining an open output stream.

createArchiveOutputStream

protected OutputStream createArchiveOutputStream(URI archiveURI)
                                          throws IOException
Creates an output stream for the archive access.

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

createPlatformResourceOutputStream

protected OutputStream createPlatformResourceOutputStream(String platformResourcePath)
                                                   throws 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:
IOException - if there is a problem obtaining an open output stream or a valid interpretation of the path.
See Also:
EcorePlugin.resolvePlatformResourcePath(String)

createURLOutputStream

protected OutputStream createURLOutputStream(URI uri)
                                      throws IOException
Creates an output stream for the URI, assuming it's a URL, and returns it.

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

createInputStream

public InputStream createInputStream(URI uri)
                              throws 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. It factors out the URI schemes file and platform (with leading resource segment) for special processing by createFileInputStream and createPlatformResourceInputStream, respectively. The file-based URI is converted to a file path, e.g.,

  file:///C:/directory/file
    ->
   C:/directory/file
and the 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 
All other cases are handled as standard URLs by createURLInputStream.

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

createFileInputStream

protected InputStream createFileInputStream(String filePath)
                                     throws IOException
Creates an input stream for the file path and returns it.

This implementation allocates a FileInputStream.

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

createArchive

protected URIConverterImpl.Archive createArchive(URI uri)

createArchiveInputStream

protected InputStream createArchiveInputStream(URI archiveURI)
                                        throws IOException
Creates an input stream for the archive paths and returns it. It uses ArchiveReader to implement read access.

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

createPlatformResourceInputStream

protected InputStream createPlatformResourceInputStream(String platformResourcePath)
                                                 throws 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:
IOException - if there is a problem obtaining an open input stream or a valid interpretation of the path.
See Also:
EcorePlugin.resolvePlatformResourcePath(String)

createURLInputStream

protected InputStream createURLInputStream(URI uri)
                                    throws IOException
Creates an input stream for the URI, assuming it's a URL, and returns it.

Returns:
an open input stream.
Throws:
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 Map 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.