Пример #1
0
 public function configure($basePath)
 {
     /*Document*/
     $configDoc = new DomDocument();
     //        try
     //        {
     //	         SAXBuilder builder = new SAXBuilder();
     //
     //       	 byte[] configBytes = ClassLoaders.loadResourceBytes( basePath + File.separator + getConfigFileName() );
     //       	 configDoc = builder.build( new ByteArrayInputStream( configBytes ));
     //        }
     //        catch( Throwable exception )
     //        {
     //            if( Log.isLogging( LoggingConstants.ERROR ) )
     //                Log.log( LoggingConstants.ERROR, "Unable to parse " + getConfigFileName(), exception );
     //
     //            return;
     //        }
     $configDoc->load($basePath . "/" . $this->getConfigFileName());
     /*Element*/
     $root = $configDoc->documentElement;
     /*List*/
     $channelDefinitions = XmlUtil::getChild($root, self::CHANNELS)->getElementsByTagName(self::CHANNEL_DEFINITION);
     for ($i = 0, $max = $channelDefinitions->length; $i < $max; $i++) {
         /*Element*/
         $channelDefinition = $channelDefinitions->item($i);
         /*Element*/
         $endpointElement = XmlUtil::getChild($channelDefinition, self::ENDPOINT);
         /*String*/
         $id = $channelDefinition->getAttribute("id");
         /*String*/
         $endpoint = $endpointElement->getAttribute("uri");
         /*Channel*/
         $channel = new Channel($id, $endpoint);
         $channel->setChannelClass($channelDefinition->getAttribute("class"));
         $channel->setEndpointClass($endpointElement->getAttribute("class"));
         $channel->setProperties($this->parseProperties(XmlUtil::getChild($channelDefinition, "properties")));
         $this->serviceChannels[] = $channel;
     }
 }
 public function saveServerConfiguration(ServerConfiguration $configuration)
 {
     $this->configuration = $configuration;
     /*Element*/
     $serverConfigurationElement = XmlUtil::getChild($this->configElement, ORBConstants::RBISERVERCONFIGURATION);
     //$this->configElement->getElementsByTagName( ORBConstants::RBISERVERCONFIGURATION );
     if ($serverConfigurationElement != null) {
         $this->configElement->removeChild($serverConfigurationElement);
     }
     $dom = $this->orbConfig->dom;
     $serverConfigurationElement = $dom->createElement(ORBConstants::RBISERVERCONFIGURATION);
     $serverAddressElement = $dom->createElement("serverAddress", $configuration->serverAddress);
     $serverConfigurationElement->appendChild($serverAddressElement);
     $reconnectionTimeoutElement = $dom->createElement("reconnectionTimeout", $configuration->reconnectionTimeout);
     $serverConfigurationElement->appendChild($reconnectionTimeoutElement);
     $this->configElement->appendChild($serverConfigurationElement);
     $this->orbConfig->Save();
 }
 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);
 }