View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.pkg;
21  
22  import java.util.Collections;
23  import java.util.Iterator;
24  import java.util.LinkedList;
25  
26  import org.xnap.XNap;
27  
28  /***
29   */
30  public class OrDependencyNode extends AbstractDependencyNode
31  {
32  
33  	//--- Data Field(s) ---
34  
35  	private LinkedList depends;
36  
37  	//--- Constructor(s) ---
38  
39  	OrDependencyNode(String token, LinkedList depends)
40  	{
41  		super(token);
42  
43  		this.depends = depends;
44  	}
45  
46  	public OrDependencyNode(String token)
47  	{
48  		this(token, new LinkedList());
49  	}
50  
51      //--- Method(s) ---
52  
53  	public void add(DependencyNode node)
54  	{
55  		depends.add(node);
56  	}
57  
58  	public Iterator children()
59  	{
60  		return depends.iterator();
61  	}
62  
63  	public void checkDepends(boolean requireInstalled)
64  		throws UnsatisfiedDependenciesException
65  	{
66  		// XXX: reverse order to sort child package nodes by higher
67  		// version first, that way the DefaultResolver will pick more recent
68  		// package versions, when determining a packages' classpath
69  		LinkedList list = new LinkedList(depends);
70  		Collections.reverse(list);
71  
72  		if (!requireInstalled) {
73  			// look for installed packages first
74  			for (Iterator i = list.iterator(); i.hasNext();) {
75  				try {
76  					((DependencyNode)i.next()).require(true);
77  					return;
78  				}
79  				catch (UnsatisfiedDependenciesException e) {
80  					// try next
81  				}
82  			}
83  		}
84  
85  		for (Iterator i = list.iterator(); i.hasNext();) {
86  			try {
87  				((DependencyNode)i.next()).require(false);
88  				return;
89  			}
90  			catch (UnsatisfiedDependenciesException e) {
91  				// try next
92  			}
93  		}
94  
95  		throw new UnsatisfiedDependenciesException(getID().toString());
96  	}
97  
98  	public String toString()
99  	{
100 		return XNap.tr("Or");
101 	}
102 
103 }
104