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  
23  /***
24   */
25  public abstract class AbstractDependencyNode implements DependencyNode
26  {
27  
28  	//--- Data Field(s) ---
29  
30  	private Object id;
31  	private boolean required;
32  
33  	//--- Constructor(s) ---
34  
35  	public AbstractDependencyNode(Object id)
36  	{
37  		this.id = id;
38  	}
39  
40      //--- Method(s) ---
41  
42  	public Object getID()
43  	{
44  		return id;
45  	}
46  
47  	public boolean isRequired()
48  	{
49  		return required;
50  	}
51  
52  	public void require(boolean requireInstalled)
53  		throws UnsatisfiedDependenciesException
54  	{
55  		if (required) {
56  			// already visited this node
57  			return;
58  		}
59  
60  		required = true;
61  		try {
62  			checkDepends(requireInstalled);
63  		}
64  		catch (UnsatisfiedDependenciesException e) {
65  			required = false;
66  			throw e;
67  		}
68  	}
69  
70  	public abstract void checkDepends(boolean requireInstalled) 
71  		throws UnsatisfiedDependenciesException;
72  
73  	public void setRequired(boolean required)
74  	{
75  		this.required = required;
76  	}
77  
78  	public String toString()
79  	{
80  		return getID().toString();
81  	}
82  
83  }
84