예제 #1
0
  private void createIncludeDirectives(
      final DefaultModule module, final List<IncludeDirective> list, final Category category) {
    DefaultResource[] providers = getDefaultProviders(Scope.RUNTIME, true, category);
    for (int i = 0; i < providers.length; i++) {
      DefaultResource provider = providers[i];
      if (provider.isaDescendant(module)) {
        // create a ref
        String path = provider.getResourcePath();
        IncludeDirective include = new IncludeDirective(IncludeDirective.REF, category, path, null);
        if (!list.contains(include)) {
          list.add(include);
        }
      } else {
        // create a urn

        Type[] types = provider.getTypes();
        for (int j = 0; j < types.length; j++) {
          Type type = types[j];
          String label = type.getID();
          Artifact artifact = type.getArtifact();
          String urn = artifact.toString();
          IncludeDirective include =
              new IncludeDirective(IncludeDirective.URI, category, urn, null);
          if (!list.contains(include)) {
            list.add(include);
          }
        }
      }
    }
  }
 /**
  * Convert a sequence of URIs to URLs.
  *
  * @param uris the uris to convert
  * @return the corresponding urls
  * @exception IOException of a transformation error occurs
  */
 public static URL[] toURLs(URI[] uris) throws IOException {
   URL[] urls = new URL[uris.length];
   for (int i = 0; i < urls.length; i++) {
     URI uri = uris[i];
     if (Artifact.isRecognized(uri)) {
       urls[i] = Artifact.toURL(uri);
     } else {
       urls[i] = uri.toURL();
     }
   }
   return urls;
 }
 /**
  * Test artifact uri function.
  *
  * @exception Exception if a test error occurs
  */
 public void testArtifact() throws Exception {
   String path = "dpml/tools/dpml-tools-ant";
   Resource resource = getLibrary().getResource(path);
   Type[] types = resource.getTypes();
   for (int i = 0; i < types.length; i++) {
     Type type = types[i];
     Artifact artifact = resource.getArtifact(type.getID());
     String urn =
         "artifact:"
             + type.getID()
             + ":"
             + resource.getResourcePath()
             + "#"
             + resource.getVersion();
     assertEquals("uri", urn, artifact.toURI().toString());
   }
 }
예제 #4
0
 /**
  * Utility function supporting resolution of uris containing 'resource' or 'alias' schemes. If the
  * supplied uri schem is 'resource' or 'alias' the reference is resolved to a artifact type, group
  * and name from which a resource is resolved and the uri returned. If the scheme is resource the
  * usri of the resource is returned. If the scheme is 'alias' a linkn alias is returned. If the
  * scheme is not 'resource' or 'alias' the argument will be evaluated as a normal transit artifact
  * uri specification.
  *
  * @param ref the uri argument
  * @return the uri value
  * @exception URISyntaxException if an error occurs during uri creation
  */
 public URI toURI(final String ref) throws URISyntaxException {
   Artifact spec = Artifact.createArtifact(ref);
   if (spec.isRecognized()) {
     return spec.toURI();
   } else if (ref.startsWith("resource:") || ref.startsWith("alias:")) {
     String type = spec.getType();
     String group = spec.getGroup();
     String name = spec.getName();
     String path = group + "/" + name;
     Library library = getLibrary();
     try {
       Resource resource = library.getResource(path);
       Type t = resource.getType(type);
       if (ref.startsWith("resource:")) {
         Artifact artifact = t.getArtifact();
         return artifact.toURI();
       } else {
         Artifact artifact = t.getLinkArtifact();
         return artifact.toURI();
       }
     } catch (ResourceNotFoundException e) {
       final String error = "Unresolvable resource reference: " + path;
       IllegalArgumentException iae = new IllegalArgumentException(error);
       iae.initCause(e);
       throw iae;
     }
   } else {
     return spec.toURI();
   }
 }