1 11 package org.eclipse.osgi.internal.resolver; 12 13 import org.eclipse.osgi.service.resolver.*; 14 import org.osgi.framework.*; 15 16 public class GenericSpecificationImpl extends VersionConstraintImpl implements GenericSpecification { 17 private Filter matchingFilter; 18 private String type = GenericDescription.DEFAULT_TYPE; 19 private int resolution = 0; 20 private GenericDescription[] suppliers; 21 22 public String getMatchingFilter() { 23 return matchingFilter == null ? null : matchingFilter.toString(); 24 } 25 26 void setMatchingFilter(String matchingFilter) throws InvalidSyntaxException { 27 this.matchingFilter = matchingFilter == null ? null : FrameworkUtil.createFilter(matchingFilter); 28 } 29 30 public boolean isSatisfiedBy(BaseDescription supplier) { 31 if (!(supplier instanceof GenericDescription)) 32 return false; 33 GenericDescription candidate = (GenericDescription) supplier; 34 if (getName() == null || !getName().equals(candidate.getName())) 35 return false; 36 if (getType() == null || !getType().equals(candidate.getType())) 37 return false; 38 return matchingFilter == null || matchingFilter.match(candidate.getAttributes()); 40 } 41 42 public String toString() { 43 StringBuffer sb = new StringBuffer (); 44 sb.append(StateBuilder.GENERIC_REQUIRE).append(": ").append(getName()); if (getType() != GenericDescription.DEFAULT_TYPE) 46 sb.append(':').append(getType()); 47 if (matchingFilter != null) 48 sb.append("; ").append(getMatchingFilter()); return sb.toString(); 50 } 51 52 public String getType() { 53 return type; 54 } 55 56 void setType(String type) { 57 if (type == null || type.equals(GenericDescription.DEFAULT_TYPE)) 58 this.type = GenericDescription.DEFAULT_TYPE; 59 else 60 this.type = type; 61 } 62 63 public int getResolution() { 64 return resolution; 65 } 66 67 public boolean isResolved() { 68 return suppliers != null && suppliers.length > 0; 69 } 70 71 void setResolution(int resolution) { 72 this.resolution = resolution; 73 } 74 75 public BaseDescription getSupplier() { 76 return suppliers == null || suppliers.length == 0 ? null : suppliers[0]; 77 } 78 79 protected void setSupplier(BaseDescription supplier) { 80 if (supplier == null) { 81 suppliers = null; 82 return; 83 } 84 int len = suppliers == null ? 0 : suppliers.length; 85 GenericDescription[] temp = new GenericDescription[len + 1]; 86 if (suppliers != null) 87 System.arraycopy(suppliers, 0, temp, 0, len); 88 temp[len] = (GenericDescription) supplier; 89 suppliers = temp; 90 } 91 92 public GenericDescription[] getSuppliers() { 93 return suppliers; 94 } 95 96 void setSupplers(GenericDescription[] suppliers) { 97 this.suppliers = suppliers; 98 } 99 } 100 | Popular Tags |