KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > logging > LogLevelChangeEventListenerImpl


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 package com.sun.enterprise.server.logging;
25
26 import java.util.logging.ErrorManager JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import com.sun.enterprise.admin.event.LogLevelChangeEventListener;
34 import com.sun.enterprise.admin.event.LogLevelChangeEvent;
35 import com.sun.enterprise.admin.event.AdminEventListenerRegistry;
36 import com.sun.enterprise.admin.event.AdminEventListenerException;
37 import com.sun.enterprise.config.serverbeans.ElementProperty;
38 import com.sun.enterprise.config.ConfigContext;
39 import com.sun.enterprise.config.ConfigBean;
40 import com.sun.enterprise.config.ConfigChange;
41 import com.sun.enterprise.config.ConfigAdd;
42 import com.sun.enterprise.config.ConfigUpdate;
43
44 public class LogLevelChangeEventListenerImpl
45     implements LogLevelChangeEventListener
46 {
47     public void logLevelChanged(LogLevelChangeEvent event)
48         throws AdminEventListenerException
49     {
50         try {
51             if( event.isPropertyChanged() ) {
52                 ConfigContext newConfig = event.getConfigContext();
53                 Iterator JavaDoc iter = event.getConfigChangeList().iterator();
54                 while (iter.hasNext() ) {
55                     Object JavaDoc change= iter.next();
56                     if (change instanceof ConfigAdd || change instanceof ConfigUpdate) {
57                         String JavaDoc xpath = ((ConfigChange)change).getXPath();
58                         if( xpath != null){
59                             ConfigBean item = newConfig.exactLookup(xpath);
60                             if (item instanceof ElementProperty) {
61                                 ElementProperty elementProperty = (ElementProperty)item;
62                                 String JavaDoc loggerName = elementProperty.getName();
63                                 String JavaDoc logLevel = elementProperty.getValue();
64                                 boolean logExists = LogMBean.getInstance().findLogger(loggerName);
65                                 if (!logExists) {
66                                     Logger.getLogger(loggerName); //if the logger doesn't exist, create it.
67
}
68                                 LogMBean.getInstance().setLogLevel( loggerName, logLevel );
69                             }
70                         }
71                     }
72                 }
73             } else {
74                 // This is not a property change event, so it must be a
75
// module log level change.
76
LogMBean.getInstance().setLogLevelForModule(
77                     event.getModuleName(), event.getNewLogLevel() );
78             }
79         } catch( Exception JavaDoc e ) {
80             new ErrorManager JavaDoc().error( "Error In LogLevelChanged event", e,
81                 ErrorManager.GENERIC_FAILURE );
82         }
83     }
84 }
85
Popular Tags