public ModelledResourceImpl()

in subsystem/subsystem-modeller/src/main/java/org/apache/aries/subsystem/modelling/impl/ModelledResourceImpl.java [91:203]


  public ModelledResourceImpl (String fileURI, Attributes bundleAttributes, 
      ResourceType resourceType, ExportedBundle exportedBundle,
      Collection<ImportedService> importedServices, 
      Collection<ExportedService> exportedServices 
      ) throws InvalidAttributeException 
  {
    logger.debug("Method entry: {}, args {}", "ModelledResourceImpl", new Object[]{fileURI, bundleAttributes, importedServices, exportedServices,
        resourceType});

    if (exportedBundle == null) { 
      _exportedBundle = new ExportedBundleImpl (bundleAttributes);
    } else { 
      _exportedBundle = exportedBundle;
    }
    _resourceType = resourceType;
    _fileURI = fileURI;
    if(importedServices != null)
      _importedServices = new ArrayList<ImportedService> (importedServices);
    else
      _importedServices = new ArrayList<ImportedService>();
    
    if(exportedServices != null)
      _exportedServices = new ArrayList<ExportedService> (exportedServices);
    else
      _exportedServices = new ArrayList<ExportedService>();
    
    _exportedPackages = new ArrayList<ExportedPackage>();
    String packageExports = bundleAttributes.getValue(EXPORT_PACKAGE);
    if (packageExports != null) {
      List<NameValuePair> exportedPackages = ManifestHeaderProcessor
        .parseExportString(packageExports);
      for (NameValuePair exportedPackage : exportedPackages) {
        _exportedPackages.add(new ExportedPackageImpl(this, exportedPackage.getName(), 
            new HashMap<String, Object>(exportedPackage.getAttributes())));
    
      }
    }
  
    _importedPackages = new ArrayList<ImportedPackage>();
    String packageImports = bundleAttributes.getValue(IMPORT_PACKAGE);
    if (packageImports != null) {
      Map<String, Map<String, String>> importedPackages = ManifestHeaderProcessor
          .parseImportString(packageImports);
      for (Map.Entry<String, Map<String, String>> importedPackage : importedPackages.entrySet()) {
        Map<String, String> atts = importedPackage.getValue();
        _importedPackages.add(new ImportedPackageImpl(importedPackage.getKey(), atts));
      }
    }
    
    // Use of Import-Service and Export-Service is deprecated in OSGi. We like Blueprint. 
    // Blueprint is good. 
    
    String serviceExports = null; 
    if (_resourceType == ResourceType.BUNDLE) { 
      serviceExports = bundleAttributes.getValue(EXPORT_SERVICE);
    } 
    if (serviceExports != null) {
      List<NameValuePair> expServices = ManifestHeaderProcessor
          .parseExportString(serviceExports);
      for (NameValuePair exportedService : expServices) {
        _exportedServices.add(new ExportedServiceImpl(exportedService.getName(), exportedService.getAttributes()));
      }
    }
  
    String serviceImports =null;
    if (_resourceType == ResourceType.BUNDLE) { 
      serviceImports = bundleAttributes.getValue(IMPORT_SERVICE);
    } 
    if (serviceImports != null) {
      Map<String, Map<String, String>> svcImports = ManifestHeaderProcessor
          .parseImportString(serviceImports);
      for (Map.Entry<String, Map<String, String>> importedService : svcImports.entrySet()) {
        _importedServices.add(new ImportedServiceImpl(importedService.getKey(), importedService.getValue()));
      }
    }
    
    _requiredBundles = new ArrayList<ImportedBundle>();
    // Require-Bundle and DynamicImport-Package relevant to Bundles but not Composites
    if (_resourceType == ResourceType.BUNDLE) { 
      String requireBundleHeader = bundleAttributes.getValue(REQUIRE_BUNDLE);
      if (requireBundleHeader != null) {
        Map<String, Map<String, String>> requiredBundles = ManifestHeaderProcessor
            .parseImportString(requireBundleHeader);
        for (Map.Entry<String, Map<String, String>> bundle : requiredBundles.entrySet()) {
          String type = bundle.getKey();
          Map<String, String> attribs = bundle.getValue();
          // We may parse a manifest with a header like Require-Bundle: bundle.a;bundle-version=3.0.0
          // The filter that we generate is intended for OBR in which case we need (version>=3.0.0) and not (bundle-version>=3.0.0)
          String bundleVersion = attribs.remove(BUNDLE_VERSION_ATTRIBUTE);
          if (bundleVersion != null && attribs.get(VERSION_ATTRIBUTE) == null) { 
            attribs.put (VERSION_ATTRIBUTE, bundleVersion);
          }
          String filter = ManifestHeaderProcessor.generateFilter(ModellingConstants.OBR_SYMBOLIC_NAME, type, attribs);
          Map<String, String> atts = new HashMap<String, String>(bundle.getValue());
          atts.put(ModellingConstants.OBR_SYMBOLIC_NAME,  bundle.getKey());
          _requiredBundles.add(new ImportedBundleImpl(filter, atts));
        }
      }
    
      String dynamicImports = bundleAttributes.getValue(DYNAMICIMPORT_PACKAGE);
      if (dynamicImports != null) {
        Map<String, Map<String, String>> dynamicImportPackages = ManifestHeaderProcessor
            .parseImportString(dynamicImports);
        for (Map.Entry<String, Map<String, String>> dynImportPkg : dynamicImportPackages.entrySet()) {
          if (dynImportPkg.getKey().indexOf("*") == -1) {
            dynImportPkg.getValue().put(RESOLUTION_DIRECTIVE + ":", RESOLUTION_OPTIONAL);
            _importedPackages.add(new ImportedPackageImpl(dynImportPkg.getKey(), dynImportPkg.getValue()));
          }
        }
      }
    }
    logger.debug("Method exit: {}, returning {}", "ModelledResourceImpl");
  }