KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > julia > control > content > TypeContentMixin


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.control.content;
25
26 import org.objectweb.fractal.api.Component;
27 import org.objectweb.fractal.api.NoSuchInterfaceException;
28 import org.objectweb.fractal.api.control.ContentController;
29 import org.objectweb.fractal.api.type.ComponentType;
30 import org.objectweb.fractal.api.type.InterfaceType;
31
32 import org.objectweb.fractal.julia.ChainedNoSuchInterfaceException;
33 import org.objectweb.fractal.julia.ComponentInterface;
34
35 import java.util.Map JavaDoc;
36
37 /**
38  * Provides basic type system related checks to a {@link ContentController}.
39  * <br>
40  * <br>
41  * <b>Requirements</b>
42  * <ul>
43  * <li>the component to which this controller object belongs must provide the
44  * {@link Component} interface.</li>
45  * <li>the type of the component in which this mixin is used must be an instance
46  * of {@link ComponentType}.</li>
47  * </ul>
48  */

49
50 public abstract class TypeContentMixin implements ContentController {
51
52   // -------------------------------------------------------------------------
53
// Private constructor
54
// -------------------------------------------------------------------------
55

56   private TypeContentMixin () {
57   }
58
59   // -------------------------------------------------------------------------
60
// Fields and methods added and overriden by the mixin class
61
// -------------------------------------------------------------------------
62

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

74
75   public Object JavaDoc getFcInternalInterface (final String JavaDoc interfaceName)
76     throws NoSuchInterfaceException
77   {
78     ComponentType compType = (ComponentType)_this_weaveableC.getFcType();
79     InterfaceType itfType;
80     try {
81       itfType = compType.getFcInterfaceType(interfaceName);
82     } catch (NoSuchInterfaceException e) {
83       throw new ChainedNoSuchInterfaceException(
84         null, _this_weaveableC, interfaceName);
85     }
86     Object JavaDoc result;
87     try {
88       result = _super_getFcInternalInterface(interfaceName);
89     } catch (NoSuchInterfaceException e) {
90       if (itfType.isFcCollectionItf()) {
91         String JavaDoc collectionName = "/collection/" + itfType.getFcItfName();
92         result = _super_getFcInternalInterface(collectionName);
93         result = ((ComponentInterface)result).clone();
94         ((ComponentInterface)result).setFcItfName(interfaceName);
95         _this_fcInternalInterfaces.put(interfaceName, result);
96       } else {
97         throw e;
98       }
99     }
100     return result;
101   }
102
103   // -------------------------------------------------------------------------
104
// Fields and methods required by the mixin class in the base class
105
// -------------------------------------------------------------------------
106

107   /**
108    * The <tt>weaveableC</tt> field required by this mixin. This field is
109    * supposed to reference the {@link Component} interface of the component to
110    * which this controller object belongs.
111    */

112
113   public Component _this_weaveableC;
114
115   /**
116    * The <tt>fcInterfaces</tt> field required by this mixin. This field is
117    * supposed to store the internal interfaces of the component.
118    */

119
120   public Map JavaDoc _this_fcInternalInterfaces;
121
122   /**
123    * The {@link ContentController#getFcInternalInterface getFcInternalInterface}
124    * method overriden by this mixin.
125    *
126    * @param interfaceName the name of the internal interface that must be
127    * returned.
128    * @return the internal interface of the component to which this interface
129    * belongs, whose name is equal to the given name.
130    * @throws NoSuchInterfaceException if there is no such interface.
131    */

132
133   public abstract Object JavaDoc _super_getFcInternalInterface (String JavaDoc interfaceName)
134     throws NoSuchInterfaceException ;
135 }
136
Popular Tags