1 11 12 package org.eclipse.core.internal.dependencies; 13 14 import java.util.*; 15 16 public class SatisfactionVisitor implements IElementSetVisitor { 17 private int order; 18 19 public SatisfactionVisitor(int order) { 20 this.order = order; 21 } 22 23 public Collection getAncestors(ElementSet elementSet) { 24 return elementSet.getRequired(); 25 } 26 27 public Collection getDescendants(ElementSet elementSet) { 28 return elementSet.getRequiring(); 29 } 30 31 public int getOrder() { 32 return order; 33 } 34 35 public void update(ElementSet elementSet) { 36 if (elementSet.getRequired().isEmpty()) { 38 elementSet.setSatisfied(elementSet.getAvailable()); 39 return; 40 } 41 42 Set satisfied = new HashSet(); 43 for (Iterator elementsIter = elementSet.getAvailable().iterator(); elementsIter.hasNext();) { 44 Element element = (Element) elementsIter.next(); 45 Dependency[] dependencies = element.getDependencies(); 46 boolean versionSatisfied = true; 47 for (int i = 0; i < dependencies.length; i++) { 48 if (dependencies[i].isOptional()) 50 continue; 51 52 ElementSet requiredNode = elementSet.getSystem().getElementSet(dependencies[i].getRequiredObjectId()); 53 54 Collection requiredNodeSatisfiedVersions = requiredNode.getSatisfied(); 55 boolean depSatisfied = false; 56 for (Iterator requiredNodeSatisfiedVersionsIter = requiredNodeSatisfiedVersions.iterator(); requiredNodeSatisfiedVersionsIter.hasNext();) { 57 Element requiredSatisfiedVersion = (Element) requiredNodeSatisfiedVersionsIter.next(); 58 if (dependencies[i].getMatchRule().isSatisfied(dependencies[i].getUserObject(), requiredSatisfiedVersion.getVersionId())) { 59 depSatisfied = true; 60 break; 61 } 62 } 63 if (!depSatisfied) { 64 versionSatisfied = false; 65 break; 66 } 67 } 68 if (versionSatisfied) 69 satisfied.add(element); 70 } 71 elementSet.setSatisfied(satisfied); 72 } 73 74 } | Popular Tags |