KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > ConfigContextEvent


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

39
40 package com.sun.enterprise.config;
41
42
43
44 import javax.management.Notification JavaDoc;
45
46
47
48 /**
49
50  * event used for notification of changes
51
52  */

53
54 public class ConfigContextEvent extends Notification JavaDoc {
55
56    
57     public static final String JavaDoc PRE_ACCESS = "PRE_ACCESS";
58
59     public static final String JavaDoc POST_ACCESS = "POST_ACCESS";
60
61     public static final String JavaDoc PRE_ADD_CHANGE = "PRE_ADD_CHANGE";
62
63     public static final String JavaDoc POST_ADD_CHANGE = "POST_ADD_CHANGE";
64
65     public static final String JavaDoc PRE_UPDATE_CHANGE = "PRE_UPDATE_CHANGE";
66
67     public static final String JavaDoc POST_UPDATE_CHANGE = "POST_UPDATE_CHANGE";
68
69     public static final String JavaDoc PRE_DELETE_CHANGE = "PRE_DELETE_CHANGE";
70
71     public static final String JavaDoc POST_DELETE_CHANGE = "POST_DELETE_CHANGE";
72
73     public static final String JavaDoc PRE_SET_CHANGE = "PRE_SET_CHANGE";
74
75     public static final String JavaDoc POST_SET_CHANGE = "POST_SET_CHANGE";
76
77     public static final String JavaDoc PRE_FLUSH_CHANGE = "PRE_FLUSH_CHANGE";
78
79     public static final String JavaDoc POST_FLUSH_CHANGE = "POST_FLUSH_CHANGE";
80
81
82
83     private static long eventCounter = 0;
84
85     private String JavaDoc name;
86
87     private Object JavaDoc value;
88
89     private String JavaDoc choice;
90
91     private String JavaDoc beanName;
92
93     /* The classObject will represent the true config bean that is being invoked
94
95      * through the admin GUI.
96
97      */

98
99     private Object JavaDoc classObject;
100
101     //</addition>
102

103
104
105     /**
106
107      * Create a new ConfigChangeEvent event.
108
109      * @param ctx ConfigContext which is the source
110
111      */

112
113     public ConfigContextEvent(ConfigContext ctx, String JavaDoc eventType) {
114
115         super(eventType, ctx, ++eventCounter, System.currentTimeMillis());
116
117     }
118
119     
120
121     // <addition> srini@sun.com server.xml verifier
122

123     public ConfigContextEvent(final ConfigContext ctx,
124                               final String JavaDoc eventType,
125                               final String JavaDoc name,
126                               final Object JavaDoc value,
127                               final String JavaDoc choice) {
128         this(ctx, eventType, name, value, choice, null);
129    }
130
131     public ConfigContextEvent(final ConfigContext ctx,
132                               final String JavaDoc eventType,
133                               final String JavaDoc name,
134                               final Object JavaDoc value,
135                               final String JavaDoc choice,
136                               final String JavaDoc beanName) {
137         this(ctx,eventType);
138         this.name = name;
139         this.value = value;
140         this.choice = choice;
141         this.beanName = beanName;
142     }
143
144     
145
146   
147
148     public Object JavaDoc getObject(){
149
150         return value;
151
152     }
153
154     
155
156     public String JavaDoc getName(){
157
158         return name;
159
160     }
161
162     
163
164     public String JavaDoc getChoice(){
165
166         return choice;
167
168     }
169
170     
171
172     public void setBeanName(String JavaDoc beanName){
173
174         this.beanName = beanName;
175
176     }
177
178     
179
180     public String JavaDoc getBeanName() {
181
182         return beanName;
183
184     }
185
186     // </addition> server.xml verifier
187

188
189
190     /**
191
192      * Returns ConfigContext which is the source of the event. The difference
193
194      *
195
196      * @see getSource()
197
198      * @return ConfigContext
199
200      */

201
202     public ConfigContext getConfigContext() {
203
204         return (ConfigContext)getSource();
205
206     }
207
208
209
210     /**
211
212      * Return a String representation.
213
214      */

215
216     public String JavaDoc toString() {
217
218         return this.getClass().getName() + " -- "
219
220                 + " [Id:" + this.getSequenceNumber()
221
222                 + ", ts:" + this.getTimeStamp() + "]";
223
224     }
225
226     
227
228     //<addition author="irfan@sun.com" [bug/rfe]-id="4704985" >
229

230     /** The function returns the classObject which is set through the base config
231
232      * bean. The classObject represents the actual config bean that has been
233
234      * invoked through the admin GUI
235
236      *
237
238      * @return Object
239
240      */

241
242     public Object JavaDoc getClassObject()
243
244     {
245
246         return classObject;
247
248     }
249
250     
251
252     /** The function is called from the ConfigBean class and sets the actual
253
254      * config bean as the classObject.
255
256      *
257
258      * @param Object - ConfigBean object representing the actual config bean
259
260      */

261
262     public void setClassObject(Object JavaDoc obj)
263
264     {
265
266         this.classObject = obj;
267
268     }
269
270     //</addition>
271

272             /**
273            Return the object which is the target of the validation,
274            given the {@link ConfigContextEvent}
275            @param cce the {@link ConfigContextEvent} from which the
276            target is to be found
277            @return the {@link ConfigBean} target
278            object which is to be validated.
279            @throws {@link ConfigException} if the validation target
280            cannot be obtained.
281          */

282         // The validation target is the class that a *Test class is
283
// testing. Its in different places in the ConfigContextEvent
284
// for different kinds of event. Where it is is simply a
285
// matter of convention, not enforced by any programmatic
286
// construct. See
287
// appserv-commons/src/java/com/sun/enterprise/config/ConfigBean
288
// for what gets loaded where!
289
public ConfigBean getValidationTarget() throws ConfigException{
290         final String JavaDoc choice = this.getChoice();
291         if (choice.equals("VALIDATE")){
292             return (ConfigBean) this.getObject();
293         } else if (choice.equals("ADD")) {
294             return (ConfigBean) this.getObject();
295         } else if (choice.equals("DELETE")) {
296             return (ConfigBean) this.getObject();
297         } else if (choice.equals("UPDATE")) {
298             return (ConfigBean) this.getClassObject();
299         } else if (choice.equals("SET")) {
300             if (null == this.getBeanName()){
301                 if (this.getName().equals("Description")){
302                     throw new ConfigException("Internal error - invalid condition - attempting to validate a SET operation with a \"Description\" object");
303                 } else {
304                     return (ConfigBean) this.getObject();
305                 }
306             } else {
307                 return (ConfigBean) this.getClassObject();
308             }
309         } else {
310             throw new ConfigException("Internal error - invalid choice received: \""+choice+"\". Only expecting ADD, DELETE, UPDATE or SET");
311         }
312     }
313     
314     
315
316
317 }
318
319
Popular Tags