KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
34 import com.sun.enterprise.admin.event.BaseDeployEvent;
35 import com.sun.enterprise.config.ConfigChange;
36
37 //i18n import
38
import com.sun.enterprise.util.i18n.StringManager;
39
40 /**
41  * Resource deployment event. This event is generated whenever a application
42  * server resource is deployed, undeployed, redeployed, enabled or disabled.
43  *
44  */

45 public class ResourceDeployEvent extends BaseDeployEvent implements Cloneable JavaDoc {
46
47     /**
48      * Constant to denote custom resource type.
49      */

50     public static final String JavaDoc RES_TYPE_CUSTOM = "custom";
51
52     /**
53      * Constant to denote external jndi resource type.
54      */

55     public static final String JavaDoc RES_TYPE_EXTERNAL_JNDI = "external-jndi";
56
57     /**
58      * Constant to denote jdbc resource type.
59      */

60     public static final String JavaDoc RES_TYPE_JDBC = "jdbc";
61
62     /**
63      * Constant to denote mail resource type.
64      */

65     public static final String JavaDoc RES_TYPE_MAIL = "mail";
66
67     /**
68      * Constant to denote jms resource type.
69      */

70     public static final String JavaDoc RES_TYPE_JMS = "jms";
71
72     /**
73      * Constant to denote persistence manager factory resource type.
74      */

75     public static final String JavaDoc RES_TYPE_PMF = "pmf";
76
77     /**
78      * Constant to denote jdbc connection pool resource type.
79      */

80     public static final String JavaDoc RES_TYPE_JCP = "jcp";
81
82     /**
83      * Constant to denote admin object resource type.
84      */

85     public static final String JavaDoc RES_TYPE_AOR = "aor";
86     
87     /**
88      * Constant to denote connector connection pool resource type.
89      */

90     public static final String JavaDoc RES_TYPE_CCP = "ccp";
91     
92     /**
93      * Constant to denote connector resource type.
94      */

95     public static final String JavaDoc RES_TYPE_CR = "cr";
96     
97     /**
98      * Constant to denote resource adapter config type.
99      */

100     public static final String JavaDoc RES_TYPE_RAC = "rac";
101     
102     /**
103      * Event type
104      */

105     static final String JavaDoc eventType = ResourceDeployEvent.class.getName();
106
107     /**
108      * Resource type. The valid values are Custom, external
109      */

110     private String JavaDoc resourceType;
111
112     /**
113      * Resource exists. This is set to true if the event is created with
114      * action code of REDEPLOY, UNDEPLOY, ENABLE OR DISABLE. Otherwise, it
115      * is set to false.
116      */

117     private boolean resourceExists = true;
118
119     /**
120      *
121      */

122     private boolean noOp = false;
123
124     // i18n StringManager
125
private static StringManager localStrings =
126         StringManager.getManager( ResourceDeployEvent.class );
127
128     /**
129      * Create a new ResourceDeployEvent for the specified instance,
130      * resource (type and name) and action code.
131      *
132      * @param instance name of the server instance to which resource has
133      * been deployed, undeployed or redployed.
134      * @param resourceName name of the resource that has been deployed,
135      * undeployed, redeployed, enabled or disabled
136      * @param resourceType of the resource, one of RES_TYPE_CUSTOM,
137      * RES_TYPE_EXTERNAL_JNDI, RES_TYPE_JDBC, RES_TYPE_MAIL,
138      * RES_TYPE_JMS, RES_TYPE_PMF, RES_TYPE_JCP.
139      * @param actionCode what happened to the resource, the valid values are
140      * BaseDeployEvent.DEPLOY, BaseDeployEvent.REDEPLOY,
141      * BaseDeployEvent.UNDEPLOY, BaseDeployEvent.ENABLE or
142      * BaseDeployEvent.DISABLE
143      * @throws IllegalArgumentException if resourceType or actionCode is invalid
144      */

145     public ResourceDeployEvent(String JavaDoc instance, String JavaDoc resourceName,
146             String JavaDoc resourceType, String JavaDoc actionCode) {
147         super(eventType, instance, BaseDeployEvent.RESOURCE, resourceName,
148                 actionCode);
149         if(resourceType!=null)
150             setResourceType(resourceType);
151         if (DEPLOY.equals(actionCode)) {
152             resourceExists = false;
153         }
154     }
155
156     private ResourceDeployEvent(String JavaDoc type, Object JavaDoc source,
157                                  long seqNumber,long time) {
158         super(type, source, seqNumber, time);
159         setResourceType(type);
160         this.j2eeComponentType = BaseDeployEvent.RESOURCE;
161
162         // WARNING: actionName & j2eeComponentName is not set
163
}
164     
165     /**
166      * Get name of the resource that was affected by deployment action.
167      * @return name of the resource
168      */

169     public String JavaDoc getResourceName() {
170         return getJ2EEComponentName();
171     }
172
173     /**
174      * Get resource type - one of RES_TYPE_CUSTOM, RES_TYPE_EXTERNAL_JNDI,
175      * RES_TYPE_JDBC, RES_TYPE_MAIL, RES_TYPE_JMS, RES_TYPE_PMF, RES_TYPE_JCP.
176      * @return resource type
177      */

178     public String JavaDoc getResourceType() {
179         return resourceType;
180     }
181
182     /**
183      * Helper method to validate and set resource type.
184      */

185     public void setResourceType(String JavaDoc resType) {
186         boolean valid = false;
187         if (RES_TYPE_CUSTOM.equals(resType)
188                 || RES_TYPE_EXTERNAL_JNDI.equals(resType)
189                 || RES_TYPE_JDBC.equals(resType)
190                 || RES_TYPE_MAIL.equals(resType)
191                 || RES_TYPE_JMS.equals(resType)
192                 || RES_TYPE_PMF.equals(resType)
193                 || RES_TYPE_JCP.equals(resType)
194                 || RES_TYPE_AOR.equals(resType)
195                 || RES_TYPE_CCP.equals(resType)
196                 || RES_TYPE_CR.equals(resType)
197                 || RES_TYPE_RAC.equals(resType)) {
198             valid = true;
199         }
200         if (!valid) {
201             String JavaDoc msg = localStrings.getString( "admin.event.invalid_resource_type", resType );
202             throw new IllegalArgumentException JavaDoc( msg );
203         }
204         this.resourceType = resType;
205     }
206
207 /*
208 Transition for config change processing. A single processing may include
209 n Add and m Delete and 0 or 1 Update. n and m should differ by at most 1.
210
211 Create -> creation of event
212 Add, Upd, Del -> Type of config change
213
214 For any transitions not allowed by this state diagram, the setActionForXXX
215 methods throw IllegalStateException
216
217 INITIAL STATE: RESOURCE DOES NOT EXIST
218
219                                +---+
220                              +-|Upd|--+
221                              | +---+ |
222 +------------+ +-+--------V-+ +-----------+
223 |exist=false,| +------+ |exist=true, | +---+ |exist=false|
224 |action=null,+--|Create|-->+action=depl,+--|Del|-->+action=depl|
225 | noop=null | +------+ |noop=false | +---+ |noop=true |
226 +------------+ [Add] +-----+------+ +-----+-----+
227                                  | +---+ |
228                                  +--<------|Add|---------+
229                                            +---+
230 INITIAL STATE: RESOURCE EXISTS
231
232                                +------------+
233                                |exist=true | +---+
234                            +-->|action=enbl +--|Del|--->---+
235                            | |noop=false | +---+ |
236                            | +------------+ |
237                            | |
238                            | |
239 +------------+ | +------------+ |
240 |exist=true | +------+ | |exist=true | +---+ |
241 |action=null +--|Create|---+-->|action=dsbl +--|Del|--->---+
242 |noop=null | +------+ | |noop=false | +---+ |
243 +-----+------+ [Upd] | +------------+ |
244       | | |
245       | | |
246       | | +------------+ |
247       | | |exist=true | +---+ |
248       | +-->|action=rdpl +--|Del|--->---+
249       | |noop=false | +---+ |
250       | +-+--------+-+<--------+ |
251       | | +---+ | | |
252       | +-|Upd|->+ | |
253       | +---+ | |
254       | | |
255       | +------------+ | |
256       | +------+ |exist=false | +---+ | |
257       +---------|Create|------>|action=udpl +--|Add|--+ |
258                 +------+ |noop=false | +---+ |
259                  [Del] +-----+------+ |
260                                      | |
261                                      +------<--------------+
262
263
264 */

265     /**
266      * Set appropriate action code for a ConfigChange of type Add. This method
267      * is called while processing config changes after the initial creation of
268      * the event.
269      * @throws IllegalStateException if Add operation is invalid in current
270      * context.
271      */

272     private void setActionForAdd() {
273         if (resourceExists) {
274             String JavaDoc currentAction = getAction();
275             if (UNDEPLOY.equals(currentAction)) {
276                 setAction(REDEPLOY);
277             } else {
278                 // throw new IllegalStateException("Existing resource with "
279
// + "action " + currentAction + ". Can not Add!");
280
}
281         } else {
282             if (noOp) {
283                 setAction(DEPLOY);
284                 noOp = false;
285             } else {
286                 // Add can come again for properties associated to the resource
287
// So do not throw exception
288
// throw new IllegalStateException("Can not add new resource "
289
// + "again!");
290
}
291         }
292     }
293
294     /**
295      *
296      * @throws IllegalStateException if Update operation is invalid in
297      * current context.
298      */

299     private void setActionForUpdate() {
300         // FIX
301
// Do Nothing??
302
// String currentAction = getAction();
303
// if (ENABLE.equals(currentAction) || DISABLE.equals(currentAction)) {
304
// throw new IllegalStateException("A resource can have only "
305
// + "one Config Change entry of type update!");
306
// }
307
}
308
309     /**
310      *
311      * @throws IllegalStateException if Delete operation is invalid in
312      * current context.
313      */

314     private void setActionForDelete() {
315         if (resourceExists) {
316             String JavaDoc currentAction = getAction();
317             if (UNDEPLOY.equals(currentAction)) {
318                 // throw new IllegalStateException("Resource already removed."
319
// + "Can not remove again!");
320
} else {
321                 setAction(UNDEPLOY);
322             }
323         } else {
324             if (noOp) {
325                 // throw new IllegalStateException("New resource already "
326
// + "removed. Can not remove again!");
327
} else {
328                 noOp = true;
329             }
330         }
331     }
332
333     /**
334      * Set action for specified action. If action is unknown then the method
335      * throws IllegalArgumentException. If the new action can not be applied in
336      * current state, the method throws IllegalStateException.
337      */

338     void setNewAction(String JavaDoc newAction) {
339         if (DEPLOY.equals(newAction)) {
340             setActionForAdd();
341         } else if (REDEPLOY.equals(newAction)) {
342             setActionForUpdate();
343         } else if (UNDEPLOY.equals(newAction)) {
344             setActionForDelete();
345         } else {
346             String JavaDoc msg = localStrings.getString( "admin.event.illegal_new_action", newAction );
347             throw new IllegalArgumentException JavaDoc( msg );
348         }
349     }
350
351     /**
352      * Is this event a no-op. An event can be no-op if a resource is created
353      * and then removed without reconfiguring the instance.
354      */

355     boolean isNoOp() {
356         return noOp;
357     }
358
359     public String JavaDoc toString() {
360         return "ResourceDeployEvent -- " + getAction() + " " + resourceType + "/" + getJ2EEComponentName();
361     }
362
363     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
364         ResourceDeployEvent re = (ResourceDeployEvent) super.clone();
365         return re;
366     }
367 }
368
Popular Tags