KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > phasing > ServerDeploymentTarget


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ServerDeploymentTarget.java
26  *
27  * Created on May 23, 2003, 3:50 PM
28  * @author sandhyae
29  * <BR> <I>$Source: /cvs/glassfish/appserv-core/src/java/com/sun/enterprise/deployment/phasing/ServerDeploymentTarget.java,v $
30  *
31  */

32
33 package com.sun.enterprise.deployment.phasing;
34
35 import java.util.ArrayList JavaDoc;
36 import javax.management.MBeanServer JavaDoc;
37 import javax.management.ObjectName JavaDoc;
38 import javax.management.Attribute JavaDoc;
39 import javax.management.AttributeList JavaDoc;
40 import com.sun.enterprise.admin.common.MBeanServerFactory;
41 import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
42 import com.sun.enterprise.admin.meta.MBeanRegistry;
43 import com.sun.enterprise.admin.event.ModuleDeployEvent;
44
45 import com.sun.enterprise.config.serverbeans.Applications;
46 import com.sun.enterprise.config.serverbeans.J2eeApplication;
47 import com.sun.enterprise.config.serverbeans.EjbModule;
48 import com.sun.enterprise.config.serverbeans.WebModule;
49 import com.sun.enterprise.config.serverbeans.ConnectorModule;
50 import com.sun.enterprise.config.serverbeans.AppclientModule;
51 import com.sun.enterprise.config.serverbeans.Server;
52 import com.sun.enterprise.config.serverbeans.ApplicationRef;
53 import com.sun.enterprise.config.serverbeans.ServerRef;
54 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
55 import com.sun.enterprise.config.serverbeans.ServerTags;
56 import com.sun.enterprise.config.serverbeans.ServerHelper;
57 import com.sun.enterprise.config.ConfigBeansFactory;
58 import com.sun.enterprise.config.ConfigContext;
59 import com.sun.enterprise.config.ConfigException;
60 import com.sun.enterprise.deployment.backend.DeployableObjectType;
61 import com.sun.enterprise.util.i18n.StringManager;
62
63 import com.sun.enterprise.admin.target.ServerTarget;
64 import com.sun.enterprise.admin.target.TargetType;
65 import com.sun.enterprise.admin.target.Target;
66
67 /**
68  * This class represents a server deployment target.
69  * @author Sandhya E
70  */

