KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > ast > utils > lib > ExecutorInfo


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.ast.utils.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.ast.api.DeclarationKind;
31 import org.objectweb.openccm.ast.api.Declaration;
32 import org.objectweb.openccm.ast.api.ComponentDecl;
33 import org.objectweb.openccm.ast.api.HomeExecutorDecl;
34 import org.objectweb.openccm.ast.api.ExecutorDecl;
35 import org.objectweb.openccm.ast.api.SegmentDecl;
36 import org.objectweb.openccm.ast.api.InterfacePortDecl;
37 import org.objectweb.openccm.ast.api.EventPortDecl;
38 import java.util.List JavaDoc;
39 import java.util.ArrayList JavaDoc;
40
41 /**
42  * This class provides usefull methods for components.
43  *
44  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
45  *
46  * @version 0.1
47  */

48
49 public class ExecutorInfo
50   implements org.objectweb.openccm.ast.utils.api.ExecutorInfo
51 {
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57

58     /** The executor declaration. */
59     private ExecutorDecl exec_;
60
61     /** The binding component declaration. */
62     private ComponentDecl comp_;
63
64     // ==================================================================
65
//
66
// Constructors.
67
//
68
// ==================================================================
69

70     /**
71      * The default constructor.
72      *
73      * @param exec - The executor declaration.
74      **/

75     public ExecutorInfo(ExecutorDecl exec)
76     {
77         HomeExecutorDecl home_exec = null;
78
79         // Init internal states
80
exec_ = exec;
81
82         // Get the managed component
83
home_exec = (HomeExecutorDecl) exec.getParent();
84         comp_ = home_exec.getHomeType().getManagedComponent();
85     }
86
87     // ==================================================================
88
//
89
// Internal methods.
90
//
91
// ==================================================================
92

93     /**
94      * Remove implemented facets for the list.
95      */

96     protected void
97     removeSegmentFacets( SegmentDecl seg,
98                          List JavaDoc implemented_facets )
99     {
100         ComponentDecl current = null;
101         String JavaDoc[] facets = null;
102         String JavaDoc[] sinks = null;
103
104         // For each facet implemented,
105
// remove the corresponding interface from the list
106
facets = seg.getFacetList().getStrings();
107         for (int i=0; i<facets.length; i++)
108         {
109             InterfacePortDecl itf_port = null;
110
111             current = comp_;
112             while ((itf_port == null) && (current != null))
113             {
114                 itf_port = (InterfacePortDecl) current.lookup(facets[i]);
115                 // Search facet declaration in the base component
116
current = current.getBaseComponent();
117             }
118             implemented_facets.remove(itf_port);
119         }
120
121         // For each sink implemented,
122
// remove the corresponding interface from the list
123
sinks = seg.getSinkList().getStrings();
124         for (int i=0; i<sinks.length; i++)
125         {
126             EventPortDecl event_port = null;
127
128             current = comp_;
129             while ((event_port == null) && (current != null))
130             {
131                 event_port = (EventPortDecl) current.lookup(sinks[i]);
132                 // Search sink declaration in the base component
133
current = current.getBaseComponent();
134             }
135             implemented_facets.remove(event_port);
136         }
137     }
138
139     // ==================================================================
140
//
141
// Public methods for org.objectweb.openccm.generator.cif.api.ComponentInfo.
142
//
143
// ==================================================================
144

145     /**
146      * Get facets and sinks implemented directly by the main segment.
147      * This not include facets and sinks implemented by component's segments.
148      *
149      * @return The facets (or sinks) list.
150      */

151     public Declaration[]
152     getMainSegmentFacets()
153     {
154         Declaration[] decls = null;
155         List JavaDoc implemented_facets = new ArrayList JavaDoc();
156
157         // Get ProvidesDecl and ConsumesDecl to build a list
158
decls = comp_.getContents( false,
159                                    DeclarationKind.dk_provides
160                                    + DeclarationKind.dk_consumes );
161         for (int i=0; i<decls.length; i++)
162         {
163             implemented_facets.add( decls[i] );
164         }
165
166         // Get segments and remove implemented facets & sinks
167
decls = exec_.getContents(true, DeclarationKind.dk_segment);
168         for (int i=0; i<decls.length; i++)
169         {
170             removeSegmentFacets( (SegmentDecl) decls[i],
171                                  implemented_facets );
172         }
173
174         return (Declaration[]) implemented_facets.toArray(new Declaration[0]);
175     }
176
177     // ==================================================================
178
//
179
// Public methods.
180
//
181
// ==================================================================
182

183 }
184
Popular Tags