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.commons.pkg;
21  
22  import java.util.Collections;
23  import java.util.Iterator;
24  import java.util.LinkedList;
25  import org.xnap.commons.i18n.I18n;
26  
27  /***
28   */
29  public class OrDependencyNode extends AbstractDependencyNode
30  {
31  
32  	//--- Data Field(s) ---
33  
34  	private LinkedList depends;
35  
36  	//--- Constructor(s) ---
37  
38  	OrDependencyNode(String token, LinkedList depends)
39  	{
40  		super(token);
41  
42  		this.depends = depends;
43  	}
44  
45  	public OrDependencyNode(String token)
46  	{
47  		this(token, new LinkedList());
48  	}
49  
50      //--- Method(s) ---
51  
52  	public void add(DependencyNode node)
53  	{
54  		depends.add(node);
55  	}
56  
57  	public Iterator children()
58  	{
59  		return depends.iterator();
60  	}
61  
62  	public void checkDepends(boolean requireInstalled)
63  		throws UnsatisfiedDependenciesException
64  	{
65  		// XXX: reverse order to sort child package nodes by higher
66  		// version first, that way the DefaultResolver will pick more recent
67  		// package versions, when determining a packages' classpath
68  		LinkedList list = new LinkedList(depends);
69  		Collections.reverse(list);
70  
71  		if (!requireInstalled) {
72  			// look for installed packages first
73  			for (Iterator i = list.iterator(); i.hasNext();) {
74  				try {
75  					((DependencyNode)i.next()).require(true);
76  					return;
77  				}
78  				catch (UnsatisfiedDependenciesException e) {
79  					// try next
80  				}
81  			}
82  		}
83  
84  		for (Iterator i = list.iterator(); i.hasNext();) {
85  			try {
86  				((DependencyNode)i.next()).require(false);
87  				return;
88  			}
89  			catch (UnsatisfiedDependenciesException e) {
90  				// try next
91  			}
92  		}
93  
94  		throw new UnsatisfiedDependenciesException(getID().toString());
95  	}
96  
97  	public String toString()
98  	{
99  		return I18n.tr("Or");
100 	}
101 
102 }
103