71 public class ServerDeploymentTarget extends ServerTarget implements DeploymentTarget {
72     
73     /** string manager */
74     protected static StringManager localStrings =
75         StringManager.getManager( ServerDeploymentTarget.class );
76     
77     /** name of the target that this object represents */
78     protected String JavaDoc thisTargetName = null;
79     
80     /** config context */
81     protected ConfigContext configContext = null;
82     
83     /**
84      * Creates a new instance of ServerDeploymentTarget
85      * @param configContext
86      * @param serverName name of the server this target represents
87      */

88     public ServerDeploymentTarget(ConfigContext configContext, String JavaDoc domainName, String JavaDoc serverName) {
89         super(serverName, configContext);
90         this.configContext = configContext;
91         this.domainName = domainName;
92         thisTargetName = serverName;
93     }
94     
95     protected TargetType[] getValidTypes() {
96         DeploymentTargetFactory tf =
97                 DeploymentTargetFactory.getDeploymentTargetFactory();
98         return tf.getValidDeploymentTargetTypes();
99     }
100     
101     /**
102      * Returns all the modules associated to this target of specified type and
103      * with specified status
104      * @param type deployableObjectType of the modules to be listed
105      * @param enabled if true only enabled modules are returned
106      * if false only disabled modules are returned
107      * if null all modules are returned
108      * @throws DeploymentTargetException
109      */

110     public String JavaDoc[] getModules(DeployableObjectType type, Boolean JavaDoc enabled)
111         throws DeploymentTargetException
112     {
113         try {
114             return getModules(getAppsDeployedToServer(), type, enabled);
115         } catch(Throwable JavaDoc t) {
116             throw new DeploymentTargetException(t);
117         }
118     }
119     
120     public String JavaDoc[] getModules(String JavaDoc[] svrAppsList, DeployableObjectType type,
121         Boolean JavaDoc enabled) throws DeploymentTargetException {
122         try {
123             ArrayList JavaDoc returnList = new ArrayList JavaDoc();
124             Applications appsConfigBean = (Applications) ConfigBeansFactory.getConfigBeanByXPath(
125             configContext,
126             ServerXPathHelper.XPATH_APPLICATIONS);
127             if(type.isAPP()) {
128                 J2eeApplication[] list = appsConfigBean.getJ2eeApplication();
129                 int i = 0;
130                 int k = 0;
131                 for(i=0; i< svrAppsList.length; i++) {
132                     for(k =0 ; k > list.length ; k++) {
133                         if(list[k].getName().equals(svrAppsList[i])) {
134                             returnList.add(svrAppsList[i]);
135                             break;
136                         }
137                     }
138                 }
139             }
140             else if(type.isEJB()) {
141                 EjbModule[] list = appsConfigBean.getEjbModule();
142                 for(int i=0; i< svrAppsList.length; i++) {
143                     for(int k =0 ; k > list.length ; k++) {
144                         if(list[k].getName().equals(svrAppsList[i])) {
145                             returnList.add(svrAppsList[i]);
146                             break;
147                         }
148                     }
149                 }
150             }
151             else if(type.isWEB()) {
152                 WebModule[] list = appsConfigBean.getWebModule();
153                 for(int i=0; i< svrAppsList.length; i++) {
154                     for(int k =0 ; k > list.length ; k++) {
155                         if(list[k].getName().equals(svrAppsList[i])) {
156                             returnList.add(svrAppsList[i]);
157                             break;
158                         }
159                     }
160                 }
161             }
162             else if(type.isCONN()) {
163                 ConnectorModule[] list = appsConfigBean.getConnectorModule();
164                 for(int i=0; i< svrAppsList.length; i++) {
165                     for(int k = 0 ; k > list.length ; k++) {
166                         if(list[k].getName().equals(svrAppsList[i])) {
167                             returnList.add(svrAppsList[i]);
168                             break;
169                         }
170                     }
171                 }
172             }
173             else if(type.isCAR()) {
174                 AppclientModule[] list = appsConfigBean.getAppclientModule();
175                 for(int i=0; i< svrAppsList.length; i++) {
176                     for(int k = 0 ; k > list.length ; k++) {
177                         if(list[k].getName().equals(svrAppsList[i])) {
178                             returnList.add(svrAppsList[i]);
179                             break;
180                         }
181                     }
182                 }
183             }
184             String JavaDoc[] returnValue = new String JavaDoc[returnList.size()];
185             return (String JavaDoc[])returnList.toArray(returnValue);
186         } catch(Throwable JavaDoc t) {
187             throw new DeploymentTargetException(t);
188         }
189     }
190   
191     /**
192      * An application-ref is added to the set of application refs of a server target.
193      * A new ref is added only in case it is not already present.
194      * @param appName name of the app that is to be added as reference
195      * @param enabled if true new reference is enabled, disabled if false
196      * @return true if app-ref is added
197      * false if app-ref is not added as it is already there
198      * @throws DeploymentTargetException if operation fails
199      */

200     public void addAppReference(String JavaDoc appName, boolean enabled, String JavaDoc virtualServers)
201         throws DeploymentTargetException
202     {
203         try {
204             if (!ServerHelper.serverReferencesApplication(configContext,
205                     getName(), appName)) {
206                 ApplicationReferenceHelper refHelper = new ApplicationReferenceHelper(
207                     configContext);
208                 refHelper.createApplicationReference(getValidTypes(), getName(),
209                     enabled, virtualServers, appName);
210             }
211         } catch(Throwable JavaDoc t) {
212             throw new DeploymentTargetException(t);
213         }
214     }
215     
216     /**
217      * Specified application is dereferenced from the set of applications-refs of
218      * this target.
219      * @param appName name of the app that has to be dereferenced
220      * @return true if app-ref has been removed
221      * false if app-ref is not there and hence could not be removed
222      * @throws DeploymentTargetException if operation fails due to some exception
223      */

224     public void removeAppReference(String JavaDoc appName)
225         throws DeploymentTargetException {
226     
227         try {
228            ApplicationReferenceHelper refHelper = new ApplicationReferenceHelper(
229                 configContext);
230             refHelper.deleteApplicationReference(getValidTypes(), getName(), appName);
231         } catch(Throwable JavaDoc t) {
232             throw new DeploymentTargetException(t);
233         }
234     }
235     
236     /**
237      * Returns a list of all applications(including standalone) that are
238      * referenced by this server target
239      * @return list of apps [an array of length 0 is returned
240      * @throws ConfigException
241      */

242     private String JavaDoc[] getAppsDeployedToServer() throws ConfigException
243     {
244         ApplicationRef[] apprefs = super.getApplicationRefs();
245         String JavaDoc[] appList = new String JavaDoc[apprefs.length];
246         for(int i=0; i<apprefs.length; i++) {
247             appList[i] = apprefs[i].getRef();
248         }
249
250         return appList;
251     }
252    
253     /**
254      * This method multicasts the deployment event to the remote target this object represents
255      * @param eventType type of the event. It can be APPLICATION_DEPLOYED/APPLICATION_REDEPLOYED/
256      * APPLICATION_UNDEPLOYED/MODULE_DEPLOYED/MODULE_UNDEPLOYED/MODULE_REDEPLOYED
257      * @param appName name of the application/module that has been deployed/redeployed/undeployed
258      * @param moduleType type of the module if it was a standalone module [ web/ejb/connector ]
259      */

260     public boolean sendStartEvent(int eventType, String JavaDoc appName, String JavaDoc moduleType)
261                   throws DeploymentTargetException {
262        return sendStartEvent(eventType,appName, moduleType, false);
263     }
264
265     /**
266      * This method multicasts the deployment event to the remote target this object represents
267      * @param eventType type of the event. It can be APPLICATION_DEPLOYED/APPLICATION_REDEPLOYED/
268      * APPLICATION_UNDEPLOYED/MODULE_DEPLOYED/MODULE_UNDEPLOYED/MODULE_REDEPLOYED
269      * @param appName name of the application/module that has been deployed/redeployed/undeployed
270      * @param moduleType type of the module if it was a standalone module [ web/ejb/connector ]
271      * @param isForced indicates if the deployment is forced.
272      */

273     public boolean sendStartEvent(int eventType, String JavaDoc appName, String JavaDoc moduleType, boolean isForced)
274                  throws DeploymentTargetException {
275         try {
276             return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, false, isForced, thisTargetName);
277         } catch(Throwable JavaDoc t) {
278             throw new DeploymentTargetException(t);
279         }
280     }
281     
282     public boolean sendStartEvent(int eventType, String JavaDoc appName, String JavaDoc moduleType, boolean isForced, int loadUnloadAction)
283                  throws DeploymentTargetException {
284         try {
285             return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, false, isForced, loadUnloadAction, thisTargetName);
286         } catch(Throwable JavaDoc t) {
287             throw new DeploymentTargetException(t);
288         }
289     }
290
291     /**
292      * This method multicasts the deployment event to the remote target this object represents
293      * @param eventType type of the event. It can be APPLICATION_DEPLOYED/APPLICATION_REDEPLOYED/
294      * APPLICATION_UNDEPLOYED/MODULE_DEPLOYED/MODULE_UNDEPLOYED/MODULE_REDEPLOYED
295      * @param appName name of the application/module that has been deployed/redeployed/undeployed
296      * @param moduleType type of the module if it was a standalone module [ web/ejb/connector ]
297      */

