KickJava   Java API By Example, From Geeks To Geeks.

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


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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.explorer.DCI;
28
29 import java.util.Vector JavaDoc;
30
31 import org.ist.coach.DCI.AssemblyManager;
32 import org.ist.coach.DCI.DCIDeployment;
33 import org.ist.coach.DCI.DCIInformation;
34 import org.ist.coach.DCI.DCIManager;
35 import org.ist.coach.DCI.UnknownAssembly;
36 import org.objectweb.openccm.explorer.CORBA.TypageCORBA;
37 import org.objectweb.util.explorer.api.Table;
38 import org.objectweb.util.explorer.api.TreeView;
39 import org.objectweb.util.explorer.core.naming.lib.DefaultEntry;
40 import org.omg.Components.Deployment.Assembly;
41
42 /**
43  * Displays the running assemblies for the given DCIManager.
44  *
45  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
46  *
47  * @version 0.1
48  */

49 public class DCIRunningAssembliesTable
50   implements Table
51 {
52
53     //==================================================================
54
//
55
// Internal states.
56
//
57
//==================================================================
58

59     //==================================================================
60
//
61
// No constructor.
62
//
63
//==================================================================
64

65     // ==================================================================
66
//
67
// Internal methods.
68
//
69
// ==================================================================
70

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

79     protected String JavaDoc getName(AssemblyManager assemblyManager){
80         String JavaDoc returnedValue = "Assembly ";
81         String JavaDoc assemblyId = assemblyManager.ass_id();
82         if(assemblyId.indexOf(":")!=-1)
83             returnedValue = assemblyId.substring(0,assemblyId.indexOf(":"));
84         return returnedValue;
85     }
86     
87     protected boolean isStarted(AssemblyManager assemblyManager){
88         Assembly assembly = assemblyManager.provide_assembly();
89         return assembly.get_state().equals(org.omg.Components.Deployment.AssemblyState.INSERVICE);
90     }
91         
92     //==================================================================
93
//
94
// Public methods for Table interface.
95
//
96
//==================================================================
97

98     /* (non-Javadoc)
99      * @see org.objectweb.util.explorer.api.Table#getHeaders(org.objectweb.util.explorer.api.TreeView)
100      */

101     public String JavaDoc[] getHeaders(TreeView treeView) {
102         return new String JavaDoc[]{"Assemblies"};
103     }
104     
105     /* (non-Javadoc)
106      * @see org.objectweb.util.explorer.api.Table#getRows(org.objectweb.util.explorer.api.TreeView)
107      */

108     public Object JavaDoc[][] getRows(TreeView treeView) {
109         DCIManager DCIManager_ = (DCIManager)treeView.getSelectedObject();
110         DCIInformation DCIInfo = DCIManager_.provide_dci_information();
111         DCIDeployment DCIDeploy = DCIManager_.provide_dci_deployment();
112         String JavaDoc[] assemblyUUIDs = DCIDeploy.get_assemblies();
113         Vector JavaDoc values = new Vector JavaDoc();
114         
115         for (int i = 0; i < assemblyUUIDs.length; i++) {
116             try{
117                 String JavaDoc[] instanceUUID = DCIDeploy.get_assembly_instances(assemblyUUIDs[i]);
118                 for (int j = 0; j < instanceUUID.length; j++) {
119                     AssemblyManager assemblyManager = DCIDeploy.get_assembly_manager(instanceUUID[j]);
120                     AssemblyManagerWrapperWithDCIDeployment am = new AssemblyManagerWrapperWithDCIDeployment();
121                     am.setAssemblyManager(assemblyManager);
122                     am.setDCIDeployment(DCIDeploy);
123                     am.setUUID(instanceUUID[j]);
124                     if(isStarted(assemblyManager))
125                         values.add(new DefaultEntry(getName(assemblyManager) + " (" + (j+1) + ")", am));
126                 }
127             } catch (UnknownAssembly e) {
128                 e.printStackTrace();
129             }
130         }
131
132         Object JavaDoc[][] contenu = new Object JavaDoc[values.size()][1];
133         for(int i=0 ; i<values.size() ; i++){
134             contenu[i][0] = values.get(i);
135         }
136         
137         return contenu;
138     }
139 }
140
Popular Tags