1 23 24 package com.sun.enterprise.management.selfmanagement.reconfig; 25 26 import com.sun.enterprise.management.selfmanagement.SelfManagementService; 27 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent; 28 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEventListener; 29 30 import com.sun.enterprise.admin.event.AdminEventListener; 31 import com.sun.enterprise.admin.event.AdminEventListenerException; 32 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent; 33 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEventListener; 34 import com.sun.enterprise.config.ConfigAdd; 35 import com.sun.enterprise.config.ConfigSet; 36 import com.sun.enterprise.config.ConfigDelete; 37 import com.sun.enterprise.config.ConfigChange; 38 import com.sun.enterprise.config.ConfigContext; 39 import com.sun.enterprise.config.ConfigException; 40 import com.sun.enterprise.config.ConfigUpdate; 41 import com.sun.enterprise.config.ConfigBean; 42 import com.sun.enterprise.config.serverbeans.Config; 43 import com.sun.enterprise.config.serverbeans.ElementProperty; 44 import com.sun.enterprise.config.serverbeans.ManagementRules; 45 import com.sun.enterprise.config.serverbeans.ManagementRule; 46 import com.sun.enterprise.config.serverbeans.Action; 47 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 48 import com.sun.enterprise.config.serverbeans.Server; 49 50 import java.util.ArrayList ; 51 import java.util.logging.Logger ; 52 import java.util.logging.Level ; 53 import com.sun.logging.LogDomains; 54 55 61 public class ManagementRuleReconfig implements ManagementRuleEventListener{ 62 63 private static SelfManagementService service = 64 SelfManagementService.getService(); 65 66 67 private static Logger _logger = null; 68 69 static { 70 _logger = LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER); 71 } 72 73 76 public void handleCreate(ManagementRuleEvent event) 77 throws AdminEventListenerException { 78 _logger.log(Level.FINE,"sgmt.reconfig_handlecreatereceived"); 79 80 try{ 81 ConfigContext configContext = event.getConfigContext(); 82 Config config = ServerBeansFactory.getConfigBean(configContext); 83 ConfigAdd configAdd = null; 84 ConfigChange configChange = null; 85 ArrayList <ConfigChange> configChangeList = event.getConfigChangeList(); 86 ManagementRule rule = null; 87 String xpath = null; 88 String pXPath = null; 89 Object object; 90 91 for (int i=0; i < configChangeList.size(); i++){ 92 configChange = configChangeList.get(i); 93 if (configChange instanceof ConfigAdd) { 94 _logger.log(Level.INFO,"sgmt.reconfig_handlecreaterulereceived"); 95 xpath = configChange.getXPath(); 96 if (xpath != null) { 98 _logger.log(Level.INFO, "sgmt.reconfig_handlexpath",xpath); 99 rule = (ManagementRule)configContext.exactLookup(xpath); 100 if (rule.isEnabled()) { 101 service.addRule(rule, configContext); 102 } else { 103 service.addDisabledRule(rule); 104 } 105 } 106 } else if(configChange instanceof ConfigSet) { 107 pXPath = configChange.getParentXPath(); 109 String name = configChange.getName(); 110 if (name.equals(ManagementRule.ACTION)) { 111 _logger.log(Level.INFO,"smgt.handleactionadd",pXPath); 112 rule = (ManagementRule)configContext.exactLookup(pXPath); 113 service.handleActionAdd(rule, configContext); 114 } 115 } 116 } 117 } catch (Exception ex) { 118 throw new AdminEventListenerException(ex); 119 } 120 } 121 122 123 126 public void handleUpdate(ManagementRuleEvent event) 127 throws AdminEventListenerException { 128 _logger.log(Level.INFO,"sgmt.reconfig_handleupdatereceived"); 129 130 try { 131 ConfigContext configContext = event.getConfigContext(); 132 ConfigContext oldConfigContext = event.getOldConfigContext(); 133 Config config = ServerBeansFactory.getConfigBean(configContext); 134 ConfigUpdate configUp = null; 135 ArrayList <ConfigUpdate> configChangeList = event.getConfigChangeList(); 136 String xPath = null; 137 Object object; 138 139 for (int i=0; i < configChangeList.size(); i++){ 140 configUp = configChangeList.get(i); 141 142 xPath = configUp.getXPath(); 143 if (xPath!=null) { 144 _logger.log(Level.INFO,"sgmt.handleupdatexpath", xPath); 145 object = configContext.exactLookup(xPath); 146 if (object instanceof ManagementRules) { 147 ManagementRules rules = (ManagementRules)object; 148 service.handleRulesUpdate(configContext,configUp); 149 } else if(object instanceof ManagementRule) { 150 ManagementRule rule = (ManagementRule)oldConfigContext.exactLookup(xPath); 151 service.handleRuleUpdate(rule,configUp,configContext); 152 } else if (object instanceof Action) { 153 String pXPath = xPath.substring(0,xPath.lastIndexOf("/"));; 154 ManagementRule rule = (ManagementRule)configContext.exactLookup(pXPath); 155 service.handleActionUpdate(rule,configUp); 156 } 157 } 158 } 159 160 161 } catch (Exception ex) { 162 throw new AdminEventListenerException(ex); 163 } 164 165 } 166 167 168 171 public void handleDelete(ManagementRuleEvent event) 172 throws AdminEventListenerException { 173 _logger.log(Level.INFO,"sgmt.reconfig_handledeletereceived"); 174 try{ 175 ConfigContext configContext = event.getOldConfigContext(); 176 Config config = ServerBeansFactory.getConfigBean(configContext); 177 ConfigDelete configDel = null; 178 ArrayList <ConfigDelete> configChangeList = event.getConfigChangeList(); 179 ManagementRule rule = null; 180 String xpath = null; 181 Object object; 182 183 for (int i=0; i < configChangeList.size(); i++){ 184 configDel = configChangeList.get(i); 185 186 xpath = configDel.getXPath(); 187 if (xpath != null){ 188 _logger.log(Level.INFO, "sgmt.reconfig_handledelxpath",xpath); 189 object = configContext.exactLookup(xpath); 191 if (object instanceof Action) { 192 } else if (object instanceof ManagementRule) { 194 rule = (ManagementRule)object; 195 String ruleName = rule.getName(); 196 service.deleteRule(ruleName); 197 } 198 } 199 } 200 } catch( Exception ex){ 201 throw new AdminEventListenerException(ex); 202 } 203 } 204 } 205 | Popular Tags |