KickJava   Java API By Example, From Geeks To Geeks.

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


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.NoSuchInterfaceException;
28 import org.objectweb.fractal.api.Type;
29 import org.objectweb.fractal.api.factory.InstantiationException;
30
31 import java.util.Map JavaDoc;
32
33 /**
34  * Provides a basic implementation of the {@link Component} interface.
35  * <br>
36  * <br>
37  * <b>Requirements</b>
38  * <ul>
39  * <li>none.</li>
40  * </ul>
41  */

42
43 public abstract class BasicComponentMixin implements Controller, Component {
44
45   // -------------------------------------------------------------------------
46
// Private constructor
47
// -------------------------------------------------------------------------
48

49   private BasicComponentMixin () {
50   }
51
52   // -------------------------------------------------------------------------
53
// Fields and methods added and overriden by the mixin class
54
// -------------------------------------------------------------------------
55

56   /**
57    * The type of this component.
58    */

59
60   public Type fcType;
61
62   /**
63    * The interfaces of this component. This map associates each interface to its
64    * name.
65    */

66
67   public Map JavaDoc fcInterfaces;
68
69   /**
70    * Initializes the fields of this mixin from the given context, and then calls
71    * the overriden method.
72    *
73    * @param ic information about the component to which this controller object
74    * belongs.
75    * @throws InstantiationException if the initialization fails.
76    */

77
78   public void initFcController (final InitializationContext ic)
79     throws InstantiationException JavaDoc
80   {
81     this.fcType = ic.type;
82     this.fcInterfaces = ic.interfaces;
83     _super_initFcController(ic);
84   }
85
86   public Type getFcType () {
87     return fcType;
88   }
89
90   public Object JavaDoc[] getFcInterfaces () {
91     if (fcInterfaces == null) {
92       return new Object JavaDoc[0];
93     }
94     // returns the names of all the public interfaces in fcInterfaces
95
// interfaces whose name begins with '/' are private
96
int size = 0;
97     String JavaDoc[] names = new String JavaDoc[fcInterfaces.size()];
98     names = (String JavaDoc[])fcInterfaces.keySet().toArray(names);
99     for (int i = 0; i < names.length; ++i) {
100       if (names[i].charAt(0) != '/') {
101         ++size;
102       }
103     }
104     int index = 0;
105     Object JavaDoc[] itfs = new Object JavaDoc[size];
106     for (int i = 0; i < names.length; ++i) {
107       if (names[i].charAt(0) != '/') {
108         itfs[index++] = fcInterfaces.get(names[i]);
109       }
110     }
111     return itfs;
112   }
113
114   public Object JavaDoc getFcInterface (final String JavaDoc interfaceName)
115     throws NoSuchInterfaceException
116   {
117     Object JavaDoc itf = fcInterfaces == null ? null : fcInterfaces.get(interfaceName);
118     if (itf == null) {
119       throw new ChainedNoSuchInterfaceException(null, this, interfaceName);
120     }
121     return itf;
122   }
123
124   // -------------------------------------------------------------------------
125
// Fields and methods required by the mixin class in the base class
126
// -------------------------------------------------------------------------
127

128   /**
129    * The {@link Controller#initFcController initFcController} method overriden
130    * by this mixin.
131    *
132    * @param ic information about the component to which this controller object
133    * belongs.
134    * @throws InstantiationException if the initialization fails.
135    */

136
137   public abstract void _super_initFcController (InitializationContext ic)
138     throws InstantiationException JavaDoc;
139 }
140
Popular Tags