KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > OpenCCM_DCI > cif > AssemblyXMLSegImpl


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): Briclet Fr?d?ric.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27
28
29 package org.objectweb.openccm.OpenCCM_DCI.cif;
30
31 import org.objectweb.openccm.OpenCCM_DCI.*;
32 // Package dependencies
33

34 //import org.objectweb.openccm.descriptor.componentassembly.ccm.*;
35
import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.root.*;
36 import org.objectweb.openccm.descriptor.componentassembly.beans.*;
37
38 public class AssemblyXMLSegImpl
39     extends org.objectweb.openccm.OpenCCM_DCI.
40              AssemblyManagerSessionComposition.AssemblySeg
41 {
42     
43      // xml handler path
44
private String JavaDoc xml;
45     
46     // Console for emittion of message
47
private org.objectweb.util.cmdline.api.Console console;
48     
49     //Root of xml tree cad representation
50
private ComponentassemblyBean assemblyObject;
51     
52     //Table of component handle order by id key
53
private java.util.Hashtable JavaDoc general;
54     
55     // State of the assembly
56
private Assembly etat;
57     
58     // The assembly manager component
59
private AssemblyManager am;
60
61     public void setupXML(String JavaDoc xml){
62         this.xml=xml;
63         general=new java.util.Hashtable JavaDoc();
64         etat=new AssemblyImplInactive();
65     }
66         
67     public void
68     setupAssemblyManager(org.objectweb.openccm.OpenCCM_DCI.AssemblyManager am){
69         this.am=am;
70     }
71     
72     
73     /**
74      * Inactive state for the assembly
75      */

76     private class AssemblyImplInactive implements Assembly
77     {
78
79         public void setupDeployTable()
80         {
81             try{
82                 general.put("__home_finder__",get_context().get_connection_home_finder());
83                 general.put("__home_registration__",get_context().get_connection_home_registration());
84                 general.put("__name_service__",get_context().get_connection_naming_service());
85                 general.put("__dci_information__",get_context().get_connection_dci_information());
86                 general.put("__assembly_manager__",am);
87                 general.put("__component_list__",new java.util.LinkedList JavaDoc());
88                 //general.put("__trader__",get_context().get_connection_trader());
89
}
90             catch(Exception JavaDoc e){
91                 System.err.println("Problem occured during setting of the deployTable");
92             }
93         }
94
95
96     public void build() throws org.omg.Components.CreateFailure {
97         try{
98         
99         //console.message("Load the tree");
100
loadCADTree();
101
102         setupDeployTable();
103
104         /*SAve usefull information to deployment*/
105         //general.put("BaseDir",org.objectweb.openccm.deploytool.DeploymentProcess.getBaseDir());
106
//general.put("__Console__",console);
107
/*Start the deployment operation*/
108         
109         ComponentassemblyDeployer cad=
110                        ((ComponentassemblyDeployer)
111                          ((ComponentassemblyDeployerHandler)
112                         assemblyObject
113                         .getExtensionManager().getExtensionByName("ccm.Deployer"))
114                         .getInstance((ComponentassemblyBeanImpl)assemblyObject));
115                  
116         //cad.deploy(general);
117

118         
119         /*Setup the component to configuration complete state*/
120         for (java.util.ListIterator JavaDoc it =((java.util.LinkedList JavaDoc)
121                                          general.get("__component_list__")).listIterator(0);
122              it.hasNext() ; )
123             {
124                 try {
125                     ((org.omg.Components.CCMObject)
126                      general.get((String JavaDoc)it.next())).configuration_complete();
127                 }
128                 catch (java.lang.ClassCastException JavaDoc exception) {
129                     /*Nothing to do for non component objet like console*/
130                 }
131                 catch (org.omg.Components.InvalidConfiguration exception)
132                     {
133                         exception.printStackTrace();
134                         //console.error("Could not switch a CCM Object to configuration complete");
135
return ;
136                     }
137             }
138         }
139         catch(Exception JavaDoc e)
140             {
141                 e.printStackTrace(); throw new org.omg.Components.CreateFailure();
142             }
143         etat=(Assembly) new AssemblyImplActive();
144         registerAssembly() ;
145     }
146     
147     
148     /**
149      * Private function allowing inactive assembly to load
150      * tree representation of the xml cad file
151      */

152     private void loadCADTree()throws org.omg.Components.CreateFailure
153     {
154         // get the ORB
155
org.omg.CORBA.ORB JavaDoc orb
156         = org.objectweb.openccm.corba.TheORB.getORB();
157         //console.message("Got the ORB");
158

159         // inits OpenCCM runtime
160
org.objectweb.openccm.Components.Runtime.init (orb);
161         //console.message("OpenCCM runtime is ready");
162

163         /*Creating the java file like with .CAD file*/
164         java.io.StringReader JavaDoc reader= new java.io.StringReader JavaDoc (xml);
165         
166         try {
167             assemblyObject
168             = org.objectweb.openccm.descriptor.componentassembly.beans.ComponentassemblyBeanImpl
169             .unmarshalBean(reader,true);
170         } catch (java.io.IOException JavaDoc ex)
171         {
172             ex.printStackTrace();
173             console.error("Could not unmarshal the assembly file");
174             throw new org.omg.Components.CreateFailure();
175         }
176         //console.message("Got the assembly descriptor");
177
}
178     
179     /**
180      * Break connection between composant and destroy them
181      */

182     public void tear_down() throws org.omg.Components.RemoveFailure
183     {
184         throw new org.omg.Components.RemoveFailure();
185     }
186     
187     /**
188      * Return the current assembly state
189      */

190     public org.omg.Components.Deployment.AssemblyState get_state()
191     {
192         return org.omg.Components.Deployment.AssemblyState.INACTIVE;
193         
194     }
195     }
196     
197     /**
198      * Internal class which represent an deploied assembly, only
199      * tear_down() and get_state() operation are available
200      */

201     private class AssemblyImplActive implements Assembly{
202     /**
203      * Alway thrown CreateFailure exception because the assembly
204      * is already deploied. This function is non available
205      */

206     public void build() throws org.omg.Components.CreateFailure
207     {
208         throw new org.omg.Components.CreateFailure();
209     }
210     
211     /**
212      * Tear_down the assembly in 2 part:
213      * First tear_down connections
214      * Secondly erease instantiation
215      * Switch the internal state of the assembly to inactive state.
216      */

217     public void tear_down() throws org.omg.Components.RemoveFailure
218     {
219         try{
220                  
221            ComponentassemblyDeployer cad=
222                           ((ComponentassemblyDeployer)
223                             ((ComponentassemblyDeployerHandler)
224                            assemblyObject
225                            .getExtensionManager().getExtensionByName("ccm.Deployer"))
226                                            .getInstance((ComponentassemblyBeanImpl)assemblyObject));
227  
228            cad.tearDown();
229                    
230            etat=(Assembly)new AssemblyImplInactive();
231         
232         }
233         catch(Exception JavaDoc e){e.printStackTrace();}
234         
235     }
236     
237     /**
238      * Break connection between composant and destroy them
239      */

240     public org.omg.Components.Deployment.AssemblyState get_state()
241     {
242         return org.omg.Components.Deployment.AssemblyState.INSERVICE;
243     }
244     }
245     
246     /**
247      *Internal function to register the assembly with the specified name in cad descriptor
248      * in order to retrieve and tear_down the assembly later.
249      */

250     private void
251     registerAssembly()
252     {
253         // retrieve the corba reference from the assembly object
254
/*org.omg.CORBA.Object ref =
255           this._this_object(org.objectweb.openccm.corba.TheORB.getORB());
256           
257           org.omg.Components.Deployment.Assembly assemblyRef =
258           org.omg.Components.Deployment.AssemblyHelper.narrow(ref);*/

259         
260         org.omg.Components.Deployment.Assembly assemblyRef=
261             ((org.objectweb.openccm.OpenCCM_DCI.AssemblyManagerCCM)get_context())
262             .provide_assembly();
263         
264         // Obtain the Name Service.
265
org.objectweb.openccm.corba.NamingContext ns =
266             org.objectweb.openccm.corba.TheNameService.getNamingContext();
267         
268         // Bind the server object in the name service.
269
ns.rebind(assemblyObject.getId(), assemblyRef);
270         System.out.println("Assembly {"+assemblyObject.getId()+"} is referenced");
271     }
272     
273     /*Delegation operation to the state assembly*/
274     public void
275     build()
276     throws org.omg.Components.CreateFailure
277     {
278         etat.build();
279     }
280     
281     public void
282     tear_down()
283     throws org.omg.Components.RemoveFailure
284     {
285         etat.tear_down();
286     }
287     
288     
289     public org.omg.Components.Deployment.AssemblyState
290     get_state()
291     {
292         return etat.get_state();
293     }
294    
295     
296 }
297
Popular Tags