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.HSVirtualServerEvent; 29 import com.sun.enterprise.admin.event.http.HSVirtualServerEventListener; 30 import com.sun.enterprise.config.ConfigAdd; 31 import com.sun.enterprise.config.ConfigContext; 32 import com.sun.enterprise.config.ConfigException; 33 import com.sun.enterprise.config.ConfigChange; 34 import com.sun.enterprise.config.ConfigBean; 35 import com.sun.enterprise.config.serverbeans.Config; 36 import com.sun.enterprise.config.serverbeans.ElementProperty; 37 import com.sun.enterprise.config.serverbeans.VirtualServer; 38 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 39 import com.sun.enterprise.config.serverbeans.Server; 40 import com.sun.enterprise.web.PEWebContainer; 41 42 import java.util.ArrayList ; 43 import java.util.Set ; 44 45 import org.apache.catalina.LifecycleException; 46 47 48 54 public class VirtualServerReconfig implements HSVirtualServerEventListener{ 55 56 private static PEWebContainer webContainer = 57 ((PEWebContainer)PEWebContainer.getInstance()); 58 59 62 public void handleCreate(HSVirtualServerEvent event) 63 throws AdminEventListenerException { 64 65 if ( webContainer == null) return; 66 67 try{ 68 ConfigContext configContext = event.getConfigContext(); 69 Config config = ServerBeansFactory.getConfigBean(configContext); 70 71 if ( config == null) return; 72 73 ConfigAdd configAdd = null; 74 ArrayList configChangeList = event.getConfigChangeList(); 75 VirtualServer vsBean = null; 76 String xpath = null; 77 Server serverBean = ServerBeansFactory.getServerBean(configContext); 78 ElementProperty elementProperty = null; 79 Object object; 80 Object configObject; 81 82 for (int i=0; i < configChangeList.size(); i++){ 83 configObject = configChangeList.get(i); 84 85 if ( configObject instanceof ConfigAdd) { 86 configAdd = (ConfigAdd)configObject; 87 xpath = configAdd.getXPath(); 88 if( xpath != null){ 89 object = configContext.exactLookup(xpath); 90 if ( object instanceof VirtualServer){ 92 vsBean = (VirtualServer)object; 93 webContainer.createHost(vsBean,configContext,true); 94 } else if (object instanceof ElementProperty) { 95 xpath = xpath.substring(0,xpath.lastIndexOf("/")); 97 vsBean = (VirtualServer)configContext.exactLookup(xpath); 98 elementProperty = (ElementProperty)object; 99 webContainer.updateHostProperties( 100 vsBean, 101 elementProperty.getName(), 102 elementProperty.getValue(), 103 config.getHttpService()); 104 } 105 } 106 } 107 } 108 } catch (Exception ex) { 109 throw new AdminEventListenerException(ex); 110 } 111 } 112 113 114 117 public void handleUpdate(HSVirtualServerEvent event) 118 throws AdminEventListenerException { 119 120 if ( webContainer == null) return; 121 122 try{ 123 ConfigContext configContext = event.getConfigContext(); 124 Config config = ServerBeansFactory.getConfigBean(configContext); 125 126 if ( config == null) return; 127 128 ConfigChange configChange = null; 129 ArrayList <ConfigChange> configChangeList = 130 event.getConfigChangeList(); 131 VirtualServer vsBean = null; 132 String xpath = null; 133 Server serverBean = ServerBeansFactory.getServerBean(configContext); 134 ElementProperty elementProperty = null; 135 Object object; 136 137 for (int i=0; i < configChangeList.size(); i++){ 138 configChange = configChangeList.get(i); 139 140 xpath = configChange.getXPath(); 141 if( xpath != null){ 142 object = configContext.exactLookup(xpath); 143 if ( object instanceof VirtualServer){ 144 vsBean = (VirtualServer)object; 145 webContainer.updateHost(vsBean, 146 config.getHttpService(), 147 serverBean); 148 } else if (object instanceof ElementProperty) { 149 xpath = xpath.substring(0,xpath.lastIndexOf("/")); 151 vsBean = (VirtualServer)configContext.exactLookup(xpath); 152 elementProperty = (ElementProperty)object; 153 webContainer.updateHostProperties( 154 vsBean, 155 elementProperty.getName(), 156 elementProperty.getValue(), 157 config.getHttpService()); 158 } 159 } 160 } 161 } catch (Exception ex) { 162 throw new AdminEventListenerException(ex); 163 } 164 } 165 166 167 175 public void handleDelete(HSVirtualServerEvent event) 176 throws AdminEventListenerException { 177 178 if ( webContainer == null) return; 179 180 try{ 181 if( event != null){ 182 ConfigContext configContext = event.getConfigContext(); 183 Config config = ServerBeansFactory.getConfigBean(configContext); 184 185 if ( config!= null) 186 webContainer.deleteHost(config.getHttpService()); 187 } 188 } catch( Exception ex){ 189 throw new AdminEventListenerException(ex); 190 } 191 } 192 } 193 194 195 | Popular Tags |