KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > reconfig > HttpListenerReconfig


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.web.reconfig;
25
26 import com.sun.enterprise.admin.event.AdminEventListener;
27 import com.sun.enterprise.admin.event.AdminEventListenerException;
28 import com.sun.enterprise.admin.event.http.HSHttpListenerEvent;
29 import com.sun.enterprise.admin.event.http.HSHttpListenerEventListener;
30 import org.apache.catalina.LifecycleException;
31 import com.sun.enterprise.config.ConfigAdd;
32 import com.sun.enterprise.config.ConfigChange;
33 import com.sun.enterprise.config.ConfigContext;
34 import com.sun.enterprise.config.ConfigException;
35 import com.sun.enterprise.config.ConfigUpdate;
36 import com.sun.enterprise.config.ConfigBean;
37 import com.sun.enterprise.config.serverbeans.Config;
38 import com.sun.enterprise.config.serverbeans.ElementProperty;
39 import com.sun.enterprise.config.serverbeans.HttpListener;
40 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
41 import com.sun.enterprise.config.serverbeans.Server;
42 import com.sun.enterprise.web.PEWebContainer;
43
44 import java.util.ArrayList JavaDoc;
45
46 /**
47  * This class handles dynamic reconfiguration notification related to
48  * http-listener creation, update and deletion.
49  *
50  * @author Jean-Francois Arcand
51  */

52 public class HttpListenerReconfig implements HSHttpListenerEventListener{
53     
54     private static PEWebContainer webContainer =
55                                  ((PEWebContainer)PEWebContainer.getInstance());
56     
57     /**
58      * Create a new http-listener.
59      */

60     public void handleCreate(HSHttpListenerEvent event)
61                                             throws AdminEventListenerException {
62         
63         if ( webContainer == null) return;
64         
65         try{
66             ConfigContext configContext = event.getConfigContext();
67             Config config = ServerBeansFactory.getConfigBean(configContext);
68             
69             if ( config == null) return;
70             
71             ConfigAdd configAdd = null;
72             ArrayList JavaDoc configChangeList = event.getConfigChangeList();
73             HttpListener httpBean = null;
74             String JavaDoc xpath = null;
75             Object JavaDoc object;
76             Object JavaDoc configObject;
77             
78             for (int i=0; i < configChangeList.size(); i++){
79                 configObject = configChangeList.get(i);
80
81                 if ( configObject instanceof ConfigAdd) {
82                     configAdd = (ConfigAdd)configObject;
83                     xpath = configAdd.getXPath();
84                     // We are only interested on config change for VirtualServer.
85
if( xpath != null){
86                         object = configContext.exactLookup(xpath);
87                         if ( object instanceof HttpListener){
88                             httpBean = (HttpListener)object;
89                             webContainer.createConnector(httpBean,
90                                                          config.getHttpService());
91                         }
92                     }
93                 }
94             }
95         } catch (Exception JavaDoc ex) {
96            throw new AdminEventListenerException(ex);
97         }
98     }
99     
100     
101     /**
102      * Update an existing http-listener.
103      */

104     public void handleUpdate(HSHttpListenerEvent event)
105                                             throws AdminEventListenerException {
106         
107         if ( webContainer == null) return;
108                                      
109         try{
110             ConfigContext configContext = event.getConfigContext();
111             Config config = ServerBeansFactory.getConfigBean(configContext);
112             
113             if ( config == null) return;
114             
115             ConfigChange configChange = null;
116             ArrayList JavaDoc<ConfigChange> configChangeList =
117                                                     event.getConfigChangeList();
118             HttpListener httpBean = null;
119             String JavaDoc xpath = null;
120             Object JavaDoc object;
121             ElementProperty elementProperty = null;
122              
123             for (int i=0; i < configChangeList.size(); i++){
124                 configChange = configChangeList.get(i);
125
126                 xpath = configChange.getXPath();
127                 if( xpath != null){
128                     object = configContext.exactLookup(xpath);
129                     if ( object instanceof HttpListener){
130                         httpBean = (HttpListener)object;
131                         webContainer.updateConnector(httpBean,
132                                                      config.getHttpService());
133                     } else if ( object instanceof ElementProperty) {
134                         // This is a property.
135
xpath = xpath.substring(0,xpath.lastIndexOf("/"));
136                         httpBean = (HttpListener)configContext.exactLookup(xpath);
137                         elementProperty = (ElementProperty)object;
138                         webContainer.updateConnectorProperty(
139                            httpBean,
140                            elementProperty.getName(),
141                            elementProperty.getValue());
142                     }
143                 }
144             }
145         } catch (Exception JavaDoc ex) {
146            throw new AdminEventListenerException(ex);
147         }
148     }
149     
150     
151     /**
152      * Delete an existing http-listener.
153      *
154      * Implementation note: we cannot use the same approach used when
155      * handling create/update event since the element is deleted before this
156      * method is invoked (strange behaviour). Instead we need to find by
157      * ourself which http-listener has been deleted.
158      */

159     public void handleDelete(HSHttpListenerEvent event)
160                                             throws AdminEventListenerException {
161          
162         if ( webContainer == null) return;
163         
164         try{
165             if( event != null){
166                 ConfigContext configContext = event.getConfigContext();
167                 Config config = ServerBeansFactory.getConfigBean(configContext);
168                 
169                 if ( config == null) return;
170                 
171                 webContainer.deleteConnector(config.getHttpService());
172             }
173         } catch( Exception JavaDoc ex){
174            throw new AdminEventListenerException(ex);
175         }
176     }
177 }
178
Popular Tags