KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > archie > strategy > FindRootStrategy


1 package org.sapia.archie.strategy;
2
3 import org.sapia.archie.Name;
4 import org.sapia.archie.Node;
5 import org.sapia.archie.NotFoundException;
6 import org.sapia.archie.ProcessingException;
7
8
9 /**
10  * A lookup strategy that is meant to return the root <code>Node</code>
11  * of a given node hierarchy.
12  *
13  * @author Yanick Duchesne
14  *
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class FindRootStrategy implements LookupStrategy {
22   
23   /**
24    * Returns the root <code>Node</code> of the hierarchy of which the
25    * given "from" <code>Node</code> is part.
26    *
27    * @see LookupStrategy#lookup(Name, Node)
28    */

29   public Object JavaDoc lookup(Name n, Node from)
30                 throws NotFoundException, ProcessingException {
31     Node current = from;
32
33     while (current.getParent() != null) {
34       current = current.getParent();
35     }
36
37     return current;
38   }
39 }
40
Popular Tags