KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > component > controller > ProActiveController


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2004 INRIA/University of Nice-Sophia Antipolis
8  * Contact: proactive-support@inria.fr
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  * Initial developer(s): The ProActive Team
26  * http://www.inria.fr/oasis/ProActive/contacts.html
27  * Contributor(s):
28  *
29  * ################################################################
30  */

31 package org.objectweb.proactive.core.component.controller;
32
33 import org.objectweb.fractal.api.Component;
34 import org.objectweb.fractal.api.Interface;
35 import org.objectweb.fractal.api.NoSuchInterfaceException;
36 import org.objectweb.fractal.api.Type;
37 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
38 import org.objectweb.fractal.api.control.LifeCycleController;
39 import org.objectweb.fractal.api.factory.InstantiationException;
40 import org.objectweb.fractal.api.type.InterfaceType;
41 import org.objectweb.fractal.api.type.TypeFactory;
42
43 import org.objectweb.proactive.core.ProActiveRuntimeException;
44 import org.objectweb.proactive.core.component.Constants;
45 import org.objectweb.proactive.core.component.type.ProActiveTypeFactory;
46
47 import java.io.Serializable JavaDoc;
48
49
50 /**
51  * Base class for all component controllers.
52  *
53  * @author Matthieu Morel
54  *
55  */

56 public abstract class ProActiveController implements Interface, Serializable JavaDoc {
57     private Component owner;
58     private boolean isInternal = true;
59     private InterfaceType interfaceType;
60     private String JavaDoc controllerName;
61
62     /**
63      * Constructor for ProActiveController.
64      * @param owner the component that wants this controller
65      * @param controllerName the name of the controller (the list of controller names
66      * is in the {@link Constants} class.
67      */

68     public ProActiveController(Component owner, String JavaDoc controllerName) {
69         this.owner = owner;
70         //this.interfaceType = interfaceType;
71
this.controllerName = controllerName;
72         try {
73             if (controllerName.equals(Constants.CONTENT_CONTROLLER)) {
74                 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.CONTENT_CONTROLLER,
75                         ProActiveContentController.class.getName(),
76                         TypeFactory.SERVER, TypeFactory.MANDATORY,
77                         TypeFactory.SINGLE);
78             } else if (controllerName.equals(Constants.BINDING_CONTROLLER)) {
79                 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.BINDING_CONTROLLER,
80                         ProActiveBindingController.class.getName(),
81                         TypeFactory.SERVER, TypeFactory.MANDATORY,
82                         TypeFactory.SINGLE);
83             } else if (controllerName.equals(Constants.LIFECYCLE_CONTROLLER)) {
84                 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.LIFECYCLE_CONTROLLER,
85                         ProActiveLifeCycleController.class.getName(),
86                         TypeFactory.SERVER, TypeFactory.MANDATORY,
87                         TypeFactory.SINGLE);
88             } else if (controllerName.equals(
89                         Constants.COMPONENT_PARAMETERS_CONTROLLER)) {
90                 interfaceType = ProActiveTypeFactory.instance().createFcItfType(Constants.COMPONENT_PARAMETERS_CONTROLLER,
91                         ProActiveComponentParametersController.class.getName(),
92                         TypeFactory.SERVER, TypeFactory.MANDATORY,
93                         TypeFactory.SINGLE);
94             } else {
95                 throw new ProActiveRuntimeException("unknown controller");
96             }
97         } catch (InstantiationException JavaDoc e) {
98             throw new ProActiveRuntimeException("cannot create component or interface type",
99                 e);
100         }
101     }
102
103     /**
104      * see {@link org.objectweb.fractal.api.Interface#getFcItfOwner()}
105      */

106     public Component getFcItfOwner() {
107         return owner;
108     }
109
110     /**
111      * see {@link org.objectweb.fractal.api.Interface#isFcInternalItf()}
112      */

113     public boolean isFcInternalItf() {
114         return isInternal;
115     }
116
117     /**
118      * see {@link org.objectweb.fractal.api.Interface#getFcItfName()}
119      */

120     public String JavaDoc getFcItfName() {
121         return controllerName;
122     }
123
124     /**
125      * see {@link org.objectweb.fractal.api.Interface#getFcItfType()}
126      */

127     public Type getFcItfType() {
128         return interfaceType;
129     }
130
131     /**
132      * some control operations are to be performed while the component is stopped
133      */

134     protected void checkLifeCycleIsStopped() throws IllegalLifeCycleException {
135         try {
136             if (!((LifeCycleController) getFcItfOwner().getFcInterface(Constants.LIFECYCLE_CONTROLLER)).getFcState()
137                       .equals(LifeCycleController.STOPPED)) {
138                 throw new IllegalLifeCycleException(
139                     "this control operation should be performed while the component is stopped");
140             }
141         } catch (NoSuchInterfaceException nsie) {
142             throw new ProActiveRuntimeException(
143                 "life cycle controller interface not found");
144         }
145     }
146
147     // // -------------------------------------------------------------------------
148
// // Implementation of the Name interface
149
// // -------------------------------------------------------------------------
150
//
151
// public NamingContext getNamingContext() {
152
// return null;
153
// }
154
//
155
// public byte[] encode() throws NamingException {
156
// throw new NamingException("Unsupported operation");
157
// }
158
}
159
Popular Tags