Exemplo n.º 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);
          }
        }
      }
    }
  }
Exemplo n.º 2
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();
   }
 }