KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > lib > FractalHelper


1 /**
2  * Copyright (C) 2001-2005 France Telecom R&D
3  */

4 package org.objectweb.speedo.lib;
5
6 import org.objectweb.fractal.api.Component;
7 import org.objectweb.fractal.api.control.NameController;
8 import org.objectweb.fractal.util.Fractal;
9 import org.objectweb.util.monolog.api.BasicLevel;
10 import org.objectweb.util.monolog.api.Logger;
11
12 import java.util.StringTokenizer JavaDoc;
13
14 /**
15  *
16  *
17  * @author chassase
18  */

19 public class FractalHelper {
20
21     public static Component getSubComponent(Component parent, String JavaDoc path, Logger logger)
22             throws Exception JavaDoc {
23         if (logger != null) {
24             logger.log(BasicLevel.DEBUG, "path: " + path);
25         }
26         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(path, ".", false);
27         Component res = parent;
28         while (st.hasMoreTokens()) {
29             String JavaDoc commponenentname = st.nextToken();
30             Component[] children = Fractal.getContentController(res)
31                     .getFcSubComponents();
32             int i = 0;
33             if (logger != null) {
34                 logger.log(BasicLevel.DEBUG, "search: " + commponenentname);
35             }
36             while (i < children.length
37                     && !Fractal.getNameController(children[i]).getFcName()
38                             .equals(commponenentname)) {
39                 if (logger != null) {
40                     logger.log(BasicLevel.DEBUG, "current: "
41                             + ((NameController) children[i]
42                                     .getFcInterface("name-controller"))
43                                     .getFcName());
44                 }
45                 i++;
46             }
47             if (i < children.length) {
48                 if (logger != null) {
49                     logger.log(BasicLevel.DEBUG, "found: "
50                             + ((NameController) children[i]
51                                     .getFcInterface("name-controller"))
52                                     .getFcName());
53                 }
54                 res = children[i];
55             } else {
56                 if (logger != null) {
57                     logger.log(BasicLevel.DEBUG, "not found");
58                 }
59                 return null;
60             }
61         }
62         return res;
63     }
64
65 }
Popular Tags