public static function saveConfig()
 {
     self::$configDoc->save(OrbConfig::getInstance()->getFlexConfigPath() . self::REMOTINGSERVICE_FILE);
     //    	echo self::$configDoc->saveXml();exit;
 }
 public function update(ServiceDestination $serviceDestination, ServiceDestination $newServiceDestination)
 {
     $dom = FlexRemotingServiceConfig::getConfigDoc();
     if ($this->isReadOnly($serviceDestination)) {
         throw new Exception("Destination can't be updated");
     }
     if (!$serviceDestination->DestinationId == $newServiceDestination->DestinationId) {
         $this->checkExistance($newServiceDestination);
     }
     $this->validate($newServiceDestination);
     /*Element*/
     $root = $dom->documentElement;
     /*List*/
     $children = $root->getElementsByTagName("destination");
     /*Element*/
     $serviceDestinationNode = null;
     for ($i = 0; $i < $children->length; $i++) {
         $serviceDestinationNode = $children->item($i);
         if ($serviceDestinationNode->getAttribute("id") == $serviceDestination->DestinationId) {
             break;
         }
     }
     if ($serviceDestinationNode == null) {
         throw new Exception("Destination " . $serviceDestination->DestinationId . " not found");
     }
     /*Element*/
     $serviceDestinationNode = $this->findService($serviceDestination);
     /*Element*/
     $source = XmlUtil::getChild(XmlUtil::getChild($serviceDestinationNode, "properties"), "source");
     XmlUtil::getChild($serviceDestinationNode, "properties")->removeChild($source);
     XmlUtil::getChild($serviceDestinationNode, "properties")->appendChild($dom->createElement("source", $newServiceDestination->ServiceId));
     $serviceDestinationNode->setAttribute("id", $newServiceDestination->DestinationId);
     /*Element*/
     $channelsElement = XmlUtil::getChild($serviceDestinationNode, "channels");
     if ($channelsElement != null) {
         if ($newServiceDestination->Channel == "default channel") {
             $serviceDestinationNode->removeChild($channelsElement);
         } else {
             /*Element*/
             $channelElement = XmlUtil::getChild(channelsElement, "channel");
             if ($channelElement != null) {
                 $channelElement->setAttribute("ref", $newServiceDestination->Channel);
             } else {
                 $channelsElement->appendChild($dom->createElement("channel")->setAttribute("ref", $newServiceDestination->Channel));
             }
         }
     } else {
         if (!$newServiceDestination->Channel == "default channel") {
             $channelsElement = $dom->createElement("channels");
             $channelsElement->appendChild($dom->createElement("channel")->setAttribute("ref", $newServiceDestination->Channel));
             $serviceDestinationNode->appendChild($channelsElement);
         }
     }
     /*Element*/
     $securityElement = XmlUtil::getChild($serviceDestinationNode, "security");
     /*Element*/
     $rolesElement = null;
     /*Element*/
     $constraintElement = null;
     if (count($newServiceDestination->Roles) > 0) {
         if ($securityElement != null) {
             $constraintElement = XmlUtil::getChild($securityElement, "security-constraint");
         } else {
             $securityElement = $dom->createElement("security");
             $constraintElement = $dom->createElement("security-constraint");
             $securityElement->appendChild($constraintElement);
             $serviceDestinationNode->appendChild($securityElement);
         }
         if ($constraintElement != null) {
             $rolesElement = XmlUtil::getChild($constraintElement, "roles");
         } else {
             $constraintElement = $dom->createElement("security-constraint");
             $rolesElement = $dom->createElement("roles");
             $constraintElement->appendChild($rolesElement);
             $securityElement->appendChild($constraintElement);
         }
         if ($rolesElement == null) {
             $rolesElement = $dom->createElement("roles");
             $constraintElement->appendChild($rolesElement);
         } else {
             /*Element*/
             $role = XmlUtil::getChild($rolesElement, "role");
             $rolesElement->removeChildren($role);
         }
         for ($j = 0; $j < count($newServiceDestination->Roles); $j++) {
             /*Element*/
             $role = $dom->createElement("role", $newServiceDestination->Roles[$j]);
             $rolesElement->appendChild($role);
         }
     } else {
         /*Element*/
         $role = XmlUtil::getChild(XmlUtil::getChild(XmlUtil::getChild($securityElement, "security-constraint"), "roles"), "role");
         if (XmlUtil::getChild(XmlUtil::getChild($securityElement, "security-constraint"), "roles") != null) {
             XmlUtil::getChild(XmlUtil::getChild($securityElement, "security-constraint"), "roles")->removeChild($role);
         }
     }
     $dom->save(OrbConfig::getInstance()->getFlexConfigPath() . FlexRemotingServiceConfig::REMOTINGSERVICE_FILE);
     /*IDestination*/
     $dest = new FlexRemotingServiceConfig();
     $dest->processDestination(ORBConfig::getInstance(), $serviceDestination->DestinationId, $serviceDestinationNode);
     ORBConfig::getInstance()->getDataServices()->getDestinationManager()->addDestination($serviceDestination->DestinationId, $dest);
 }