1 23 24 25 package com.sun.enterprise.admin.mbeans.custom; 26 27 import com.sun.enterprise.admin.common.MBeanServerFactory; 28 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 29 import com.sun.enterprise.admin.server.core.AdminService; 30 import com.sun.enterprise.admin.target.Target; 31 import com.sun.enterprise.admin.target.TargetBuilder; 32 import com.sun.enterprise.config.ConfigContext; 33 import com.sun.enterprise.config.serverbeans.Mbean; 34 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 35 import com.sun.enterprise.config.serverbeans.ServerTags; 36 import com.sun.enterprise.util.SystemPropertyConstants; 37 import java.util.ArrayList ; 38 import java.util.List ; 39 import javax.management.MBeanServerConnection ; 40 import javax.management.ObjectName ; 41 42 43 public class BasicCustomMBeanConfigQueries implements CustomMBeanConfigQueries { 44 45 protected final ConfigContext acc; 46 47 public BasicCustomMBeanConfigQueries() { 48 this.acc = MBeanRegistryFactory.getAdminContext().getAdminConfigContext(); 49 } 50 51 public boolean existsMBean(String target, String name) throws CustomMBeanException { 52 final List <String > names = this.listMBeanNames(target); 53 boolean exists = false; 54 for (String aName : names) { 55 if (aName.equals(name)) { 56 exists = true; 57 break; 58 } 59 } 60 return ( exists ); 61 } 62 63 public boolean isMBeanEnabled(String target, String name) throws CustomMBeanException { 64 boolean enabled = false; 65 if (!existsMBean(target, name)) { 66 final String msg = CMBStrings.get("MBeanNotFound", name, target); 67 throw new CustomMBeanException(msg); 68 } 69 final List <ObjectName > ons = this.listMBeanConfigObjectNames(target); 70 try { 72 final MBeanServerConnection mbsc = MBeanServerFactory.getMBeanServer(); final String noe = ServerTags.ENABLED; 74 for (ObjectName on : ons) { 75 final String s = (String ) mbsc.getAttribute(on, noe); 76 if (Boolean.valueOf(s).booleanValue()) { 77 enabled = true; 78 break; 79 } 80 } 81 return ( enabled ); 82 } catch (final Exception e) { 83 throw new CustomMBeanException (e); 84 } 85 } 86 87 public List <ObjectName > listMBeanConfigObjectNames(String target) throws CustomMBeanException { 88 Target t = null; 89 try { 90 t = TargetBuilder.INSTANCE.createTarget(target, this.acc); 91 } catch (final Exception e) { 92 throw new CustomMBeanException(e); 93 } 94 return ( this.listMBeanConfigObjectNamesForServer(t.getName()) ); 95 } 96 97 public List <ObjectName > listMBeanConfigObjectNames(String target, int type, boolean state) throws CustomMBeanException { 98 throw new UnsupportedOperationException (CMBStrings.get("NYI", "com.sun.enterprise.admin.mbeans.custom.BasicCustomMBeanConfigQueries.listMBeanConfigObjectNames")); 99 } 100 101 public List <String > listMBeanNames(String target) throws CustomMBeanException { 102 final List <ObjectName > ons = this.listMBeanConfigObjectNames(target); 103 final List <String > names = new ArrayList <String > (); 104 try { 106 final MBeanServerConnection mbsc = MBeanServerFactory.getMBeanServer(); final String noa = ServerTags.NAME; 108 for (ObjectName on : ons) { 109 final String voa = (String ) mbsc.getAttribute(on, noa); 110 names.add(voa); 111 } 112 return ( names ); 113 } catch(final Exception e) { 114 throw new CustomMBeanException(e); 115 } 116 } 117 118 121 protected List <ObjectName > listMBeanConfigObjectNamesForServer(final String s) throws RuntimeException { 122 try { 124 final List <Mbean> refdMbeans = ServerBeansFactory.getReferencedMBeans(acc, s); 125 return ( this.mbeans2ConfigMBeanObjectNames(refdMbeans) ); 126 } catch (final Exception e) { 127 throw new RuntimeException (e); 128 } 129 } 130 protected List <ObjectName > mbeans2ConfigMBeanObjectNames(List <Mbean> mbeans) throws RuntimeException { 131 try { 132 final List <ObjectName > ons = new ArrayList <ObjectName > (); 133 for (Mbean m : mbeans) { 134 final String domain = AdminService.PRIVATE_MBEAN_DOMAIN_NAME; 135 final ObjectName on = MBeanRegistryFactory.getAdminMBeanRegistry().getObjectNameForConfigBean(m, domain); 136 ons.add(on); 137 } 138 return ( ons ) ; 139 } catch (final Exception e) { 140 throw new RuntimeException (e); 141 } 142 } 143 } 144 | Popular Tags |