View Javadoc
1   package org.andromda.repositories.emf;
2   
3   import org.andromda.core.repository.RepositoryFacadeException;
4   import org.apache.commons.lang.StringUtils;
5   import org.eclipse.emf.common.util.URI;
6   
7   /**
8    * Contains some utilities methods for dealing with the EMF repository
9    * facade functionality.
10   *
11   * @author Chad Brandon
12   */
13  class EMFRepositoryFacadeUtils
14  {
15      /**
16       * The URI file prefix.
17       */
18      private static final String FILE_PREFIX = "file:";
19  
20      /**
21       * The URI archive file prefix.
22       */
23      private static final String ARCHIVE_FILE_PREFIX = "jar:file:";
24  
25      /**
26       * Creates the EMF URI instance from the given <code>uri</code>.
27       *
28       * @param uri the path from which to create the URI.
29       * @return the URI
30       */
31      static URI createUri(String uri)
32      {
33          if (!uri.startsWith(ARCHIVE_FILE_PREFIX) && uri.startsWith(FILE_PREFIX))
34          {
35              final String filePrefixWithSlash = FILE_PREFIX + '/';
36              if (!uri.startsWith(filePrefixWithSlash))
37              {
38                  uri = StringUtils.replaceOnce(
39                          uri,
40                          FILE_PREFIX,
41                          filePrefixWithSlash);
42              }
43          }
44          final URI resourceUri = URI.createURI(uri);
45          if (resourceUri == null)
46          {
47              throw new RepositoryFacadeException("The path '" + uri + "' is not a valid URI");
48          }
49          return resourceUri;
50      }
51  }