Ejemplo n.º 1
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();
   }
 }
 /**
  * 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());
   }
 }