KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > DCI > DCIManagerContext


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.explorer.DCI;
27
28 import org.ist.coach.DCI.AssemblyManager;
29 import org.ist.coach.DCI.DCIDeployment;
30 import org.ist.coach.DCI.DCIInformation;
31 import org.ist.coach.DCI.DCIManager;
32 import org.ist.coach.DCI.NodeManager;
33 import org.ist.coach.DCI.UnknownAssembly;
34 import org.objectweb.openccm.explorer.CORBA.TypageCORBA;
35 import org.objectweb.util.explorer.api.Context;
36 import org.objectweb.util.explorer.api.Entry;
37 import org.objectweb.util.explorer.core.common.api.ContextContainer;
38 import org.objectweb.util.explorer.core.naming.lib.DefaultEntry;
39 import org.omg.Components.Deployment.Assembly;
40
41 /**
42  * This context displays:
43  * <ul>
44  * <li>a sequence of all NodeManager instances registered with the DCIManager.</li>
45  * <li>the assemblies installed on the DCIManager.</li>
46  * <li>the assemblies runnning under the DCIManager.</li>
47  * <li>the available homes.</li>
48  * </ul>
49  *
50  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
51  *
52  * @version 0.1
53  */

54 public class DCIManagerContext
55   implements Context
56 {
57
58     // ==================================================================
59
//
60
// Internal states.
61
//
62
// ==================================================================
63

64     // ==================================================================
65
//
66
// No constructor.
67
//
68
// ==================================================================
69

70     // ==================================================================
71
//
72
// Internal methods.
73
//
74
// ==================================================================
75

76     protected String JavaDoc getName(org.omg.CORBA.Object JavaDoc o) {
77         TypageCORBA tc = new TypageCORBA(o, org.objectweb.openccm.corba.TheORB.getORB());
78         return tc.getTypeID();
79     }
80
81     /**
82      * Provides a name depending on the AssemblyManager id.
83      */

84     protected String JavaDoc getName(String JavaDoc assemblyUUID){
85         String JavaDoc returnedValue = "Assembly ";
86         if(assemblyUUID!=null && assemblyUUID.indexOf(":")!=-1)
87             returnedValue = assemblyUUID.substring(0,assemblyUUID.indexOf(":")) + " Assembly";
88         return returnedValue;
89     }
90    
91     /**
92      * Provides a name depending on the AssemblyManager id.
93      */

94     protected String JavaDoc getName(AssemblyManager assemblyManager){
95         String JavaDoc returnedValue = "Assembly ";
96         String JavaDoc assemblyId = assemblyManager.ass_id();
97         if(assemblyId.indexOf(":")!=-1)
98             returnedValue = assemblyId.substring(0,assemblyId.indexOf(":"));
99         return returnedValue;
100     }
101     
102     protected boolean isStarted(AssemblyManager assemblyManager){
103         Assembly assembly = assemblyManager.provide_assembly();
104         return assembly.get_state().equals(org.omg.Components.Deployment.AssemblyState.INSERVICE);
105     }
106     
107     // ==================================================================
108
//
109
// Public methods for interface Context.
110
//
111
// ==================================================================
112

113     /* (non-Javadoc)
114      * @see org.objectweb.util.explorer.api.Context#getEntries(java.lang.Object)
115      */

116     public Entry[] getEntries(Object JavaDoc object) {
117         DCIManager DCIManager = (DCIManager) object;
118         java.util.List JavaDoc v = new java.util.Vector JavaDoc();
119
120         DCIInformation DCIInfo = DCIManager.provide_dci_information();
121         
122         ContextContainer nodeContainer = new NodeContextContainer();
123         NodeManager[] nodeManagerList = DCIInfo.get_node_managers();
124         for(int i=0 ; i<nodeManagerList.length ; i++)
125             nodeContainer.addEntry(nodeManagerList[i].node_name(), nodeManagerList[i]);
126         v.add(new DefaultEntry("Nodes", nodeContainer));
127         
128         DCIDeployment DCIDeploy = DCIManager.provide_dci_deployment();
129         
130         // Completing both the "Installed Assemblies" context and the "Running Assemblies" context
131
ContextContainer installedAssembliesContainer = new InstalledAssembliesContextContainer(DCIDeploy);
132         ContextContainer runningAssembliesContainer = new RunningAssembliesContextContainer();
133         String JavaDoc[] assemblyUUIDs = DCIDeploy.get_assemblies();
134         for (int i = 0; i < assemblyUUIDs.length; i++) {
135             String JavaDoc assemblyName = getName(assemblyUUIDs[i]) + " (" + (i+1) + ")";
136             installedAssembliesContainer.addEntry(assemblyName,new AssemblyUUIDWrapper(assemblyUUIDs[i],DCIDeploy));
137             try{
138                 String JavaDoc[] instanceUUID = DCIDeploy.get_assembly_instances(assemblyUUIDs[i]);
139                 for (int j = 0; j < instanceUUID.length; j++) {
140                     AssemblyManager assemblyManager = DCIDeploy.get_assembly_manager(instanceUUID[j]);
141                     AssemblyManagerWrapperWithDCIDeployment am = new AssemblyManagerWrapperWithDCIDeployment();
142                     am.setAssemblyManager(assemblyManager);
143                     am.setDCIDeployment(DCIDeploy);
144                     am.setUUID(instanceUUID[j]);
145                     if(isStarted(assemblyManager))
146                         runningAssembliesContainer.addEntry(getName(assemblyManager) + " (" + (j+1) + ")",am);
147                 }
148             } catch (UnknownAssembly e) {
149                 e.printStackTrace();
150             }
151         }
152         v.add(new DefaultEntry("Installed Assemblies", installedAssembliesContainer));
153         v.add(new DefaultEntry("Running Assemblies", runningAssembliesContainer));
154         
155         v.add(new DefaultEntry("Homes", DCIManager.provide_home_finder()));
156         
157         // Return the array of entry
158
return (Entry[]) v.toArray(new Entry[0]);
159     }
160
161 }
Popular Tags