1 9 package org.eclipse.osgi.internal.module; 10 11 import org.eclipse.osgi.service.resolver.BundleDescription; 12 import org.eclipse.osgi.service.resolver.VersionConstraint; 13 14 17 public abstract class ResolverConstraint { 18 final protected ResolverBundle bundle; 19 final protected VersionConstraint constraint; 20 private VersionSupplier[] possibleSuppliers; 21 private int selectedSupplierIndex = 0; 22 23 ResolverConstraint(ResolverBundle bundle, VersionConstraint constraint) { 24 this.bundle = bundle; 25 this.constraint = constraint; 26 } 27 28 ResolverBundle getBundle() { 30 return bundle; 31 } 32 33 BundleDescription getBundleDescription() { 35 return bundle.getBundle(); 36 } 37 38 boolean isFromFragment() { 40 return constraint.getBundle().getHost() != null; 41 } 42 43 boolean isSatisfiedBy(VersionSupplier vs) { 45 if (!bundle.getResolver().getPermissionChecker().checkPermission(constraint, vs.getBaseDescription())) 46 return false; 47 return constraint.isSatisfiedBy(vs.getBaseDescription()); 48 } 49 50 VersionConstraint getVersionConstraint() { 52 return constraint; 53 } 54 55 public String getName() { 57 return constraint.getName(); 58 } 59 60 public String toString() { 61 return constraint.toString(); 62 } 63 64 abstract boolean isOptional(); 66 67 public void setPossibleSuppliers(VersionSupplier[] possibleSuppliers) { 68 this.possibleSuppliers = possibleSuppliers; 69 } 70 71 void addPossibleSupplier(VersionSupplier supplier) { 72 if (supplier == null) 73 return; 74 if (possibleSuppliers == null) { 76 possibleSuppliers = new VersionSupplier[] {supplier}; 77 return; 78 } 79 VersionSupplier[] newSuppliers = new VersionSupplier[possibleSuppliers.length + 1]; 80 System.arraycopy(possibleSuppliers, 0, newSuppliers, 0, possibleSuppliers.length); 81 newSuppliers[possibleSuppliers.length] = supplier; 82 possibleSuppliers = newSuppliers; 83 } 84 85 public void removePossibleSupplier(VersionSupplier supplier) { 86 if (possibleSuppliers == null || supplier == null) 87 return; 88 int index = -1; 89 for (int i = 0; i < possibleSuppliers.length; i++) { 90 if (possibleSuppliers[i] == supplier) { 91 index = i; 92 break; 93 } 94 } 95 if (index >= 0) { 96 if (possibleSuppliers.length == 1) { 97 possibleSuppliers = null; 98 return; 99 } 100 VersionSupplier[] newSuppliers = new VersionSupplier[possibleSuppliers.length - 1]; 101 System.arraycopy(possibleSuppliers, 0, newSuppliers, 0, index); 102 if (index < possibleSuppliers.length - 1) 103 System.arraycopy(possibleSuppliers, index + 1, newSuppliers, index, possibleSuppliers.length - index - 1); 104 possibleSuppliers = newSuppliers; 105 } 106 } 107 108 int getNumPossibleSuppliers() { 109 if (possibleSuppliers == null) 110 return 0; 111 return possibleSuppliers.length; 112 } 113 114 boolean selectNextSupplier() { 115 if (possibleSuppliers == null || selectedSupplierIndex >= possibleSuppliers.length) 116 return false; 117 selectedSupplierIndex += 1; 118 return selectedSupplierIndex < possibleSuppliers.length; 119 } 120 121 VersionSupplier getSelectedSupplier() { 122 if (possibleSuppliers == null || selectedSupplierIndex >= possibleSuppliers.length) 123 return null; 124 return possibleSuppliers[selectedSupplierIndex]; 125 } 126 127 void setSelectedSupplier(int selectedSupplier) { 128 this.selectedSupplierIndex = selectedSupplier; 129 } 130 131 int getSelectedSupplierIndex() { 132 return this.selectedSupplierIndex; 133 } 134 135 VersionSupplier[] getPossibleSuppliers() { 136 return possibleSuppliers; 137 } 138 139 void clearPossibleSuppliers() { 140 possibleSuppliers = null; 141 selectedSupplierIndex = 0; 142 } 143 } 144 | Popular Tags |