KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > InitializationContext


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 France Telecom R&D
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: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package org.objectweb.fractal.julia;
25
26 import org.objectweb.fractal.api.Component;
27 import org.objectweb.fractal.api.Type;
28 import org.objectweb.fractal.api.factory.InstantiationException;
29
30 import org.objectweb.fractal.julia.factory.ChainedInstantiationException;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36
37 /**
38  * A context used to initialize {@link Controller} objects.
39  * @see Controller#initFcController initFcController
40  */

41
42 public class InitializationContext {
43
44   /**
45    * The type of the component to which the controller object belongs.
46    */

47
48   public Type type;
49
50   /**
51    * The controllers objects of the component to which the controller object
52    * belongs.
53    */

54
55   public List JavaDoc controllers;
56
57   /**
58    * The external interfaces of the component to which the controller object
59    * belongs.
60    */

61
62   public Map JavaDoc interfaces;
63
64   /**
65    * The external interfaces of the component to which the controller object
66    * belongs.
67    */

68
69   public Map JavaDoc internalInterfaces;
70
71   /**
72    * The content of the component to which the controller object belongs.
73    */

74
75   public Object JavaDoc content;
76
77   /**
78    * Miscellaneous additional context information.
79    */

80
81   public Object JavaDoc hints;
82
83   /**
84    * Constructs an uninitialized {@link InitializationContext} object.
85    */

86
87   public InitializationContext () {
88   }
89
90   /**
91    * Initializes and fills in the fields of this object. This method must create
92    * the type, the controller objects and the interfaces of a component. The
93    * default implementation of this method does nothing.
94    *
95    * @throws InstantiationException if the component type, a controller object
96    * or a component interface cannot be created.
97    */

98
99   public void create () throws InstantiationException JavaDoc {
100     controllers = new ArrayList JavaDoc();
101     interfaces = new HashMap JavaDoc();
102     internalInterfaces = new HashMap JavaDoc();
103   }
104
105   /**
106    * Returns the component interface of the {@link #interfaces interfaces} map
107    * whose name is given.
108    *
109    * @param name the name of a component interface.
110    * @return the interface whose name is given.
111    * @throws InstantiationException if there is no such component interface.
112    */

113
114   public Object JavaDoc getInterface (final String JavaDoc name) throws InstantiationException JavaDoc {
115     Object JavaDoc o = getOptionalInterface(name);
116     if (o == null) {
117       throw new ChainedInstantiationException(
118         null,
119         (Component)getOptionalInterface("component"),
120         "Cannot find the required interface '" + name + '\'');
121     }
122     return o;
123   }
124
125   /**
126    * Returns the component interface of the {@link #interfaces interfaces} map
127    * whose name is given.
128    *
129    * @param name the name of a component interface.
130    * @return the interface whose name is given, or <tt>null</tt> if there is no
131    * such component interface.
132    */

133
134   public Object JavaDoc getOptionalInterface (final String JavaDoc name) {
135     Object JavaDoc o = interfaces.get(name);
136     if (o instanceof ComponentInterface) {
137       o = ((ComponentInterface)o).getFcItfImpl();
138     }
139     return o;
140   }
141 }
142
Popular Tags