private static void WriteDomain(TextWriter writer, MBeanDomain domain)
 {
     writer.WriteLine("<span class=\"folder\">{0}</span>", domain.Name);
     writer.WriteLine("<ul>");
     WriteDomainItems(writer, domain);
     writer.WriteLine("</ul>");
 }
        public MBeanServerResource Get()
        {
            var beans = _serverConnection.QueryNames(null, null);
            var delegateBeanProxy = _serverConnection.CreateDynamicProxy(MBeanServerDelegate.ObjectName);

            var rootDomain = new MBeanDomain();

            foreach (var bean in beans)
            {
                var nameParts = bean.Domain.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
                var domainParts = nameParts.Take(nameParts.Length - 1).ToArray();
                var currentDomain = EnsureSubdomain(rootDomain, domainParts);
                currentDomain.Beans.Add(new Resources.MBeanInfo
                                            {
                                                ObjectName = bean.CanonicalName,
                                                ShortName = nameParts.Last()+":"+bean.KeyPropertyListString,
                                                HRef = GetResourceUrl("bean", new {objectName = bean.CanonicalName})
                                            });
            }

            var resource = new MBeanServerResource
                               {
                                   RootDomain = rootDomain,
                                   InstanceName = delegateBeanProxy.MBeanServerId,
                                   Version = delegateBeanProxy.ImplementationVersion,
                                   StaticViewHref = GetResourceUrl("server", new {}),
                                   DynamicViewHref = GetResourceUrl("ui", new { contentFile = "mbeanserver.htm" })
                               };

            return resource;
        }
 private static void WriteDomainItems(TextWriter writer, MBeanDomain domain)
 {
     foreach (var bean in domain.Beans)
     {
         writer.WriteLine("<li><span class=\"file\"><a href=\"{0}\">{1}</a></span></li>", bean.HRef, bean.ShortName);
     }
     foreach (var subdomain in domain.Subdomains)
     {
         writer.WriteLine("<li>");
         WriteDomain(writer, subdomain);
         writer.WriteLine("</li>");
     }
 }
 private static MBeanDomain EnsureSubdomain(MBeanDomain currentDomain, string[] domainParts)
 {
     foreach (var domainPartName in domainParts)
     {
         var subdomain = currentDomain.Subdomains.FirstOrDefault(x => x.Name == domainPartName);
         if (subdomain == null)
         {
             subdomain = new MBeanDomain()
                             {
                                 Name = domainPartName
                             };
             currentDomain.Subdomains.Add(subdomain);
         }
         currentDomain = subdomain;
     }
     return currentDomain;
 }