示例#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);
          }
        }
      }
    }
  }
示例#2
0
 /**
  * Return a resource type relative to a supplied type id.
  *
  * @param id the type name to retrieve
  * @return the type instance
  * @exception IllegalArgumentException if the id value does not match a type produced by the
  *     resource.
  */
 public Type getType(final String id) throws IllegalArgumentException {
   boolean flag = id.indexOf('#') > -1;
   if (flag) {
     for (int i = 0; i < m_types.length; i++) {
       Type type = m_types[i];
       if (type.getCompoundName().equals(id)) {
         return type;
       }
     }
   } else {
     for (int i = 0; i < m_types.length; i++) {
       Type type = m_types[i];
       if (type.getID().equals(id)) {
         return type;
       }
     }
   }
   final String error =
       "Type name ["
           + id
           + "] not recognized with the scope of resource ["
           + getResourcePath()
           + "].";
   throw new IllegalArgumentException(error);
 }
示例#3
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();
   }
 }
示例#4
0
 /**
  * Test if this resource is associated with a type of the supplied name.
  *
  * @param type the type id
  * @return TRUE if this resource produces an artifact of the supplied type
  */
 public boolean isa(final String type) {
   for (int i = 0; i < m_types.length; i++) {
     Type someType = m_types[i];
     String name = someType.getID();
     if (name.equals(type)) {
       return true;
     }
   }
   return false;
 }