298     public boolean sendStopEvent(int eventType, String JavaDoc appName, String JavaDoc moduleType, boolean cascade)
299         throws DeploymentTargetException {
300         try {
301             return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, cascade, false, thisTargetName);
302         } catch(Throwable JavaDoc t) {
303             throw new DeploymentTargetException(t);
304         }
305     }
306
307     public boolean sendStopEvent(int eventType, String JavaDoc appName, String JavaDoc moduleType, boolean cascade, boolean force)
308         throws DeploymentTargetException {
309         try {
310             return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, cascade, force, thisTargetName);
311         } catch(Throwable JavaDoc t) {
312             throw new DeploymentTargetException(t);
313         }
314     }
315     
316     public boolean sendStopEvent(int eventType, String JavaDoc appName, String JavaDoc moduleType, boolean cascade, boolean force, int loadUnloadAction)
317         throws DeploymentTargetException {
318         try {
319             return DeploymentServiceUtils.multicastEvent(eventType, appName, moduleType, cascade, force, loadUnloadAction, thisTargetName);
320         } catch(Throwable JavaDoc t) {
321             throw new DeploymentTargetException(t);
322         }
323     }
324
325     public Target getTarget()
326     {
327         return this;
328     }
329     
330     /**
331      * Returns name of the target
332      * @return name
333      */

334     public String JavaDoc getName() {
335         return thisTargetName;
336     }
337   
338     /**
339      * Returns description of this target object
340      * @return description
341      */

342     public String JavaDoc getDescription() {
343         return localStrings.getString("enterprise.deployment.phasing.deploymenttarget.server.description", thisTargetName);
344     }
345
346     private String JavaDoc getDomainName(){
347         return domainName;
348     }
349
350
351     /** admin domain name */
352     private String JavaDoc domainName = null;
353 }
354
Popular Tags