KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > event > ModuleDeployEvent


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  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.event;
32
33 import com.sun.enterprise.admin.event.BaseDeployEvent;
34
35 //i18n import
36
import com.sun.enterprise.util.i18n.StringManager;
37
38 /**
39  * Module deployment event. This event is generated whenever a J2EE
40  * module is deployed, undeployed, redeployed, enabled or disabled.
41  */

42 public class ModuleDeployEvent extends BaseDeployEvent {
43
44     /**
45      * Constant to denote standalone web module
46      */

47     public static final String JavaDoc TYPE_WEBMODULE = "web";
48
49     /**
50      * Constant to denote standalone ejb module
51      */

52     public static final String JavaDoc TYPE_EJBMODULE = "ejb";
53
54     /**
55      * Constant to denote connector module
56      */

57     public static final String JavaDoc TYPE_CONNECTOR = "connector";
58     
59     
60     /**
61      * Constant to denote appclient module
62      */

63     public static final String JavaDoc TYPE_APPCLIENT = "appclient";
64
65     /**
66      * Int constant to denote standalone web module
67      */

68     public static final int TYPE_WEBMODULE_CODE = 1;
69
70     /**
71      * Int constant to denote standalone ejb module
72      */

73     public static final int TYPE_EJBMODULE_CODE = 2;
74
75     /**
76      * Int constant to denote connector module
77      */

78     public static final int TYPE_CONNECTOR_CODE = 3;
79
80     /**
81      * Int constant to denote appclient module
82      */

83     public static final int TYPE_APPCLIENT_CODE = 4;
84     
85     /**
86      * Event type
87      */

88     static final String JavaDoc eventType = ModuleDeployEvent.class.getName();
89
90     /**
91      * Module type.
92      */

93     private String JavaDoc moduleType;
94
95     /**
96      * Module type code.
97      */

98     private int moduleTypeCode;
99
100     /**
101      * Indicates whether the ModuleDeployEvent was forced
102      */

103     private boolean forceDeploy = false;
104
105     // i18n StringManager
106
private static StringManager localStrings =
107         StringManager.getManager( ModuleDeployEvent.class );
108
109     /**
110      * Create a new ModuleDeployEvent for the specified instance,
111      * module (name and type) and action code.
112      *
113      * @param instance name of the server instance to which module has
114      * been deployed, undeployed or redployed.
115      * @param moduleName name of the module that has been deployed,
116      * undeployed, redeployed, enabled or disabled
117      * @param moduleType type of the module - one of TYPE_WEBMODULE,
118      * TYPE_EJBMODULE, TYPE_CONNECTOR
119      * @param actionCode what happened to the module, the valid values are
120      * BaseDeployEvent.DEPLOY, BaseDeployEvent.REDEPLOY,
121      * BaseDeployEvent.UNDEPLOY, BaseDeployEvent.ENABLE or
122      * BaseDeployEvent.DISABLE
123      * @throws IllegalArgumentException if moduleType or actionCode is invalid
124      */

125     public ModuleDeployEvent(String JavaDoc instance, String JavaDoc moduleName,
126             String JavaDoc moduleType, String JavaDoc actionCode) {
127         super(eventType, instance, BaseDeployEvent.MODULE, moduleName, actionCode);
128         setModuleType(moduleType);
129     }
130
131     /**
132      * Creates a new ModuleDeployEvent for the provided instance,
133      * moduleName, moduleType, actionCode and cascade
134      */

135     public ModuleDeployEvent(String JavaDoc instance, String JavaDoc moduleName,
136             String JavaDoc moduleType, String JavaDoc actionCode, boolean cascade) {
137         super(eventType, instance, BaseDeployEvent.MODULE, moduleName, actionCode, cascade);
138         setModuleType(moduleType);
139     }
140
141    /**
142     * Creates a new ModuleDeployEvent for the provided instance,
143     * moduleName, moduleType, actionCode, cascade and
144     * forceDeploy values
145     */

146     public ModuleDeployEvent(String JavaDoc instance, String JavaDoc moduleName,
147                  String JavaDoc moduleType, String JavaDoc actionCode,
148                  boolean cascade, boolean forceDeploy) {
149         super(eventType, instance, BaseDeployEvent.MODULE, moduleName, actionCode, cascade);
150         setModuleType(moduleType);
151         setForceDeploy(forceDeploy);
152     }
153
154     public void setForceDeploy(boolean forceDeploy) {
155         this.forceDeploy = forceDeploy;
156     }
157     
158     public boolean getForceDeploy(){
159         return this.forceDeploy;
160     }
161
162     /**
163      * Get name of the module that was affected by deployment action.
164      */

165     public String JavaDoc getModuleName() {
166         return getJ2EEComponentName();
167     }
168
169     /**
170      * Get type of the module. Possible values are TYPE_WEBMODULE,
171      * TYPE_EJBMODULE and TYPE_CONNECTOR.
172      */

173     public String JavaDoc getModuleType() {
174         return moduleType;
175     }
176
177     /**
178      * Get module type code. Possible values are TYPE_WEBMODULE_CODE,
179      * TYPE_EJBMODULE_CODE and TYPE_CONNECTOR_CODE.
180      */

181     public int getModuleTypeCode() {
182         return moduleTypeCode;
183     }
184
185     /**
186      * Helper method to validate and set module type
187      */

188     private void setModuleType(String JavaDoc modType) {
189         boolean valid = true;
190         int modTypeCode = 0;
191         if (TYPE_WEBMODULE.equals(modType)) {
192             modTypeCode = TYPE_WEBMODULE_CODE;
193         } else if (TYPE_EJBMODULE.equals(modType)) {
194             modTypeCode = TYPE_EJBMODULE_CODE;
195         } else if (TYPE_CONNECTOR.equals(modType)) {
196             modTypeCode = TYPE_CONNECTOR_CODE;
197         } else if (TYPE_APPCLIENT.equals(modType)) {
198             modTypeCode = TYPE_APPCLIENT_CODE;
199         } else {
200             valid = false;
201         }
202         if (!valid) {
203             String JavaDoc msg = localStrings.getString( "admin.event.invalid_module_type", modType );
204             throw new IllegalArgumentException JavaDoc( msg );
205         }
206         this.moduleType = modType;
207         this.moduleTypeCode = modTypeCode;
208     }
209
210     /**
211      * Return a useful string representation.
212      */

213     public String JavaDoc toString() {
214         return "ModuleDeployEvent -- " + getAction() + " " + moduleType + "/" + getModuleName();
215     }
216 }
217
Popular Tags