コード例 #1
0
  @SuppressWarnings("unchecked")
  private static URI createNewResource(
      Resource projectResource, String projectPath, ProjectElement projectElement) {
    int i = 0;
    List<Resource> list = projectResource.getResourceSet().getResources();
    URIConverter uriConverter = projectResource.getResourceSet().getURIConverter();
    URI uri = null;
    boolean found = false;
    do {
      found = false;
      i++;
      // TODO Add file extension name to ProjectElement
      uri = generateResourceName(projectPath, projectElement, i);

      URI normalizedURI = uriConverter.normalize(uri);
      for (Resource resource2 : list) {
        if (uriConverter.normalize(resource2.getURI()).equals(normalizedURI)) {
          found = true;
          break;
        }
      }
      if (!found) {
        File file = new File(uri.toFileString());
        if (file.exists()) found = true;
      }
    } while (found);
    uri.deresolve(projectResource.getURI(), true, true, true);
    return uri;
  }
コード例 #2
0
  public static String createBuildPathRelativeReference(URI sourceURI, URI targetURI) {
    if (sourceURI == null || targetURI == null) throw new IllegalArgumentException();

    // BaseURI source = new BaseURI(sourceURI);
    // return source.getRelativeURI(targetURI);
    // TODO: this is probably bogus.
    if (targetURI.isFile()) {
      return targetURI.lastSegment();
    }
    String result = targetURI.deresolve(sourceURI, true, true, true).toFileString();
    // When absolute URLs
    return (result == null ? targetURI.toString() : result);
  }
コード例 #3
0
  /**
   * Gets the relative URI of a method element in the managed method library.
   *
   * @param element a method element
   * @return a relative URI
   */
  public URI getElementRelativeURI(MethodElement element) {
    if (debug) {
      DebugTrace.print(
          this, "getElementRelativeURI", "element=" + element); // $NON-NLS-1$ //$NON-NLS-2$
    }

    if (element != null) {
      Resource resource = library.eResource();
      if (resource != null) {
        URI libraryURI = resource.getURI();
        URI elementURI = element.eResource().getURI();
        return elementURI.deresolve(libraryURI);
      }
    }
    return null;
  }