KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > adl > nodes > RemoteBootstrapLoader


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): Vivien Quema
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.adl.nodes;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.fractal.adl.ADLException;
30 import org.objectweb.fractal.adl.AbstractLoader;
31 import org.objectweb.fractal.adl.Definition;
32 import org.objectweb.fractal.adl.Node;
33 import org.objectweb.fractal.adl.components.Component;
34 import org.objectweb.fractal.adl.components.ComponentContainer;
35 import org.objectweb.fractal.adl.nodes.VirtualNode;
36 import org.objectweb.fractal.adl.nodes.VirtualNodeContainer;
37 import org.objectweb.fractal.rmi.registry.NamingService;
38
39 /**
40  * This class defines a loader that lookups virtual nodes referenced in the AST.
41  */

42 public class RemoteBootstrapLoader extends AbstractLoader
43 {
44
45   /**
46    * @see org.objectweb.fractal.adl.Loader#load(java.lang.String, java.util.Map)
47    */

48   public Definition load(final String JavaDoc name, final Map JavaDoc context)
49       throws ADLException
50   {
51     NamingService ns = (NamingService) context.get("naming-service");
52     Definition d = clientLoader.load(name, context);
53     checkNode((Node) d, ns, context);
54     return d;
55   }
56
57   private void checkNode(final Node node, final NamingService ns,
58       final Map JavaDoc context) throws ADLException
59   {
60     if (node instanceof VirtualNodeContainer)
61     {
62       VirtualNode vn = ((VirtualNodeContainer) node).getVirtualNode();
63       if (vn != null)
64       {
65         String JavaDoc name = vn.getName();
66         if (context.get(name) == null)
67         {
68           if (ns == null)
69           {
70             throw new ADLException(
71                 "Unable to find the naming service in the context", null);
72           }
73           System.out.println("looking for " + name);
74           Object JavaDoc bootstrap = ns.lookup(name);
75           if (bootstrap == null)
76           {
77             throw new ADLException(
78                 "Unable to find the bootstrap component for virtual node "
79                     + name, null);
80           }
81           context.put(name, bootstrap);
82         }
83       }
84     }
85     if (node instanceof ComponentContainer)
86     {
87       ComponentContainer container = (ComponentContainer) node;
88       Component[] tab = container.getComponents();
89       for (int i = 0; i < tab.length; i++)
90       {
91         Component subComponent = tab[i];
92         checkNode((Node) subComponent, ns, context);
93       }
94     }
95   }
96
97 }
Popular Tags