Package org.osgi.service.indexer

Examples of org.osgi.service.indexer.Resource


  }
 
 
  private Tag generateResource(File file, Map<String, String> config) throws Exception {

    Resource resource = null;
    synchronized (recognizers) {
      for(ResourceRecognizer recognizer : recognizers){
        resource = recognizer.recognizeResource(file, resource);
      }
    }
    if(resource == null){
      throw new IllegalStateException("Failed to recognize resource: " + file.getAbsolutePath());
    }
   
    List<Capability> caps = new AddOnlyList<Capability>(new LinkedList<Capability>());
    List<Requirement> reqs = new AddOnlyList<Requirement>(new LinkedList<Requirement>());
   
    // Read config settings and save in thread local state
    if (config != null) {
      URL rootURL;
      String rootURLStr = config.get(ResourceIndexer.ROOT_URL);
      if (rootURLStr != null) {
        File rootDir = new File(rootURLStr);
        if (rootDir.isDirectory())
          rootURL = rootDir.toURI().toURL();
        else
          rootURL = new URL(rootURLStr);
      }
      else
        rootURL = new File(System.getProperty("user.dir")).toURI().toURL();
     
      String urlTemplate = config.get(ResourceIndexer.URL_TEMPLATE);
      bundleAnalyzer.setStateLocal(new GeneratorState(rootURL, urlTemplate));
      defaultAnalyzer.setStateLocal(new GeneratorState(rootURL, urlTemplate));
    } else {
      bundleAnalyzer.setStateLocal(null);
      defaultAnalyzer.setStateLocal(null);
    }
   
    // Iterate over the analyzers
    try {
      synchronized (analyzers) {
        for (Pair<ResourceAnalyzer, Filter> entry : analyzers) {
          ResourceAnalyzer analyzer = entry.getFirst();
          Filter filter = entry.getSecond();
         
          if (filter == null || filter.match(resource.getProperties())) {
            try {
              analyzer.analyzeResource(resource, caps, reqs);
            } catch (Exception e) {
              log(LogService.LOG_ERROR, MessageFormat.format("Error calling analyzer \"{0}\" on resource {1}.", analyzer.getClass().getName(), resource.getLocation()), e);
            }
          }
        }
      }
    } finally {
View Full Code Here


  }

  public Manifest getManifest() throws IOException {
    synchronized (this) {
      if (manifest == null) {
        Resource manifestResource = getChild("META-INF/MANIFEST.MF");
        if (manifestResource != null) {
          try {
            manifest = new Manifest(manifestResource.getStream());
          } finally {
            manifestResource.close();
          }
        }
      }
    }
    return manifest;
View Full Code Here

  }

  public Manifest getManifest() throws IOException {
    synchronized (this) {
      if (manifest == null) {
        Resource manifestResource = getChild("META-INF/MANIFEST.MF");
        if (manifestResource != null) {
          try {
            manifest = new Manifest(manifestResource.getStream());
          } finally {
            manifestResource.close();
          }
        }
      }
      return manifest;
    }
View Full Code Here

  public OSGiFrameworkAnalyzer(LogService log) {
    this.log = log;
  }

  public void analyzeResource(Resource resource, List<Capability> caps, List<Requirement> reqs) throws Exception {
    Resource fwkFactorySvc = resource.getChild(SERVICE_FRAMEWORK_FACTORY);
    if (fwkFactorySvc != null) {
      Builder builder = new Builder().setNamespace(Namespaces.NS_CONTRACT).addAttribute(Namespaces.NS_CONTRACT, Namespaces.CONTRACT_OSGI_FRAMEWORK);

      Version specVersion = null;
      StringBuilder uses = new StringBuilder();
View Full Code Here

      reqs.add(requirement);
    }
  }
 
  private Version processScrXml(Resource resource, String path) throws IOException {
    Resource childResource = resource.getChild(path);
    if (childResource == null) {
      if (log != null) log.log(LogService.LOG_WARNING, MessageFormat.format("Cannot analyse SCR requirement version: resource {0} does not contain path {1} referred from Service-Component header.", resource.getLocation(), path));
      return null;
    }
   
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
   
    try {
      SAXParser parser = spf.newSAXParser();
      SCRContentHandler handler = new SCRContentHandler();
      parser.parse(childResource.getStream(), handler);
     
      return handler.highest;
    } catch (Exception e) {
      if (log != null)
        log.log(LogService.LOG_ERROR, MessageFormat.format("Processing error: failed to parse child resource {0} in resource {1}.", path, resource.getLocation()), e);
View Full Code Here

  }

  public Manifest getManifest() throws IOException {
    synchronized (this) {
      if (manifest == null) {
        Resource manifestResource = getChild("META-INF/MANIFEST.MF");
        if (manifestResource != null) {
          try {
            manifest = new Manifest(manifestResource.getStream());
          } finally {
            manifestResource.close();
          }
        }
      }
    }
    return manifest;
View Full Code Here

    String path = attribs.getValue(Constants.BUNDLE_LOCALIZATION);
    if (path == null)
      path = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
    path += ".properties";
   
    Resource propsResource = resource.getChild(path);
    if (propsResource != null) {
      try {
        props.load(propsResource.getStream());
      } finally {
        propsResource.close();
      }
    }
   
    return props;
  }
View Full Code Here

  public OSGiFrameworkAnalyzer(LogService log) {
    this.log = log;
  }

  public void analyzeResource(Resource resource, List<Capability> caps, List<Requirement> reqs) throws Exception {
    Resource fwkFactorySvc = resource.getChild(SERVICE_FRAMEWORK_FACTORY);
    if (fwkFactorySvc != null) {
      Builder builder = new Builder().setNamespace(Namespaces.NS_CONTRACT).addAttribute(Namespaces.NS_CONTRACT, Namespaces.CONTRACT_OSGI_FRAMEWORK);

      Version specVersion = null;
      StringBuilder uses = new StringBuilder();
View Full Code Here

      reqs.add(requirement);
    }
  }
 
  private Version processScrXml(Resource resource, String path) throws IOException {
    Resource childResource = resource.getChild(path);
    if (childResource == null) {
      if (log != null) log.log(LogService.LOG_WARNING, MessageFormat.format("Cannot analyse SCR requirement version: resource {0} does not contain path {1} referred from Service-Component header.", resource.getLocation(), path));
      return null;
    }
   
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
   
    try {
      SAXParser parser = spf.newSAXParser();
      SCRContentHandler handler = new SCRContentHandler();
      parser.parse(childResource.getStream(), handler);
     
      return handler.highest;
    } catch (Exception e) {
      if (log != null)
        log.log(LogService.LOG_ERROR, MessageFormat.format("Processing error: failed to parse child resource {0} in resource {1}.", path, resource.getLocation()), e);
View Full Code Here

      reqs.add(requirement);
    }
  }

  private Version processScrXml(Resource resource, String path) throws IOException {
    Resource childResource = resource.getChild(path);
    if (childResource == null) {
      if (log != null)
        log.log(LogService.LOG_WARNING,
            MessageFormat.format("Cannot analyse SCR requirement version: resource {0} does not contain path {1} referred from Service-Component header.",
                resource.getLocation(), path));
      return null;
    }

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);

    try {
      SAXParser parser = spf.newSAXParser();
      SCRContentHandler handler = new SCRContentHandler();
      parser.parse(childResource.getStream(), handler);

      return handler.highest;
    } catch (Exception e) {
      if (log != null)
        log.log(LogService.LOG_ERROR, MessageFormat.format("Processing error: failed to parse child resource {0} in resource {1}.", path, resource.getLocation()), e);
View Full Code Here

TOP

Related Classes of org.osgi.service.indexer.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.