KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > installer > CSDestinationDeployer


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 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer;
27
28 import java.util.Arrays JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.List JavaDoc;
31 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.FatalDeploymentException;
32 import org.objectweb.openccm.descriptor.softpkg.ccm.DependencyResolutionFailureException;
33 import org.objectweb.openccm.Deployment.Server;
34 import org.objectweb.openccm.Deployment.ServerHelper;
35 import org.omg.Components.CCMHome;
36 import org.omg.Components.ConfigValue;
37 import org.omg.Components.Deployment.ComponentInstallation;
38 import org.omg.Components.Deployment.Container;
39
40 /**
41  * This class is the destination deployer implementation able to deploy
42  * home on a openccm componentserver.
43  *
44  * @author <a HREF="mailto:briclet@lifl.fr">Briclet Fr?d?ric</a>
45  *
46  * @version 0.1
47  */

48 public class CSDestinationDeployer
49        extends DestinationDeployerBase
50     {
51
52     // ==================================================================
53
//
54
// Internal state.
55
//
56
// ==================================================================
57
private Server server;
58     private Hashtable JavaDoc containerTable;
59     private java.util.List JavaDoc config_values;
60     // ==================================================================
61
//
62
// Constructor.
63
//
64
// ==================================================================
65
public CSDestinationDeployer(){
66         containerTable=new Hashtable JavaDoc();
67         config_values=new java.util.LinkedList JavaDoc();
68     }
69     
70     // ==================================================================
71
//
72
// Internals methods.
73
//
74
// ==================================================================
75
/**
76      * Internal method to retrieve the server which support the component
77      * server and component installation.
78      *
79      * @return the server describes by destination element
80      */

81     private Server getServer()
82     throws Exception JavaDoc
83     {
84         if (server == null) {
85             server = ServerHelper.narrow(getFindbyDeployer().resolveReference());
86         }
87         return server;
88     }
89     /**
90      * Internal method to install a home.
91      *
92      * @param csConfig
93      * @param contConfig
94      * @param homeConfig
95      * @param implID
96      * @param entryPoint
97      * @return
98      * @throws FatalDeploymentException
99      */

100     private CCMHome
101     installCCMHome(
102            ConfigValue[] csConfig,
103            ConfigValue[] contConfig,
104            ConfigValue[] homeConfig,
105            String JavaDoc implID,
106            String JavaDoc entryPoint)
107      throws FatalDeploymentException
108      {
109         
110        CCMHome home = null;
111         try {
112             Container cont = getServer()
113                               .provide_component_server()
114                               .create_container(contConfig);
115             home = cont.install_home(implID, entryPoint, homeConfig);
116             containerTable.put(home, cont);
117         } catch (Exception JavaDoc e) {
118             throw new FatalDeploymentException(this,e,"Cannot deploy the CCMHome on the required destination");
119         }
120         return home;
121      }
122
123     // ==================================================================
124
//
125
// Public methods.
126
//
127
// ==================================================================
128
/**
129       * Return the component installation of the target host used
130       * to install the home.
131       *
132       * @return The component installation of the target host
133       * @throws FatalDeploymentException if a fatal problem occured during installation
134       */

135     public ComponentInstallation
136     getComponentInstallation()
137     throws FatalDeploymentException {
138
139         try {
140             return getServer().provide_install();
141         } catch (Exception JavaDoc e) {
142             throw new FatalDeploymentException(this,e,"Cannot acces to the componentinstallation on the required destination");
143         }
144     }
145     /**
146      * Make the target destination deployer process all the dependencies
147      * of the implementation.
148      *
149      * @throws FatalDeploymentException if a problem occured
150      * during processing of dependencies
151      */

152     public void
153     resolveDependency()
154     throws FatalDeploymentException
155     {
156         try{
157             config_values.addAll(Arrays.asList(getSoftpkgDeployer()
158                                                 .processDependencies
159                                                     (getComponentInstallation())));
160             List JavaDoc l=Arrays.asList(getImplementationDeployer()
161                                  .install(getComponentInstallation()));
162               
163             config_values.addAll(l);
164                                                     
165         }
166         catch(DependencyResolutionFailureException e){
167             getErrorManager().submitException(e);
168         }
169     }
170     /**
171      * InstallHome install the home on the precised destination according
172      * to the host requirements, such as dependencies and event factory.
173      *
174      * @return The home installed
175      * @throws FatalDeploymentException
176      */

177     public CCMHome
178     installHome()
179     throws FatalDeploymentException
180     {
181       ConfigValue[] config_home =(ConfigValue[])
182                                  config_values.toArray(new ConfigValue[config_values.size()]);
183
184        return installCCMHome(new ConfigValue[0],
185                        new ConfigValue[0],
186                        config_home,
187                        getImplementationDeployer().getImplementation().getId(),
188                        getImplementationDeployer().getEntryPoint());
189     }
190     
191    
192     /**
193      * Remove a previously installed CCMHome
194      *
195      * @param home the home to remove
196      * @throws FatalDeploymentException if a fatal problem occured during uninstallation
197      */

198      public void
199      removeHome(CCMHome home)
200      throws FatalDeploymentException
201      {
202          try {
203              Container cont = (Container) containerTable.remove(home);
204              cont.remove_home(home);
205              cont.remove();
206          } catch (Exception JavaDoc e) {
207              throw new FatalDeploymentException(e);
208          }
209      }
210
211 }
212
Popular Tags