1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import java.util.Map ; 31 import java.util.logging.Level ; 32 33 import javax.management.*; 34 35 import com.sun.enterprise.admin.util.jmx.AttributeListUtils; 36 import com.sun.enterprise.config.ConfigException; 37 import com.sun.enterprise.admin.config.BaseConfigMBean; 38 39 public class HttpListenerMBean extends BaseConfigMBean 40 implements MBeanRegistration 41 { 42 private ObjectName on; 43 44 static final String DEFAULT_VIRTUAL_SERVER = "default_virtual_server"; 45 46 public void setAttribute(Attribute attribute) 47 throws AttributeNotFoundException, MBeanException, ReflectionException 48 { 49 String oldVs = null; 50 if (isDefaultVirtualServer(attribute)) 51 { 52 oldVs = (String )super.getAttribute(DEFAULT_VIRTUAL_SERVER); 53 } 54 55 super.setAttribute(attribute); 56 57 if (isDefaultVirtualServer(attribute)) 58 { 59 try 60 { 61 changeHttpListenerRef(oldVs, (String )attribute.getValue()); 62 } 63 catch (ConfigException ce) 64 { 65 throw new MBeanException(ce); 66 } 67 } 68 } 69 70 public AttributeList setAttributes(AttributeList list) 71 { 72 String oldVs = null; 73 if (isDefaultVirtualServerExists(list)) 74 { 75 try 76 { 77 oldVs = (String )super.getAttribute(DEFAULT_VIRTUAL_SERVER); 78 } 79 catch (JMException e) 80 { 81 } 83 } 84 AttributeList al = super.setAttributes(list); 85 if (isDefaultVirtualServerExists(list) && 86 isDefaultVirtualServerExists(al)) 87 { 88 try 89 { 90 changeHttpListenerRef(oldVs, getDefaultVirtualServer(list)); 91 } 92 catch (ConfigException ce) 93 { 94 _sLogger.log(Level.WARNING, 95 "httplistenerMBean.failed_to_add_http_listener_ref",ce); 96 } 97 } 98 return al; 99 } 100 101 public ObjectName preRegister(MBeanServer server, ObjectName name) 102 throws Exception 103 { 104 on = super.preRegister(server, name); 105 return on; 106 } 107 108 private void changeHttpListenerRef(String oldVs, String newVs) 109 throws ConfigException 110 { 111 HttpListenerVirtualServerAssociationMgr mgr = 112 new HttpListenerVirtualServerAssociationMgr( 113 super.getConfigContext(), on.getKeyProperty("config")); 114 final String id = on.getKeyProperty("id"); 115 mgr.changeHttpListenerRef(id, oldVs, newVs); 116 } 117 118 private boolean isDefaultVirtualServer(Attribute a) 119 { 120 return a.getName().equals(DEFAULT_VIRTUAL_SERVER); 121 } 122 123 private boolean isDefaultVirtualServerExists(AttributeList al) 124 { 125 return AttributeListUtils.containsNamedAttribute(al, 126 DEFAULT_VIRTUAL_SERVER); 127 } 128 129 private String getDefaultVirtualServer(AttributeList al) 130 { 131 final Map map = AttributeListUtils.asNameMap(al); 132 final Attribute val = (Attribute)map.get(DEFAULT_VIRTUAL_SERVER); 133 return (String )val.getValue(); 134 } 135 } 136 | Popular Tags |