void JBossAppServerInstance::UpdateJBoss4Ports()

in source/code/providers/support/appserver/jbossappserverinstance.cpp [496:592]


    void JBossAppServerInstance::UpdateJBoss4Ports()
    {
        const string cServerNodeName("server");
        const string cMbeanNodeName("mbean");
        const string cCodeAttributeName("code");
        const string cServiceBindingManagerName("org.jboss.services.binding.ServiceBindingManager");
        const string cAttributeNodeName("attribute");
        const string cNameAttributeName("name");
        const string cServerNameName("ServerName");
        const string cStoreUrlName("StoreURL");
        const wstring cHomeUrlName(L"${jboss.home.url}/");

        SCXFilePath filename(m_diskPath);

        string xmlcontent;
        filename.Append(L"/conf/jboss-service.xml");

        try {
            SCXHandle<istream> mystream = m_deps->OpenXmlServiceFile(filename.Get());
            GetStringFromStream(mystream, xmlcontent);

            XElementPtr serverNode;
            XElement::Load(xmlcontent, serverNode);
            if (serverNode->GetName() == cServerNodeName)
            {
                XElementList mbeanNodes;
                bool foundnode = false;

                serverNode->GetChildren(mbeanNodes);
                for (size_t mbeanNodeIdx = 0; !foundnode && mbeanNodeIdx < mbeanNodes.size(); ++mbeanNodeIdx)
                {
                    string codeprop;

                    if (mbeanNodes[mbeanNodeIdx]->GetName() == cMbeanNodeName && 
                        mbeanNodes[mbeanNodeIdx]->GetAttributeValue(cCodeAttributeName, codeprop) && 
                        cServiceBindingManagerName == codeprop)
                    {
                        XElementList attrNodes;
                        bool foundname = false;
                        bool foundurl = false;
                        string serverName("");
                        wstring storeUrl(L"");

                        foundnode = true;

                        mbeanNodes[mbeanNodeIdx]->GetChildren(attrNodes);
                        for (size_t attrNodeIdx = 0; !(foundname && foundurl) && attrNodeIdx < attrNodes.size(); ++attrNodeIdx)
                        {
                            string nameprop;

                            if (attrNodes[attrNodeIdx]->GetName() == cAttributeNodeName && 
                                attrNodes[attrNodeIdx]->GetAttributeValue(cNameAttributeName, nameprop))
                            {
                                if (cServerNameName == nameprop)
                                {
                                    foundname = true;
                                    attrNodes[attrNodeIdx]->GetContent(serverName);
                                }
                                else if (cStoreUrlName == nameprop)
                                {
                                    foundurl = true;
                                    attrNodes[attrNodeIdx]->GetContent(storeUrl);
                                }
                            }
                        }

                        if (foundname && foundurl)
                        {
                            size_t homePos = storeUrl.find(cHomeUrlName);
                            if (homePos != wstring::npos)
                            {
                                storeUrl.replace(homePos, cHomeUrlName.length(), m_basePath);
                            }
                            UpdateJBoss4PortsFromServiceBinding(storeUrl, serverName);
                        }
                    }
                }

                if (!foundnode)
                {
                    UpdateJBoss4PortsFromServerConfiguration();
                }
            }
        }
        catch (SCXFilePathNotFoundException&)
        {
            SCX_LOGERROR(m_log, wstring(L"JBossAppServerInstance::UpdateJBoss4Ports() - ").append(GetId()).append(L" - Could not find file: ").append(filename));
        }
        catch (SCXUnauthorizedFileSystemAccessException&)
        {
            SCX_LOGERROR(m_log, wstring(L"JBossAppServerInstance::UpdateJBoss4Ports() - ").append(GetId()).append(L" - not authorized to open file: ").append(filename));
        }
        catch (XmlException&)
        {
            SCX_LOGERROR(m_log, wstring(L"JBossAppServerInstance::UpdateJBoss4Ports() - ").append(GetId()).append(L" - Could not load XML from file: ").append(filename));
        }
    }