void ossimPlanetSocketNetworkConnection::send(const ossimPlanetAction& a, const std::string& /*destination*/) 
{
   ossimString code;
   a.sourceCode(code);
   if (outBuffer_.empty())
   {
      int bytesWritten = theSocket->send(code.c_str(), code.length());
      if (bytesWritten != (int)code.length())
      {
         outBuffer_.append(code.substr(bytesWritten == -1 ? 0 : bytesWritten));
         outBuffer_.append(1, actionDelimiter_);
      }
      else
      {
         if (theSocket->send(&actionDelimiter_, 1) != 1)
         {
            outBuffer_.append(1, actionDelimiter_);
         }
      }
   }
   else
   {
      outBuffer_.append(code.string());
      outBuffer_.append(1, actionDelimiter_);
      attemptToFlushOutBuffer();
   }
}
void ossimPlanetLatLonHud::execute(const ossimPlanetAction& action)
{
#if 0
   if(action.command() == "init")
   {
      ossimPlanetLayer::execute(action); // initialize the base.
   }
   else
   {
      ossimPlanetLayer::execute(action);
   }
#endif  
}
void ossimPlanetAnnotationLayer::execute(const ossimPlanetAction& action)
{
   std::string command = action.command();
   const ossimPlanetXmlAction* xmlAction = action.toXmlAction();
   if(command == "Add")
   {
      // we will use the add action to get the child
      if(xmlAction&&xmlAction->xmlNode().valid()) 
      {
         const ossimXmlNode::ChildListType& children = xmlAction->xmlNode()->getChildNodes();
         ossim_uint32 idx = 0;
         for(idx = 0; idx < children.size(); ++idx)
         {
            ossimString tag = children[idx]->getTag();
            ossimString parentId = children[idx]->getAttributeValue("parentId");
            ossimString id = children[idx]->getChildTextValue("id");
            if(!id.empty())
            {
               ossimPlanetLayerNameIdSearchVisitor nv("", id);
               accept(nv);
               if(nv.node().get())
               {
                  // already an id exists with that value so we return and don't add
                  return;
               }
            }
            osg::ref_ptr<ossimPlanetNode> layerNode;
            if(tag != "Group")
            {
               layerNode = ossimPlanetNodeRegistry::instance()->create(tag);
            }
            if(!layerNode.valid()&&(tag == "Group"))
            {
               if(children[idx]->getAttributeValue("groupType")=="feature")
               {
                  layerNode = new ossimPlanetAnnotationGroupNode();
               }
            }
            if(layerNode.valid())
            {
					osg::ref_ptr<ossimPlanetXmlAction> tempAction = xmlAction->duplicateChildAndMaintainAction(idx);
					tempAction->setCommand("Set");
					layerNode->setLayer(this);
               layerNode->execute(*tempAction);
            }
				osg::ref_ptr<ossimPlanetAnnotationLayerNode> annotationNode = dynamic_cast<ossimPlanetAnnotationLayerNode*>(layerNode.get());
            if(annotationNode.valid())
            {
               OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theGraphMutex);
               if(!annotationNode->isStaged())
               {
                  theStagingThreadQueue->add(new ossimPlanetAnnotationLayer::Stager(annotationNode.get()));
               }
               ossimPlanetNode* parentNode=0;
               if(!parentId.empty())
               {
                  ossimPlanetLayerNameIdSearchVisitor nv("", parentId);
                  accept(nv);
                  parentNode = dynamic_cast<ossimPlanetNode*>(nv.node().get());
               }
               
               if(parentNode)
               {
                  parentNode->addChild(annotationNode.get());
               }
               else
               {
                  addChild(annotationNode.get());
               }
					setRedrawFlag(true);					
            }
         }
      }
   }
   else if(command == "Set")
   {
      ossimString actionId = xmlAction->id();
      if(!actionId.empty())
      {
         ossimPlanetLayerNameIdSearchVisitor idSearch;
         idSearch.setId(actionId);
         accept(idSearch);
         ossimPlanetNode* node = dynamic_cast<ossimPlanetNode*>(idSearch.node().get());
         if(node)
         {
            node->execute(action);
         }
      }
      else
      {
         ossim_uint32 idx;
         const ossimXmlNode::ChildListType& children = xmlAction->xmlNode()->getChildNodes();
         for(idx = 0; idx < children.size(); ++idx)
         {
            ossimString id;
            if(children[idx]->getAttributeValue(id, "id"))
            {
               ossimPlanetLayerNameIdSearchVisitor idSearch;
               idSearch.setId(id);
               accept(idSearch);
               ossimPlanetNode* node = dynamic_cast<ossimPlanetNode*>(idSearch.node().get());
               if(node)
               {
                  osg::ref_ptr<ossimPlanetXmlAction> tempAction = xmlAction->duplicateChildAndMaintainAction(idx);
                  tempAction->setCommand("Set");
                  node->execute(*tempAction);
               }
            }
         }
      }
   }
	else if(command == "Get")
	{
	}
	else if(command == "Remove")
	{
		ossimString id; 
		ossimString name;
		// do short form
		// <Remove id="">
		if(!xmlAction->hasChildren())
		{
         ossimString id = xmlAction->id(); 
         ossimString name = xmlAction->name();
			if(!id.empty()||!name.empty())
			{
				removeByNameAndId(name, id);
			}
		}
		else
		{
			const ossimXmlNode::ChildListType& children = xmlAction->xmlNode()->getChildNodes();
			ossim_uint32 idx = 0;
			for(idx = 0; idx < children.size();++idx)
			{
				name = children[idx]->getAttributeValue("name");
				id   = children[idx]->getAttributeValue("id");
            if(name.empty()&&id.empty())
            {
               name = children[idx]->getChildTextValue("name");
               id   = children[idx]->getChildTextValue("id");
            }
				if(!name.empty()||!id.empty())
				{
					removeByNameAndId(name, id);
				}
			}
		}
	}
}
void ossimPlanetLayer::execute(const ossimPlanetAction& action)
{
   
#if 0
   if(action.command() == "setReceiver")
   {
      if(action.argCount() == 1)
      {
         setPathnameAndRegister(action.arg(1));
      }
   }
   else if(action.command() == "setEnableFlag")
   {
      if(action.argCount() == 1)
      {
         setEnableFlag(ossimString(action.arg(1)).toBool());
      }
   }
   else if(action.command() == "setId")
   {
      if(action.argCount()==1)
      {
         setId(action.arg(1));
      }
   }
   else if(action.command() == "setName")
   {
      if(action.argCount()==1)
      {
         setName(action.arg(1));
      }
   }
   else if(action.command() == "setDescription")
   {
      if(action.argCount()==1)
      {
         setDescription(action.arg(1));
      }
   }
   else if(action.command() == "init")
   {
      if(action.argCount() != 1) return;
      
      ossimString   objectName;
      ossimString   objectArg;
      ossim_uint32 idx = 1;
      ossimPlanetAction nestedAction(":dummy dummy " + action.arg(1) );
      for(idx = 1; idx <= nestedAction.argCount(); ++idx)
      {
         if(mkUtils::extractObjectAndArg(objectName,
                                         objectArg,
                                         nestedAction.arg(idx)))
         {
            if(objectName == "Name")
            {
               setName(objectArg);
            }
            else if(objectName == "Id")
            {
               setId(objectArg);
            }
            else if(objectName == "Description")
            {
               setDescription(objectArg);
            }
            else if(objectName == "ReceiverPath")
            {
               setPathnameAndRegister(objectArg);
            }
            else if(objectName == "Enable")
            {
               setEnableFlag(objectArg.toBool());
            }
         }
      }
   }
#endif
}
void ossimPlanetAnnotationPlacemark::execute(const ossimPlanetAction& action)
{
   std::string command = action.command();
   const ossimPlanetXmlAction* xmlAction = action.toXmlAction();
   ossimPlanetAnnotationLayerNode::execute(action);
   if(command == "Set")
   {
		bool coordinateUpdating = false;
      OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theUpdateMutex);
      if(xmlAction&&xmlAction->xmlNode().valid())
      {
         ossim_uint32 idx = 0;
         const ossimXmlNode::ChildListType& childNodes = xmlAction->xmlNode()->getChildNodes();
			const ossimXmlNode::ChildListType* properties = 0;
			// at this point we should just have a single object in the first child of the set
			//
			if(childNodes.size() > 0)
			{
            if((childNodes[0]->getTag() == "Placemark")||
               (childNodes[0]->getTag() == "Object"))
            {
               properties = &(childNodes[0]->getChildNodes());
            }
            else
            {
               properties = &childNodes;
            }
			}
			if(!properties) return;
         if(properties->size()==0)
         {
            properties = &childNodes; // we have direct properties first
         }
         for(idx = 0;idx<properties->size();++idx)
         {
            ossimString tag = (*properties)[idx]->getTag();
            if(tag == "Style")
            {
               const ossimXmlNode::ChildListType& childStyleNodes = (*properties)[idx]->getChildNodes();  
               ossim_uint32 styleIdx = 0;
               for(styleIdx = 0;styleIdx<childStyleNodes.size();++styleIdx)
               {
                  if(childStyleNodes[styleIdx]->getTag() == "LabelStyle")
                  {
                     ossimString color     = childStyleNodes[styleIdx]->getChildTextValue("color").trim();
                     ossimString colorMode = childStyleNodes[styleIdx]->getChildTextValue("colorMode").trim();
                     ossimString scale     = childStyleNodes[styleIdx]->getChildTextValue("scale").trim();
                     if(!color.empty())
                     {
                        std::vector<ossimString> colorValues;
                        color.split(colorValues, " ");
                        if(colorValues.size() == 4)
                        {
                           theLabelStyle->setColor(osg::Vec4d(colorValues[0].toDouble(),
                                                              colorValues[1].toDouble(),
                                                              colorValues[2].toDouble(),
                                                              colorValues[3].toDouble()));
                        }
                        else if(colorValues.size() == 3)
                        {
                           theLabelStyle->setColor(osg::Vec4d(colorValues[0].toDouble(),
                                                              colorValues[1].toDouble(),
                                                              colorValues[2].toDouble(),
                                                              1.0));
                        }
                        else if(colorValues.size() == 1)
                        {
                           theLabelStyle->setColor(osg::Vec4d(colorValues[0].toDouble(),
                                                              colorValues[0].toDouble(),
                                                              colorValues[0].toDouble(),
                                                              1.0));
                        }
                     }
                     if(!colorMode.empty())
                     {
                        if(colorMode == "random")
                        {
                           theLabelStyle->setColorMode(ossimPlanetAnnotationColorMode_RANDOM);
                        }
                        else if(colorMode == "normal")
                        {
                           theLabelStyle->setColorMode(ossimPlanetAnnotationColorMode_NORMAL);
                        }
                     }
                  }
               }
               setDirtyBit(COLOR_DIRTY);
               setRedrawFlag(true);
            }
            else if(tag == "color")
            {
               ossimString color = (*properties)[idx]->getText();
               std::vector<ossimString> colorValues;
               color.split(colorValues, " ");
               if(colorValues.size() == 4)
               {
                  theLabelStyle->setColor(osg::Vec4d(colorValues[0].toDouble(),
                                                     colorValues[1].toDouble(),
                                                     colorValues[2].toDouble(),
                                                     colorValues[3].toDouble()));
               }
               else if(colorValues.size() == 3)
               {
                  theLabelStyle->setColor(osg::Vec4d(colorValues[0].toDouble(),
                                                     colorValues[1].toDouble(),
                                                     colorValues[2].toDouble(),
                                                     1.0));
               }
               else if(colorValues.size() == 1)
               {
                  theLabelStyle->setColor(osg::Vec4d(colorValues[0].toDouble(),
                                                     colorValues[0].toDouble(),
                                                     colorValues[0].toDouble(),
                                                     1.0));
               }
               setDirtyBit(COLOR_DIRTY);
               setRedrawFlag(true);
            }
            else if(tag == "description")
            {
               setDescription((*properties)[idx]->getText());
            }
            else if(tag == "name")
            {
               setName((*properties)[idx]->getText());
               setDirtyBit(LABEL_DIRTY);
               setRedrawFlag(true);
            }
            else if(tag == "coordinates")
            {
               ossimPlanetAnnotationPoint* pointGeom = dynamic_cast<ossimPlanetAnnotationPoint*>(theGeometry.get());
               if(pointGeom)
               {
                  ossimString coordinates    = (*properties)[idx]->getText().trim();
                  if(!coordinates.empty())
                  {
                     double lon=0.0, lat=0.0, hgt=0.0;
                     ossimString coordinateStr;
                     std::stringstream in(coordinates);
                     in >> coordinateStr;
                     std::vector<ossimString> splitArray;
                     coordinateStr.split(splitArray, ",");
                     if(splitArray.size() >1)
                     {
                        lon = splitArray[0].toDouble();
                        lat = splitArray[1].toDouble();
                        if(splitArray.size() > 2)
                        {
                           hgt = splitArray[2].toDouble();
                        }
                     }
                     coordinateUpdating = true;
                     setDirtyBit(COORDINATE_DIRTY);
                     pointGeom->setCoordinate(osg::Vec3d(lat,lon,hgt));
                     setRedrawFlag(true);
                  }
               }
            }