KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dependencies > ResolutionVisitor


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.core.internal.dependencies;
13
14 import java.util.*;
15
16 public class ResolutionVisitor implements IElementSetVisitor {
17     private int order;
18
19     public ResolutionVisitor(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 there are no pre-requisites, all selected versions are resolved
37
if (elementSet.getRequired().isEmpty()) {
38             elementSet.setResolved(elementSet.getSelected());
39             return;
40         }
41         Set resolved = new HashSet();
42
43         for (Iterator elementsIter = elementSet.getSelected().iterator(); elementsIter.hasNext();) {
44             Element element = (Element) elementsIter.next();
45             Dependency[] dependencies = element.getDependencies();
46             boolean versionResolved = true;
47             for (int i = 0; i < dependencies.length; i++) {
48                 ElementSet requiredNode = elementSet.getSystem().getElementSet(dependencies[i].getRequiredObjectId());
49                 List requiredNodeResolvedVersions = new ArrayList(requiredNode.getResolved());
50                 Object JavaDoc highestRequiredVersionId = null;
51                 for (Iterator requiredNodeResolvedVersionsIter = requiredNodeResolvedVersions.iterator(); requiredNodeResolvedVersionsIter.hasNext();) {
52                     Element requiredResolvedVersion = (Element) requiredNodeResolvedVersionsIter.next();
53                     if (dependencies[i].getMatchRule().isSatisfied(dependencies[i].getUserObject(), requiredResolvedVersion.getVersionId()))
54                         if (highestRequiredVersionId == null || elementSet.getSystem().compare(requiredResolvedVersion.getVersionId(), highestRequiredVersionId) > 0)
55                             highestRequiredVersionId = requiredResolvedVersion.getVersionId();
56                 }
57                 if (highestRequiredVersionId == null && !dependencies[i].isOptional()) {
58                     versionResolved = false;
59                     break;
60                 }
61                 // new version id will be null if dependency cannot be satisfied but is optional
62
elementSet.resolveDependency(dependencies[i], highestRequiredVersionId);
63             }
64             if (versionResolved)
65                 resolved.add(element);
66         }
67         elementSet.setResolved(resolved);
68     }
69 }
Popular Tags