1 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 ; 45 46 52 public class HttpListenerReconfig implements HSHttpListenerEventListener{ 53 54 private static PEWebContainer webContainer = 55 ((PEWebContainer)PEWebContainer.getInstance()); 56 57 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 configChangeList = event.getConfigChangeList(); 73 HttpListener httpBean = null; 74 String xpath = null; 75 Object object; 76 Object 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 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 ex) { 96 throw new AdminEventListenerException(ex); 97 } 98 } 99 100 101 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 <ConfigChange> configChangeList = 117 event.getConfigChangeList(); 118 HttpListener httpBean = null; 119 String xpath = null; 120 Object 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 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 ex) { 146 throw new AdminEventListenerException(ex); 147 } 148 } 149 150 151 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 ex){ 174 throw new AdminEventListenerException(ex); 175 } 176 } 177 } 178 | Popular Tags |