KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > adl > FractalResolver


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.adl;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.adl.legacy.ComponentNotFoundException;
30 import org.objectweb.fractal.api.Component;
31 import org.objectweb.fractal.api.NoSuchInterfaceException;
32 import org.objectweb.fractal.api.control.ContentController;
33 import org.objectweb.fractal.api.control.NameController;
34 import org.objectweb.fractal.util.Fractal;
35
36 /**
37  * Resolver component to find sub component in a composite.
38  */

39 public class FractalResolver implements Resolver
40 {
41
42   /**
43    * The <code>namingContext</code> object is used as a composite component.
44    * The <code>name</code> paramaeter is a name of a sub component. <br>
45    * This method returns a sub component of the given composite with the
46    * specified name.
47    *
48    * @see Resolver#resolve(Object, String, Map)
49    */

50   public Object JavaDoc resolve(Object JavaDoc namingContext, String JavaDoc name, Map JavaDoc context)
51       throws ComponentNotFoundException
52   {
53     Component composite = (Component) namingContext;
54     ContentController cc;
55     try
56     {
57       cc = Fractal.getContentController(composite);
58     }
59     catch (NoSuchInterfaceException e)
60     {
61       throw new ComponentNotFoundException(
62           "The given component doesn't have a Content Controller", context,
63           name);
64     }
65     Component subComponents[] = cc.getFcSubComponents();
66     for (int i = 0; i < subComponents.length; i++)
67     {
68       Component subComponent = subComponents[i];
69       NameController nc;
70       try
71       {
72         nc = Fractal.getNameController(subComponent);
73       }
74       catch (NoSuchInterfaceException e1)
75       {
76         break;
77       }
78       if (nc.getFcName().equals(name))
79       {
80         return subComponent;
81       }
82     }
83     throw new ComponentNotFoundException(
84         "Unable to find sub component with the given name", context, name);
85   }
86
87 }
Popular Tags