KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > event > ApplicationEvent


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  * @(#) ApplicationLoaderEventListener.java
26  *
27  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  *
31  * This software is the confidential and proprietary information
32  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
33  * You shall not disclose such Confidential Information and shall
34  * use it only in accordance with the terms of the license
35  * agreement you entered into with iPlanet/Sun Microsystems.
36  */

37 package com.sun.enterprise.server.event;
38
39 import com.sun.enterprise.deployment.Application;
40
41 /**
42  *
43  * ApplicationEvents are sent before/after an application
44  * is loaded/unloaded.
45  *
46  * Listeners that are interested in getting ApplicationLaoderEvents
47  * can register with the ApplicationLoaderEventNotifier as follows:
48  *
49  * ApplicationLoaderEventNotifier notifier =
50  * ApplicationLoaderEventNotifier.getInstance();
51  * notifier.addListener(listener);
52  *
53  * Application events are sent even when StandaloneModules are
54  * deployed / undeployed. ApplicationEvent.getApplication().isVirtual()
55  * will return true for stand-alone modules and false otherwise.
56  *
57  * Generally, APPLICATION events are sent in the following order
58  * a) BEFORE_APPLICATION_LOADED
59  * b) AFTER_APPLICATION_LOADED
60  * c) BEFORE_APPLICATION_UNLOADED
61  * d) AFTER_APPLICATION_UNLOADED
62  *
63  * Note:-
64  * There are some cases, when AFTER_APPLICATION_LOADED and
65  * BEFORE_APPLICATION_UNLOAD will not be sent to listeners.
66  * In particular, if an Ejb cannot be loaded successfully
67  * then no AFTER_APPLICATION_LOADED and BEFORE_APPLICATION_UNLOAD
68  * will be sent to the listeners.
69  *
70  */

71
72 public class ApplicationEvent {
73
74     public static final int BEFORE_APPLICATION_LOAD = 0;
75     public static final int AFTER_APPLICATION_LOAD = 1;
76     public static final int BEFORE_APPLICATION_UNLOAD = 2;
77     public static final int AFTER_APPLICATION_UNLOAD = 3;
78
79     private int eventType;
80     private Application application;
81     private ClassLoader JavaDoc loader;
82
83     public ApplicationEvent(int eventType, Application application,
84         ClassLoader JavaDoc loader)
85     {
86     this.eventType = eventType;
87     this.application = application;
88     this.loader = loader;
89     }
90     
91     public int getEventType() {
92     return this.eventType;
93     }
94
95     public Application getApplication() {
96     return this.application;
97     }
98
99     public ClassLoader JavaDoc getClassLoader() {
100     return this.loader;
101     }
102
103     public String JavaDoc toString() {
104         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc("AppEvent: ");
105         return toString(sbuf);
106     }
107     
108     /**
109      *Appends event info to the already-instantiated StringBuffer argument.
110      *@param StringBuffer already created and, optionally, already containing
111      *a prefix identfying which type of event this is.
112      */

113     protected String JavaDoc toString(StringBuffer JavaDoc sbuf) {
114     switch (eventType) {
115         case BEFORE_APPLICATION_LOAD:
116         sbuf.append("BEFORE_LOAD -> ");
117         break;
118         case AFTER_APPLICATION_LOAD:
119         sbuf.append("AFTER_LOAD -> ");
120         break;
121         case BEFORE_APPLICATION_UNLOAD:
122         sbuf.append("BEFORE_UNLOAD -> ");
123         break;
124         case AFTER_APPLICATION_UNLOAD:
125         sbuf.append("AFTER_UNLOAD -> ");
126         break;
127         default:
128         //
129
}
130
131     if (application != null) {
132         sbuf.append(application.getRegistrationName());
133     }
134     return sbuf.toString();
135     }
136
137 }
138
Popular Tags