KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > control > content > Util


1 package org.objectweb.fractal.julia.control.content;
2
3 import org.objectweb.fractal.api.Component;
4 import org.objectweb.fractal.api.NoSuchInterfaceException;
5 import org.objectweb.fractal.api.control.ContentController;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9
10 /**
11  * Provides static utility methods related to {@link ContentController}.
12  */

13
14 public class Util {
15
16   private Util () {
17   }
18
19   /**
20    * Returns all the direct and indirect sub components of the given component.
21    *
22    * @param component a component.
23    * @return all the direct and indirect sub components of the given component.
24    */

25
26   public static List JavaDoc getAllSubComponents (final Component component) {
27     List JavaDoc allSubComponents = new ArrayList JavaDoc();
28     List JavaDoc stack = new ArrayList JavaDoc();
29     stack.add(component);
30     while (stack.size() > 0) {
31       int index = stack.size() - 1;
32       Component c = (Component)stack.get(index);
33       stack.remove(index);
34       if (!allSubComponents.contains(c)) {
35         try {
36           ContentController cc =
37             (ContentController)c.getFcInterface("content-controller");
38           Component[] subComponents = cc.getFcSubComponents();
39           for (int i = subComponents.length - 1; i >= 0; --i) {
40             stack.add(subComponents[i]);
41           }
42         } catch (NoSuchInterfaceException ignored) {
43           // c is not a composite component: nothing to do
44
}
45         allSubComponents.add(c);
46       }
47     }
48     return allSubComponents;
49   }
50 }
51
Popular Tags