1 11 package org.eclipse.osgi.internal.resolver; 12 13 import java.util.*; 14 import org.eclipse.osgi.framework.internal.core.Constants; 15 import org.eclipse.osgi.service.resolver.*; 16 17 public class ImportPackageSpecificationImpl extends VersionConstraintImpl implements ImportPackageSpecification { 18 private String resolution = ImportPackageSpecification.RESOLUTION_STATIC; private String symbolicName; 20 private VersionRange bundleVersionRange; 21 private Map attributes; 22 23 public Map getDirectives() { 24 Map result = new HashMap(5); 25 if (resolution != null) 26 result.put(Constants.RESOLUTION_DIRECTIVE, resolution); 27 return result; 28 } 29 30 public Object getDirective(String key) { 31 if (key.equals(Constants.RESOLUTION_DIRECTIVE)) 32 return resolution; 33 return null; 34 } 35 36 public Object setDirective(String key, Object value) { 37 if (key.equals(Constants.RESOLUTION_DIRECTIVE)) 38 return resolution = (String ) value; 39 return null; 40 } 41 42 public void setDirectives(Map directives) { 43 if (directives == null) 44 return; 45 resolution = (String ) directives.get(Constants.RESOLUTION_DIRECTIVE); 46 } 47 48 public String getBundleSymbolicName() { 49 return symbolicName; 50 } 51 52 public VersionRange getBundleVersionRange() { 53 if (bundleVersionRange == null) 54 return VersionRange.emptyRange; 55 return bundleVersionRange; 56 } 57 58 public Map getAttributes() { 59 return attributes; 60 } 61 62 public boolean isSatisfiedBy(BaseDescription supplier) { 63 if (!(supplier instanceof ExportPackageDescription)) 64 return false; 65 ExportPackageDescriptionImpl pkgDes = (ExportPackageDescriptionImpl) supplier; 66 67 String [] friends = (String []) pkgDes.getDirective(Constants.FRIENDS_DIRECTIVE); 70 Boolean internal = (Boolean ) pkgDes.getDirective(Constants.INTERNAL_DIRECTIVE); 71 if (internal.booleanValue() || friends != null) { 72 boolean strict = ((StateImpl) getBundle().getContainingState()).inStrictMode(); 73 if (strict) { 74 if (internal.booleanValue()) 75 return false; 76 boolean found = false; 77 if (friends != null && getBundle().getSymbolicName() != null) 78 for (int i = 0; i < friends.length; i++) 79 if (getBundle().getSymbolicName().equals(friends[i])) 80 found = true; 81 if (!found) 82 return false; 83 } 84 } 85 86 if (symbolicName != null) { 87 BundleDescription exporter = pkgDes.getExporter(); 88 if (!symbolicName.equals(exporter.getSymbolicName())) 89 return false; 90 if (getBundleVersionRange() != null && !getBundleVersionRange().isIncluded(exporter.getVersion())) 91 return false; 92 } 93 94 String name = getName(); 95 if (!"*".equals(name) && !(name.endsWith(".*") && pkgDes.getName().startsWith(name.substring(0, name.length() - 1))) && !pkgDes.getName().equals(name)) return false; 99 if (getVersionRange() != null && !getVersionRange().isIncluded(pkgDes.getVersion())) 100 return false; 101 102 Map importAttrs = getAttributes(); 103 if (importAttrs != null) { 104 Map exportAttrs = pkgDes.getAttributes(); 105 if (exportAttrs == null) 106 return false; 107 for (Iterator i = importAttrs.keySet().iterator(); i.hasNext();) { 108 String importKey = (String ) i.next(); 109 Object importValue = importAttrs.get(importKey); 110 Object exportValue = exportAttrs.get(importKey); 111 if (exportValue == null || !importValue.equals(exportValue)) 112 return false; 113 } 114 } 115 String [] mandatory = (String []) pkgDes.getDirective(Constants.MANDATORY_DIRECTIVE); 116 if (mandatory != null) { 117 for (int i = 0; i < mandatory.length; i++) { 118 if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(mandatory[i])) { 119 if (symbolicName == null) 120 return false; 121 } else if (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(mandatory[i])) { 122 if (bundleVersionRange == null) 123 return false; 124 } else if (Constants.PACKAGE_SPECIFICATION_VERSION.equals(mandatory[i]) || Constants.VERSION_ATTRIBUTE.equals(mandatory[i])) { 125 if (getVersionRange() == null) 126 return false; 127 } else { if (importAttrs == null) 129 return false; 130 if (importAttrs.get(mandatory[i]) == null) 131 return false; 132 } 133 } 134 } 135 if (((BundleDescriptionImpl)getBundle()).getEquinoxEE() < 0) 137 return true; 138 int eeIndex = ((Integer ) pkgDes.getDirective(ExportPackageDescriptionImpl.EQUINOX_EE)).intValue(); 139 return eeIndex < 0 || eeIndex == ((BundleDescriptionImpl)getBundle()).getEquinoxEE(); 140 } 141 142 protected void setBundleSymbolicName(String symbolicName) { 143 this.symbolicName = symbolicName; 144 } 145 146 protected void setBundleVersionRange(VersionRange bundleVersionRange) { 147 this.bundleVersionRange = bundleVersionRange; 148 } 149 150 protected void setAttributes(Map attributes) { 151 this.attributes = attributes; 152 } 153 154 public String toString() { 155 return "Import-Package: " + getName() + "; version=\"" + getVersionRange() + "\""; } 157 } 158 | Popular Tags |