1 17 18 package org.apache.catalina.mbeans; 19 20 21 import javax.management.Attribute ; 22 import javax.management.AttributeNotFoundException ; 23 import javax.management.InstanceNotFoundException ; 24 import javax.management.MBeanException ; 25 import javax.management.ReflectionException ; 26 import javax.management.RuntimeOperationsException ; 27 import javax.management.modelmbean.InvalidTargetObjectTypeException ; 28 29 import org.apache.catalina.deploy.ContextResource; 30 import org.apache.catalina.deploy.NamingResources; 31 import org.apache.tomcat.util.modeler.BaseModelMBean; 32 33 34 41 42 public class ContextResourceMBean extends BaseModelMBean { 43 44 45 47 48 57 public ContextResourceMBean() 58 throws MBeanException , RuntimeOperationsException { 59 60 super(); 61 62 } 63 64 65 67 68 70 71 83 public Object getAttribute(String name) 84 throws AttributeNotFoundException , MBeanException , 85 ReflectionException { 86 87 if (name == null) 89 throw new RuntimeOperationsException 90 (new IllegalArgumentException ("Attribute name is null"), 91 "Attribute name is null"); 92 93 ContextResource cr = null; 94 try { 95 cr = (ContextResource) getManagedResource(); 96 } catch (InstanceNotFoundException e) { 97 throw new MBeanException (e); 98 } catch (InvalidTargetObjectTypeException e) { 99 throw new MBeanException (e); 100 } 101 102 String value = null; 103 if ("auth".equals(name)) { 104 return (cr.getAuth()); 105 } else if ("description".equals(name)) { 106 return (cr.getDescription()); 107 } else if ("name".equals(name)) { 108 return (cr.getName()); 109 } else if ("scope".equals(name)) { 110 return (cr.getScope()); 111 } else if ("type".equals(name)) { 112 return (cr.getType()); 113 } else { 114 value = (String ) cr.getProperty(name); 115 if (value == null) { 116 throw new AttributeNotFoundException 117 ("Cannot find attribute "+name); 118 } 119 } 120 121 return value; 122 123 } 124 125 126 139 public void setAttribute(Attribute attribute) 140 throws AttributeNotFoundException , MBeanException , 141 ReflectionException { 142 143 if (attribute == null) 145 throw new RuntimeOperationsException 146 (new IllegalArgumentException ("Attribute is null"), 147 "Attribute is null"); 148 String name = attribute.getName(); 149 Object value = attribute.getValue(); 150 if (name == null) 151 throw new RuntimeOperationsException 152 (new IllegalArgumentException ("Attribute name is null"), 153 "Attribute name is null"); 154 155 ContextResource cr = null; 156 try { 157 cr = (ContextResource) getManagedResource(); 158 } catch (InstanceNotFoundException e) { 159 throw new MBeanException (e); 160 } catch (InvalidTargetObjectTypeException e) { 161 throw new MBeanException (e); 162 } 163 164 if ("auth".equals(name)) { 165 cr.setAuth((String )value); 166 } else if ("description".equals(name)) { 167 cr.setDescription((String )value); 168 } else if ("name".equals(name)) { 169 cr.setName((String )value); 170 } else if ("scope".equals(name)) { 171 cr.setScope((String )value); 172 } else if ("type".equals(name)) { 173 cr.setType((String )value); 174 } else { 175 cr.setProperty(name, ""+value); 176 } 177 178 NamingResources nr = cr.getNamingResources(); 181 nr.removeResource(cr.getName()); 182 nr.addResource(cr); 183 } 184 185 } 186 | Popular Tags |