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