KickJava   Java API By Example, From Geeks To Geeks.

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


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.type.ComponentType;
30 import org.objectweb.fractal.api.type.InterfaceType;
31
32 import java.util.Map JavaDoc;
33
34 /**
35  * Provides basic type system related checks to a {@link Component}.
36  * <br>
37  * <br>
38  * <b>Requirements</b>
39  * <ul>
40  * <li>the type of the component in which this mixin is used must be an instance
41  * of {@link ComponentType}.</li>
42  * </ul>
43  */

44
45 public abstract class TypeComponentMixin implements Component {
46
47   // -------------------------------------------------------------------------
48
// Private constructor
49
// -------------------------------------------------------------------------
50

51   private TypeComponentMixin () {
52   }
53
54   // -------------------------------------------------------------------------
55
// Fields and methods added and overriden by the mixin class
56
// -------------------------------------------------------------------------
57

58   /**
59    * Checks the interface name against the component's type and then calls the
60    * overriden method. This method also creates the collection interfaces
61    * when needed, and puts them in the {@link #_this_fcInterfaces} map.
62    *
63    * @param interfaceName the name of the external interface that must be
64    * returned.
65    * @return the external interface of the component to which this interface
66    * belongs, whose name is equal to the given name.
67    * @throws NoSuchInterfaceException if there is no such interface.
68    */

69
70   public Object JavaDoc getFcInterface (final String JavaDoc interfaceName)
71     throws NoSuchInterfaceException
72   {
73     if (interfaceName.indexOf('/') != -1) {
74       return _super_getFcInterface(interfaceName);
75     }
76     ComponentType compType = (ComponentType)_this_getFcType();
77     InterfaceType itfType;
78     try {
79       itfType = compType.getFcInterfaceType(interfaceName);
80     } catch (NoSuchInterfaceException e) {
81       throw new ChainedNoSuchInterfaceException(null, this, interfaceName);
82     }
83     Object JavaDoc result;
84     try {
85       result = _super_getFcInterface(interfaceName);
86     } catch (NoSuchInterfaceException e) {
87       if (itfType.isFcCollectionItf()) {
88         result = _super_getFcInterface("/collection/" + itfType.getFcItfName());
89         result = ((ComponentInterface)result).clone();
90         ((ComponentInterface)result).setFcItfName(interfaceName);
91         _this_fcInterfaces.put(interfaceName, result);
92       } else {
93         throw e;
94       }
95     }
96     return result;
97   }
98
99   // -------------------------------------------------------------------------
100
// Fields and methods required by the mixin class in the base class
101
// -------------------------------------------------------------------------
102

103   /**
104    * The <tt>fcInterfaces</tt> field required by this mixin. This field is
105    * supposed to store the interfaces of the component.
106    */

107
108   public Map JavaDoc _this_fcInterfaces;
109
110   /**
111    * The {@link #getFcType getFcType} method required by this mixin.
112    *
113    * @return the type of the component to which this interface belongs.
114    */

115
116   public abstract Type _this_getFcType ();
117
118   /**
119    * The {@link Component#getFcInterface getFcInterface} method overriden by
120    * this mixin.
121    *
122    * @param interfaceName the name of the external interface that must be
123    * returned.
124    * @return the external interface of the component to which this interface
125    * belongs, whose name is equal to the given name.
126    * @throws NoSuchInterfaceException if there is no such interface.
127    */

128
129   public abstract Object JavaDoc _super_getFcInterface (String JavaDoc interfaceName)
130     throws NoSuchInterfaceException;
131 }
132
Popular Tags