Пример #1
0
  public void addFilter(String ns, String name, String version, Attrs attrs) {
    List<String> parts = new ArrayList<String>();

    parts.add("(" + ns + "=" + name + ")");
    if (version != null && VersionRange.isOSGiVersionRange(version)) {
      VersionRange range = VersionRange.parseOSGiVersionRange(version);
      parts.add(range.toFilter());
    }

    String mandatory = attrs.get(Constants.MANDATORY_DIRECTIVE + ":");
    if (mandatory != null) {
      String mandatoryAttrs[] = mandatory.split("\\s*,\\s*");
      Arrays.sort(mandatoryAttrs);
      for (String mandatoryAttr : mandatoryAttrs) {
        String value = attrs.get(mandatoryAttr);
        if (value != null) {
          parts.add("(" + mandatoryAttr + "=" + escapeFilterValue(value) + ")");
        }
      }
    }

    StringBuilder sb = new StringBuilder();
    if (parts.size() > 0) sb.append("(&");
    for (String s : parts) {
      sb.append(s);
    }
    if (parts.size() > 0) sb.append(")");
    addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, sb.toString());
  }
Пример #2
0
 public CapReqBuilder addDirectives(Attrs directives) {
   for (Entry<String, String> e : directives.entrySet()) {
     String key = Attrs.toDirective(e.getKey());
     if (key != null) addDirective(key, e.getValue());
   }
   return this;
 }
Пример #3
0
 public CapReqBuilder(String ns, Attrs attrs) throws Exception {
   this.namespace = ns;
   for (Entry<String, String> entry : attrs.entrySet()) {
     String key = entry.getKey();
     if (key.endsWith(":")) addDirective(key.substring(0, key.length() - 1), entry.getValue());
     else addAttribute(key, entry.getValue());
   }
 }
Пример #4
0
 /**
  * In bnd, we only use one map for both directives & attributes. This method will properly
  * dispatch them AND take care of typing
  *
  * @param attrs
  * @throws Exception
  */
 public void addAttributesOrDirectives(Attrs attrs) throws Exception {
   for (Entry<String, String> e : attrs.entrySet()) {
     String directive = Attrs.toDirective(e.getKey());
     if (directive != null) {
       addDirective(directive, e.getValue());
     } else {
       Object typed = attrs.getTyped(e.getKey());
       if (typed instanceof aQute.bnd.version.Version) {
         typed = new Version(typed.toString());
       }
       addAttribute(e.getKey(), typed);
     }
   }
 }
Пример #5
0
  public void and(String... s) {
    String previous =
        directives == null ? null : directives.get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
    StringBuilder filter = new StringBuilder();

    if (previous != null) {
      filter.append("(&").append(previous);
    }
    for (String subexpr : s) filter.append(subexpr);

    if (previous != null) {
      filter.append(")");
    }
    addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString());
  }
Пример #6
0
  public void parseIndex(
      InputStream stream, URI baseUri, IRepositoryIndexProcessor listener, LogService log)
      throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
    inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);

    StreamSource source = new StreamSource(stream, baseUri.toString());
    XMLStreamReader reader = inputFactory.createXMLStreamReader(source);

    ResourceBuilder resourceBuilder = null;
    CapReqBuilder capReqBuilder = null;

    while (reader.hasNext()) {
      int type = reader.next();
      String localName;

      switch (type) {
        case START_ELEMENT:
          localName = reader.getLocalName();
          if (TAG_REFERRAL.equals(localName)) {
            Referral referral =
                new Referral(
                    reader.getAttributeValue(null, ATTR_REFERRAL_URL),
                    parseInt(reader.getAttributeValue(null, ATTR_REFERRAL_DEPTH)));
            listener.processReferral(baseUri, referral, referral.getDepth(), 1);
          } else if (TAG_RESOURCE.equals(localName)) {
            resourceBuilder = new ResourceBuilder();

            String bsn = reader.getAttributeValue(null, ATTR_RESOURCE_SYMBOLIC_NAME);
            String versionStr = reader.getAttributeValue(null, ATTR_RESOURCE_VERSION);
            Version version = Version.parseVersion(versionStr);
            String uri = reader.getAttributeValue(null, ATTR_RESOURCE_URI);
            URI resolvedUri = resolveUri(uri, baseUri);
            addBasicCapabilities(resourceBuilder, bsn, version, resolvedUri);
          } else if (TAG_CAPABILITY.equals(localName)) {
            String obrName = reader.getAttributeValue(null, ATTR_NAME);
            String namespace = mapObrNameToR5Namespace(obrName, false);
            capReqBuilder = new CapReqBuilder(namespace);
          } else if (TAG_REQUIRE.equals(localName)) {
            String obrName = reader.getAttributeValue(null, ATTR_NAME);
            boolean extend = "true".equalsIgnoreCase(reader.getAttributeValue(null, ATTR_EXTEND));
            String namespace = mapObrNameToR5Namespace(obrName, extend);
            boolean optional =
                "true".equalsIgnoreCase(reader.getAttributeValue(null, ATTR_OPTIONAL));

            capReqBuilder = new CapReqBuilder(namespace);
            if (optional)
              capReqBuilder.addDirective(
                  Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
            String filter =
                translateObrFilter(namespace, reader.getAttributeValue(null, ATTR_FILTER), log);
            capReqBuilder.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
          } else if (TAG_PROPERTY.equals(localName)) {
            String name = reader.getAttributeValue(null, ATTR_PROPERTY_NAME);
            String typeStr = reader.getAttributeValue(null, ATTR_PROPERTY_TYPE);
            String valueStr = reader.getAttributeValue(null, ATTR_PROPERTY_VALUE);
            if (capReqBuilder != null) {
              name = mapObrPropertyToR5(capReqBuilder.getNamespace(), name);
              if (PROPERTY_USES.equals(name)) capReqBuilder.addDirective(PROPERTY_USES, valueStr);
              else {
                Object value = convertProperty(valueStr, typeStr);
                capReqBuilder.addAttribute(name, value);
              }
            }
          }
          break;
        case END_ELEMENT:
          localName = reader.getLocalName();
          if (TAG_RESOURCE.equals(localName)) {
            if (resourceBuilder != null) {
              Resource resource = resourceBuilder.build();
              listener.processResource(resource);
            }
          } else if (TAG_CAPABILITY.equals(localName)) {
            if (resourceBuilder != null && capReqBuilder != null)
              resourceBuilder.addCapability(capReqBuilder);
            capReqBuilder = null;
          } else if (TAG_REQUIRE.equals(localName)) {
            if (resourceBuilder != null && capReqBuilder != null)
              resourceBuilder.addRequirement(capReqBuilder);
            capReqBuilder = null;
          }
      }
    }
  }
Пример #7
0
 public CapReqBuilder addDirectives(Map<String, String> directives) {
   for (Entry<String, String> e : directives.entrySet()) {
     addDirective(e.getKey(), e.getValue());
   }
   return this;
 }