Exemplo n.º 1
0
void ILI2Reader::SetFieldValues(OGRFeature *feature, DOMElement* elem) {
  int type = 0;
  //recursively search children
  for (DOMElement *childElem = (DOMElement *)elem->getFirstChild();
        type == 0 && childElem && childElem->getNodeType() == DOMNode::ELEMENT_NODE;
        childElem = (DOMElement*)childElem->getNextSibling()) {
    type = getGeometryTypeOfElem(childElem);
    if (type == 0) {
      if (childElem->getFirstChild() && childElem->getFirstChild()->getNodeType() == DOMNode::ELEMENT_NODE) {
        SetFieldValues(feature, childElem);
      } else {
        char *fName = fieldName(childElem);
        int fIndex = feature->GetFieldIndex(fName);
        if (fIndex != -1) {
          char * objVal = getObjValue(childElem);
          if (objVal == NULL)
            objVal = getREFValue(childElem); // only to try
          feature->SetField(fIndex, objVal);
          CPLFree(objVal);
        } else {
          CPLDebug( "OGR_ILI","Attribute '%s' not found", fName);
          m_missAttrs.push_back(fName);
        }
        CPLFree(fName);
      }
    } else {
      feature->SetGeometryDirectly(getGeometry(childElem, type));
    }
  }
}
Exemplo n.º 2
0
ret_ CXMLLoaderActions::LoadDualityCalculate(CProgram &Program,
											 const DOMElement *pElement,
											 const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	//
	auto_xerces_str wsOperator	("operator");
	auto_xerces_str	sOperator	(pElement->getAttribute(wsOperator));

	EDualityCalculate Calculate;

	if (SUCCESS != GetDualityOperator(sOperator, Calculate))
		return XML_LOADER_ERROR;

	//
	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	CAutoPtr<CVariable> OV[3];
	size_ n = 0;

	while (pSub)
	{
		ret_ Ret = LoadVariable(Program.Data(), pSub, OV[n].Ptr(), pPDU);

		if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
			return Ret;

		if (SUCCESS == Ret)
			if (3 <= ++n)
				break;

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	COptDualityCalculate *pODC = new COptDualityCalculate(
		OV[0].Ptr(),
		Calculate,
		OV[1].Ptr(),
		OV[2].Ptr());

	if (false_v == Program.AddOperator(pODC))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 3
0
ret_ CXMLLoaderActions::LoadAddItem(CProgram &Program,
									const DOMElement *pElement,
									const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	auto_xerces_str wsName("name");
	auto_xerces_str sName(pElement->getAttribute(wsName));
	
	// Check if there is the container
	if (!m_pTmpContainer)
		return XML_LOADER_ERROR;

	// Check if there is the table identified by the attribute
	CWindow *pWindow = m_pTmpContainer->GetChild(sName);

	if (!pWindow || WINDOW_TABLE != pWindow->Type())
		return XML_LOADER_ERROR;

	COptAddItem *pOpt = new COptAddItem(sName);

	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	while (pSub)
	{
		CVariable *pV = null_v;
		ret_ Ret = LoadVariable(Program.Data(),
								pSub,
								pV,
								pPDU);

		if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
			return Ret;

		if (SUCCESS == Ret)
			pOpt->AddVariable(pV);
		
		pSub = (DOMElement *)pSub->getNextSibling();
	}

	if (false_v == Program.AddOperator(pOpt))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 4
0
OGRPolygon *getPolygon(DOMElement *elem) {
  OGRPolygon *pg = new OGRPolygon();

  DOMElement *boundaryElem = (DOMElement *)elem->getFirstChild(); // outer boundary
  while (boundaryElem != NULL) {
    char* pszTagName = XMLString::transcode(boundaryElem->getTagName());
    if (cmpStr(ILI2_BOUNDARY, pszTagName) == 0)
      pg->addRingDirectly(getBoundary(boundaryElem));
    XMLString::release(&pszTagName);
    boundaryElem = (DOMElement *)boundaryElem->getNextSibling(); // inner boundaries
  }

  return pg;
}
Exemplo n.º 5
0
ret_ CXMLLoaderActions::LoadProgram(const CData *pParentData,
									CProgram &Program,
									const DOMElement *pElement,
									const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pParentData)
		return PARAMETER_NULL | PARAMETER_1;

	if (!pElement)
		return PARAMETER_NULL | PARAMETER_3;
#endif

	auto_xerces_str wsDataBlock("data_block");
	auto_xerces_str wsProcessBlock("process_block");

	DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

	if (!pChild)
		return XML_LOADER_ERROR;

	Program.Data().SetParent(pParentData);

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsDataBlock))
		{
			CData Data;

			if (SUCCESS != (LoadDataBlock(Data,  pChild)))
				return XML_LOADER_ERROR;

			Program.SetData(Data);
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsProcessBlock))
		{
			if (SUCCESS != LoadProcessBlock(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	return SUCCESS;
}
Exemplo n.º 6
0
ret_ CXMLLoaderActions::LoadReadFile(CProgram &Program,
									 const DOMElement *pElement,
									 const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	CAutoPtr<CVariable> OV[3];
	size_ n = 0;

	while (pSub)
	{
		ret_ Ret = LoadVariable(Program.Data(), pSub, OV[n].Ptr(), pPDU);

		if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
			return Ret;

		if (SUCCESS == Ret)
			if (3 <= ++n)
				break;

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	if (n != 3)
		return XML_LOADER_ERROR;

	COptReadFile *pOperator = new COptReadFile(OV[0].Ptr(),
											   OV[1].Ptr(),
											   OV[2].Ptr());

	if (false_v == Program.AddOperator(pOperator))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 7
0
OGRCircularString *ILI2Reader::getArc(DOMElement *elem) {
  // elem -> ARC
  OGRCircularString *arc = new OGRCircularString();
  // previous point -> start point
  OGRPoint *ptStart = getPoint((DOMElement *)elem->getPreviousSibling()); // COORD or ARC
  // end point
  OGRPoint *ptEnd = new OGRPoint();
  // point on the arc
  OGRPoint *ptOnArc = new OGRPoint();
  // double radius = 0; // radius

  DOMElement *arcElem = (DOMElement *)elem->getFirstChild();
  while (arcElem != NULL) {
    char* pszTagName = XMLString::transcode(arcElem->getTagName());
    char* pszObjValue = getObjValue(arcElem);
    if (cmpStr("C1", pszTagName) == 0)
      ptEnd->setX(CPLAtof(pszObjValue));
    else if (cmpStr("C2", pszTagName) == 0)
      ptEnd->setY(CPLAtof(pszObjValue));
    else if (cmpStr("C3", pszTagName) == 0)
      ptEnd->setZ(CPLAtof(pszObjValue));
    else if (cmpStr("A1", pszTagName) == 0)
      ptOnArc->setX(CPLAtof(pszObjValue));
    else if (cmpStr("A2", pszTagName) == 0)
      ptOnArc->setY(CPLAtof(pszObjValue));
    else if (cmpStr("A3", pszTagName) == 0)
      ptOnArc->setZ(CPLAtof(pszObjValue));
    else if (cmpStr("R", pszTagName) == 0) {
      // radius = CPLAtof(pszObjValue);
    }
    CPLFree(pszObjValue);
    XMLString::release(&pszTagName);
    arcElem = (DOMElement *)arcElem->getNextSibling();
  }
  arc->addPoint(ptStart);
  arc->addPoint(ptOnArc);
  arc->addPoint(ptEnd);
  delete ptStart;
  delete ptOnArc;
  delete ptEnd;
  return arc;
}
Exemplo n.º 8
0
OGRLineString *ILI2Reader::getArc(DOMElement *elem) {
  // elem -> ARC
  OGRLineString *ls = new OGRLineString();
  // previous point -> start point
  OGRPoint *ptStart = getPoint((DOMElement *)elem->getPreviousSibling()); // COORD or ARC
  // end point
  OGRPoint *ptEnd = new OGRPoint();
  // point on the arc
  OGRPoint *ptOnArc = new OGRPoint();
  double radius = 0; // radius

  DOMElement *arcElem = (DOMElement *)elem->getFirstChild();
  while (arcElem != NULL) {
    char* pszTagName = XMLString::transcode(arcElem->getTagName());
    char* pszObjValue = getObjValue(arcElem);
    if (cmpStr("C1", pszTagName) == 0)
      ptEnd->setX(atof(pszObjValue));
    else if (cmpStr("C2", pszTagName) == 0)
      ptEnd->setY(atof(pszObjValue));
    else if (cmpStr("C3", pszTagName) == 0)
      ptEnd->setZ(atof(pszObjValue));
    else if (cmpStr("A1", pszTagName) == 0)
      ptOnArc->setX(atof(pszObjValue));
    else if (cmpStr("A2", pszTagName) == 0)
      ptOnArc->setY(atof(pszObjValue));
    else if (cmpStr("A3", pszTagName) == 0)
      ptOnArc->setZ(atof(pszObjValue));
    else if (cmpStr("R", pszTagName) == 0)
      radius = atof(pszObjValue);
    CPLFree(pszObjValue);
    XMLString::release(&pszTagName);
    arcElem = (DOMElement *)arcElem->getNextSibling();
  }
  ptEnd->flattenTo2D();
  ptOnArc->flattenTo2D();
  interpolateArc(ls, ptStart, ptOnArc, ptEnd, arcIncr);
  delete ptStart;
  delete ptOnArc;
  delete ptEnd;
  return ls;
}
Exemplo n.º 9
0
OGRPoint *getPoint(DOMElement *elem) {
  // elem -> COORD (or ARC)
  OGRPoint *pt = new OGRPoint();

  DOMElement *coordElem = (DOMElement *)elem->getFirstChild();
  while (coordElem != NULL) {
    char* pszTagName = XMLString::transcode(coordElem->getTagName());
    char* pszObjValue = getObjValue(coordElem);
    if (cmpStr("C1", pszTagName) == 0)
      pt->setX(atof(pszObjValue));
    else if (cmpStr("C2", pszTagName) == 0)
      pt->setY(atof(pszObjValue));
    else if (cmpStr("C3", pszTagName) == 0)
      pt->setZ(atof(pszObjValue));
    CPLFree(pszObjValue);
    XMLString::release(&pszTagName);
    coordElem = (DOMElement *)coordElem->getNextSibling();
  }
  pt->flattenTo2D();
  return pt;
}
Exemplo n.º 10
0
void ILI2Reader::setFieldDefn(OGRFeatureDefn *featureDef, DOMElement* elem) {
  int type = 0;
  //recursively search children
  for (DOMElement *childElem = (DOMElement *)elem->getFirstChild();
        type == 0 && childElem && childElem->getNodeType() == DOMNode::ELEMENT_NODE;
        childElem = (DOMElement*)childElem->getNextSibling()) {
    type = getGeometryTypeOfElem(childElem);
    if (type == 0) {
      if (childElem->getFirstChild() && childElem->getFirstChild()->getNodeType() == DOMNode::ELEMENT_NODE) {
        setFieldDefn(featureDef, childElem);
      } else {
        char *fName = fieldName(childElem);
        if (featureDef->GetFieldIndex(fName) == -1) {
          CPLDebug( "OGR_ILI", "AddFieldDefn: %s",fName );
          OGRFieldDefn oFieldDefn(fName, OFTString);
          featureDef->AddFieldDefn(&oFieldDefn);
        }
        CPLFree(fName);
      }
    }
  }
}
Exemplo n.º 11
0
ret_ CXMLLoaderActions::LoadEmpty(CProgram &Program,
								  const DOMElement *pElement, 
								  const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	//
	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	CAutoPtr<CVariable> OV;

	while (pSub)
	{
		ret_ Ret = LoadVariable(Program.Data(), pSub, OV.Ptr(), pPDU);
		
		if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
			return Ret;

		if (SUCCESS == Ret)
			break;

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	COptEmpty *pOperator = new COptEmpty(OV.Ptr());

	if (false_v == Program.AddOperator(pOperator))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 12
0
OGRLineString *getLineString(DOMElement *elem, int bAsLinearRing) {
  // elem -> POLYLINE
  OGRLineString *ls;
  if (bAsLinearRing)
      ls = new OGRLinearRing();
  else
      ls = new OGRLineString();

  DOMElement *lineElem = (DOMElement *)elem->getFirstChild();
  while (lineElem != NULL) {
    char* pszTagName = XMLString::transcode(lineElem->getTagName());
    if (cmpStr(ILI2_COORD, pszTagName) == 0)
    {
      OGRPoint* poPoint = getPoint(lineElem);
      ls->addPoint(poPoint);
      delete poPoint;
    }
    else if (cmpStr(ILI2_ARC, pszTagName) == 0) {
      // end point
      OGRPoint *ptEnd = new OGRPoint();
      // point on the arc
      OGRPoint *ptOnArc = new OGRPoint();
      // radius
      double radius = 0;

      DOMElement *arcElem = (DOMElement *)lineElem->getFirstChild();
      while (arcElem != NULL) {
        char* pszTagName = XMLString::transcode(arcElem->getTagName());
        char* pszObjValue = getObjValue(arcElem);
        if (cmpStr("C1", pszTagName) == 0)
          ptEnd->setX(atof(pszObjValue));
        else if (cmpStr("C2", pszTagName) == 0)
          ptEnd->setY(atof(pszObjValue));
        else if (cmpStr("C3", pszTagName) == 0)
          ptEnd->setZ(atof(pszObjValue));
        else if (cmpStr("A1", pszTagName) == 0)
          ptOnArc->setX(atof(pszObjValue));
        else if (cmpStr("A2", pszTagName) == 0)
          ptOnArc->setY(atof(pszObjValue));
        else if (cmpStr("A3", pszTagName) == 0)
          ptOnArc->setZ(atof(pszObjValue));
        else if (cmpStr("R", pszTagName) == 0)
          radius = atof(pszObjValue);
        CPLFree(pszObjValue);
        XMLString::release(&pszTagName);

        arcElem = (DOMElement *)arcElem->getNextSibling();
      }

      ptEnd->flattenTo2D();
      ptOnArc->flattenTo2D();
      OGRPoint *ptStart = getPoint((DOMElement *)lineElem->getPreviousSibling()); // COORD or ARC
      interpolateArc(ls, ptStart, ptOnArc, ptEnd, PI/180);

      delete ptStart;
      delete ptEnd;
      delete ptOnArc;
    } /* else { // FIXME StructureValue in Polyline not yet supported
    } */
    XMLString::release(&pszTagName);

    lineElem = (DOMElement *)lineElem->getNextSibling();
  }

  return ls;
}
Exemplo n.º 13
0
ret_ CXMLLoaderActions::LoadIf(CProgram &Program,
							   const DOMElement *pElement,
							   const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_3);
#endif

	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	auto_xerces_str wsDataBlock			("data_block");
	auto_xerces_str wsExpressionUnitary	("expression_unitary");
	auto_xerces_str wsExpressionDuality	("expression_duality");
	auto_xerces_str wsConditionUnitary	("condition_unitary");
	auto_xerces_str wsConditionDuality	("condition_duality");
	auto_xerces_str wsProgram			("program");

	CProgramIf *pPI = new CProgramIf();

	pPI->Data().SetParent(&Program.Data());
	
	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  wsDataBlock))
		{
			CData Data;

			if (SUCCESS != (LoadDataBlock(Data, pSub)))
				return XML_LOADER_ERROR;

			pPI->SetData(Data);
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsExpressionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsExpressionDuality)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionDuality))
		{
			CExpression *pExpression = null_v;

			if (SUCCESS != LoadExpression(pPI->Data(),
										  pSub,
										  pExpression,
										  pPDU))
			{
				return XML_LOADER_ERROR;
			}

			if (false_v == pPI->AddExpression(pExpression))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsProgram))
		{
			CProgram *pProgram = new CProgram();

			if (SUCCESS != LoadProgram(&pPI->Data(),
									   *pProgram,
									   pSub,
									   pPDU))
			{
				return XML_LOADER_ERROR;
			}

			if (false_v == pPI->AddOperator(pProgram))
				return XML_LOADER_ERROR;
		}

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	if (false_v == Program.AddOperator(pPI))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 14
0
ret_ CXMLLoaderActions::LoadConfigGroup(CProgram &Program,
										const DOMElement *pElement,
										const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	//
	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	CAutoPtr<CVariable> OV[2];
	size_ n = 0;

	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  m_wsGroupVariable))
		{
			if (SUCCESS != LoadGroupVariable(Program.Data(),
											 pElement,
											 OV[0].Ptr()))
			{
				return XML_LOADER_ERROR;
			}

			n++;
			break;
		}

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	pSub = (DOMElement *)pSub->getNextSibling();

	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  m_wsSolidVariable))
		{
			if (SUCCESS != LoadSolidVariable(Program.Data(), 
											 pElement, 
											 OV[1].Ptr()))
			{
				return XML_LOADER_ERROR;
			}

			n++;
			break;
		}

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	if (2 != n)
		return XML_LOADER_ERROR;

	COptConfigGroup *pOperator = new COptConfigGroup(OV[0].Ptr(), OV[1].Ptr());

	if (false_v == Program.AddOperator(pOperator))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 15
0
static OGRCompoundCurve *getPolyline(DOMElement *elem) {
  // elem -> POLYLINE
  OGRCompoundCurve *ogrCurve = new OGRCompoundCurve();
  OGRLineString *ls = new OGRLineString();

  DOMElement *lineElem = (DOMElement *)elem->getFirstChild();
  while (lineElem != NULL) {
    char* pszTagName = XMLString::transcode(lineElem->getTagName());
    if (cmpStr(ILI2_COORD, pszTagName) == 0)
    {
      OGRPoint* poPoint = getPoint(lineElem);
      ls->addPoint(poPoint);
      delete poPoint;
    }
    else if (cmpStr(ILI2_ARC, pszTagName) == 0) {
      //Finish line and start arc
      if (ls->getNumPoints() > 1) {
        ogrCurve->addCurveDirectly(ls);
        ls = new OGRLineString();
      } else {
        ls->empty();
      }
      OGRCircularString *arc = new OGRCircularString();
      // end point
      OGRPoint *ptEnd = new OGRPoint();
      // point on the arc
      OGRPoint *ptOnArc = new OGRPoint();
      // radius
      // double radius = 0;

      DOMElement *arcElem = (DOMElement *)lineElem->getFirstChild();
      while (arcElem != NULL) {
        char* pszTagName2 = XMLString::transcode(arcElem->getTagName());
        char* pszObjValue = getObjValue(arcElem);
        if (cmpStr("C1", pszTagName2) == 0)
          ptEnd->setX(CPLAtof(pszObjValue));
        else if (cmpStr("C2", pszTagName2) == 0)
          ptEnd->setY(CPLAtof(pszObjValue));
        else if (cmpStr("C3", pszTagName2) == 0)
          ptEnd->setZ(CPLAtof(pszObjValue));
        else if (cmpStr("A1", pszTagName2) == 0)
          ptOnArc->setX(CPLAtof(pszObjValue));
        else if (cmpStr("A2", pszTagName2) == 0)
          ptOnArc->setY(CPLAtof(pszObjValue));
        else if (cmpStr("A3", pszTagName2) == 0)
          ptOnArc->setZ(CPLAtof(pszObjValue));
        else if (cmpStr("R", pszTagName2) == 0) {
          // radius = CPLAtof(pszObjValue);
        }
        CPLFree(pszObjValue);
        XMLString::release(&pszTagName2);

        arcElem = (DOMElement *)arcElem->getNextSibling();
      }

      OGRPoint *ptStart = getPoint((DOMElement *)lineElem->getPreviousSibling()); // COORD or ARC
      arc->addPoint(ptStart);
      arc->addPoint(ptOnArc);
      arc->addPoint(ptEnd);
      ogrCurve->addCurveDirectly(arc);

      delete ptStart;
      delete ptEnd;
      delete ptOnArc;
    } /* else { // TODO: StructureValue in Polyline not yet supported
    } */
    XMLString::release(&pszTagName);

    lineElem = (DOMElement *)lineElem->getNextSibling();
  }

  if (ls->getNumPoints() > 1) {
    ogrCurve->addCurveDirectly(ls);
  }
  else {
    delete ls;
  }
  return ogrCurve;
}
Exemplo n.º 16
0
ret_ CXMLLoaderActions::LoadWhile(CProgram &Program,
								  const DOMElement *pElement,
								  const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_3);
#endif

	auto_xerces_str	wsPosition	("position");
	auto_xerces_str	sPosition	(pElement->getAttribute(wsPosition));
	bool_			b = true_v;

	if (0 == strcmp(sPosition, "head"))
		b = true_v;
	else if (0 == strcmp(sPosition, "foot"))
		b = false_v;

	//
	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	auto_xerces_str wsDataBlock			("data_block");
	auto_xerces_str wsExpressionUnitary	("expression_unitary");
	auto_xerces_str wsExpressionDuality	("expression_duality");
	auto_xerces_str wsConditionUnitary	("condition_unitary");
	auto_xerces_str wsConditionDuality	("condition_duality");
	auto_xerces_str wsProcessBlock		("process_block");

	CData Data;
	CExpression *pExpression = null_v;
	CProgramWhile *pPW = null_v;

	Data.SetParent(&Program.Data());

	while (pSub)
	{
		if (0 == XMLString::compareString(pSub->getNodeName(),
										  wsDataBlock))
		{
			if (SUCCESS != (LoadDataBlock(Data, pSub)))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsExpressionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsExpressionDuality)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionUnitary)
				 || 0 == XMLString::compareString(pSub->getNodeName(),
												  wsConditionDuality))
		{
			if (SUCCESS != LoadExpression(Data, pSub, pExpression, pPDU))
				return XML_LOADER_ERROR;
			
			pPW = new CProgramWhile(b, pExpression, &Data);
			pPW->Data().SetParent(&Program.Data());
		}
		else if (0 == XMLString::compareString(pSub->getNodeName(),
											   wsProcessBlock))
		{
			if (!pPW)
				return XML_LOADER_ERROR;
			
			if (SUCCESS != LoadProcessBlock(*pPW, pSub, pPDU))
				return XML_LOADER_ERROR;
		}

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	if (false_v == Program.AddOperator(pPW))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 17
0
ret_ CXMLLoaderActions::LoadProcessor(const DOMElement *pElement)
{
#ifdef _DEBUG_
	if (!pElement)
		return PARAMETER_NULL | PARAMETER_2;
#endif

	//
	auto_xerces_str	wsName("name");
	auto_xerces_str wsPDU("pdu");
	auto_xerces_str sName(pElement->getAttribute(wsName));

	auto_xerces_str wsDataBlock("data_block");
	auto_xerces_str wsStart("start");
	auto_xerces_str wsOnClick("on_click");
	auto_xerces_str wsOnMessage("on_message");
	auto_xerces_str wsEnd("end");

	m_pTmpContainer = CUIManager::Instance()->GetContainer(sName);
	
	// Check if there is corresponding container, it should be exist
	if (!m_pTmpContainer)
		return XML_LOADER_ERROR;

	CProtocolInfo *pProtocol = CProtocolManager::Instance()->GetProtocol();

	// Protocol should be loaded
	if (!pProtocol)
		return XML_LOADER_ERROR;

	//
	DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

	if (!pChild)
		return XML_LOADER_ERROR;

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsDataBlock))
		{
			if (SUCCESS != LoadDataBlock(m_pTmpContainer->Data(), pChild))
				return XML_LOADER_ERROR;

			m_pTmpContainer->Data().SetParent(&CUIManager::Instance()->Data());
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsStart))
		{
			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   m_pTmpContainer->StartProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsOnClick))
		{
			auto_xerces_str sName(pChild->getAttribute(wsName));

			CProgram *pProgram = null_v;

			if (!m_pTmpContainer->AddOnClickProcessor(sName, pProgram))
				return XML_LOADER_ERROR;

			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   *pProgram,
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsOnMessage))
		{
			auto_xerces_str sPDU(pChild->getAttribute(wsPDU));

			CPDUInfo *pPDUInfo = null_v;

			if (SUCCESS != pProtocol->GetPDU(sPDU, pPDUInfo))
				return XML_LOADER_ERROR;

			CProgram *pProgram = null_v;

			if (!m_pTmpContainer->AddMessageProcessor(sPDU, pProgram))
				return XML_LOADER_ERROR;

			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   *pProgram,
									   pChild,
									   pPDUInfo))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsEnd))
		{
			if (SUCCESS != LoadProgram(&m_pTmpContainer->Data(),
									   m_pTmpContainer->EndProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	return SUCCESS;
}
Exemplo n.º 18
0
ret_ CXMLLoaderActions::LoadExpression(const CData &Data,
									   const DOMElement *pElement,
									   CExpression *&pExpression,
									   const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);

	if (pExpression)
		return (PARAMETER_NOT_NULL | PARAMETER_3);
#endif

	auto_xerces_str wsExpressionUnitary	("expression_unitary");
	auto_xerces_str wsExpressionDuality	("expression_duality");
	auto_xerces_str wsConditionUnitary	("condition_unitary");
	auto_xerces_str wsConditionDuality	("condition_duality");
	auto_xerces_str wsCalculate			("calculate");
	auto_xerces_str wsRelation			("relation");

	if (0 == XMLString::compareString(pElement->getNodeName(),
									  wsExpressionUnitary))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CExpression *pExp = null_v;

		while (pChild)
		{
			if (0 == XMLString::compareString(pChild->getNodeName(),
											  wsExpressionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsExpressionDuality)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionDuality))
			{
				if (SUCCESS != LoadExpression(Data, pChild, pExp, pPDU))
					return XML_LOADER_ERROR;

				break;
			}

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		if (!pExp)
			return XML_LOADER_ERROR;

		pExpression = (CExpression *)new CExpNot(pExp);
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsExpressionDuality))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		size_ n = 0;
		CExpression *pExp[2] = {null_v, null_v};

		while (pChild)
		{
			if (2 <= n)
				break;

			if (0 == XMLString::compareString(pChild->getNodeName(),
											  wsExpressionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsExpressionDuality)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionDuality))
			{
				if (SUCCESS != LoadExpression(Data, pChild, pExp[n++], pPDU))
					return XML_LOADER_ERROR;
			}

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		if (2 != n)
			return XML_LOADER_ERROR;

		auto_xerces_str sRelation(pElement->getAttribute(wsRelation));

		if (0 == strcmp((const ch_1 *)sRelation, "and"))
			pExpression = (CExpression *)new CExpAnd(pExp[0], pExp[1]);
		else if (0 == strcmp((const ch_1 *)sRelation, "or"))
			pExpression = (CExpression *)new CExpOr(pExp[0], pExp[1]);
		else
			return XML_LOADER_ERROR;
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsConditionUnitary))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CAutoPtr<CVariable> v;

		while (pChild)
		{
			ret_ Ret = LoadVariable(Data, pChild, v.Ptr(), pPDU);
		
			if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
				return Ret;

			if (SUCCESS == Ret)
				break;

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		pExpression = new CExpVarUnitary(v.Ptr());
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsConditionDuality))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CAutoPtr<CVariable> v[2];
		size_ n = 0;

		while (pChild)
		{
			ret_ Ret = LoadVariable(Data, pChild, v[n].Ptr(), pPDU);
		
			if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
				return Ret;

			if (SUCCESS == Ret)
				if (2 <= ++n)
					break;

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		auto_xerces_str sOperator(pElement->getAttribute(wsCalculate));
		ECompareCalculate Calculate;

		if (SUCCESS != GetCompareOperator((const ch_1 *)sOperator, Calculate))
			return XML_LOADER_ERROR;

		pExpression = new CExpVarDuality(v[0].Ptr(), Calculate, v[1].Ptr());
	}

	return SUCCESS;
}
Exemplo n.º 19
0
ret_ CXMLLoaderActions::LoadSend(CProgram &Program,
								 const DOMElement *pElement,
								 const CPDUInfo *pPDU)

{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	//
	CProtocolInfo *pProtocol = CProtocolManager::Instance()->GetProtocol();

	//
	auto_xerces_str	wsPDU	("pdu");
	auto_xerces_str	sPDU	(pElement->getAttribute(wsPDU));

	CPDUInfo *pPDUInfo = null_v;

	if (SUCCESS != (pProtocol->GetPDU(sPDU, pPDUInfo)))
		return XML_LOADER_ERROR;

	COptSend *pOperator = new COptSend(pPDUInfo);
	
	// For send operation, sub elements are not necessary.
	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (pSub)
	{
		auto_xerces_str wsFieldVariable("field_variable");
		auto_xerces_str	wsFieldName("field_name");

		while (pSub)
		{
			if (0 == XMLString::compareString(pSub->getNodeName(), wsFieldVariable))
			{
				//
				DOMElement	*pVariable = (DOMElement *)pSub->getFirstChild();
				CAutoPtr<CVariable> OV_;

				if (!pVariable)
					return XML_LOADER_ERROR;

				while (pVariable)
				{
					ret_ Ret = LoadVariable(Program.Data(), 
											pVariable, 
											OV_.Ptr(),
											pPDU);

					if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
						return Ret;

					if (SUCCESS == Ret)
						break;

					pVariable = (DOMElement *)pVariable->getNextSibling();
				}

				//
				auto_xerces_str	sFieldName(pSub->getAttribute(wsFieldName));
				CField *pField = null_v;
			
				if (SUCCESS != pPDUInfo->GetField(sFieldName, pField))
					return XML_LOADER_ERROR;
			
				//
				if (false_v == pOperator->AddEvaluate(sFieldName, OV_.Ptr()))
					return XML_LOADER_ERROR;
			}

			pSub = (DOMElement *)pSub->getNextSibling();
		}
	}

	if (false_v == Program.AddOperator(pOperator))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Exemplo n.º 20
0
ret_ CXMLLoaderActions::LoadDataBlock(CData &Data,
									  const DOMElement *pElement)
{
#ifdef _DEBUG_
	if (!pElement)
		return PARAMETER_NULL | PARAMETER_2;
#endif

	DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

	if (!pChild)
		return XML_LOADER_ERROR;

	auto_xerces_str	wsObject	("v_object");
	auto_xerces_str wsB1		("v_b_1");
	auto_xerces_str wsUB1		("v_ub_1");
	auto_xerces_str wsB2		("v_b_2");
	auto_xerces_str wsUB2		("v_ub_2");
	auto_xerces_str wsB4		("v_b_4");
	auto_xerces_str wsUB4		("v_ub_4");
	auto_xerces_str wsB8		("v_b_8");
	auto_xerces_str wsUB8		("v_ub_8");
	auto_xerces_str wsFB4		("v_fb_4");
	auto_xerces_str wsFB8		("v_fb_8");
	auto_xerces_str	wsString	("v_string");
	auto_xerces_str wsGroup		("v_group");

	auto_xerces_str	wsName		("name");
	auto_xerces_str	wsValue		("value");

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(), wsObject))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (false_v == Data.Define(sName, (obj_)null_v))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB1))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_1))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_1, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}

		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB1))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_1))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_1, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB2))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_2))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_2, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB2))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_2))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_2, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB4))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_4))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_4, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB4))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_4))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_4, (b_4)atoi(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsB8))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, B_8))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, B_8, (b_8)atoll(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsUB8))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, UB_8))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, UB_8, (ub_8)atoll(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsFB4))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, FB_4))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, (fb_4)atof(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsFB8))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, FB_8))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, (fb_8)atof(sValue)))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsString))
		{
			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sValue	(pChild->getAttribute(wsValue));

			if (0 == strcmp(sValue, SIGN_UNBOUNDED))
			{
				if (false_v == Data.Define(sName, (ch_1 *)""))
					return XML_LOADER_ERROR;
			}
			else
			{
				if (false_v == Data.Define(sName, sValue))
					return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(), wsGroup))
		{
			auto_xerces_str wsNormal("normal");
			auto_xerces_str wsFloat	("float");
			auto_xerces_str wsString("string");

			auto_xerces_str	wsName	("name");
			auto_xerces_str	wsLength("length");
			auto_xerces_str	wsSigned("signed");
			auto_xerces_str	wsSize	("size");

			auto_xerces_str sName	(pChild->getAttribute(wsName));
			auto_xerces_str sSize	(pChild->getAttribute(wsSize));

			CFieldGroupDefined *pGroupField = new CFieldGroupDefined(
				sName, 
				sSize);

			DOMElement *pSub = (DOMElement *)pChild->getFirstChild();

			if (!pSub)
				return XML_LOADER_ERROR;

			while (pSub)
			{
				if (0 == XMLString::compareString(pSub->getNodeName(),
												  wsNormal))
				{
					auto_xerces_str sName (pElement->getAttribute(wsName));
					auto_xerces_str	sLength(pElement->getAttribute(wsLength));
					auto_xerces_str	sSigned(pElement->getAttribute(wsSigned));

					EFieldType Type;

					GetFieldType(
						FIELD_NORMAL_STYLE, 
						atoi(sLength), 
						0 == strcmp(sSigned, "true") ? true_v : false_v,
						Type);
					
					CFieldNumber *pField = new CFieldNumber(sName, 
															Type, 
															pGroupField);

					pGroupField->SetSubField(pField);
				}
				else if (0 == XMLString::compareString(pSub->getNodeName(),
													   wsFloat))
				{
					auto_xerces_str sName (pElement->getAttribute(wsName));
					auto_xerces_str	sLength(pElement->getAttribute(wsLength));

					EFieldType Type;

					GetFieldType(FIELD_FLOAT_STYLE, 
								 atoi(sLength), 
								 false_v, 
								 Type);
					
					CFieldNumber *pField = new CFieldNumber(sName, 
															Type, 
															pGroupField);

					pGroupField->SetSubField(pField);
				}
				else if (0 == XMLString::compareString(pSub->getNodeName(),
													   wsString))
				{
					auto_xerces_str sName (pElement->getAttribute(wsName));
					auto_xerces_str	sLength(pElement->getAttribute(wsLength));
					auto_xerces_str	sSize(pElement->getAttribute(wsSize));
					
					CFieldString *pField = new CFieldString(sName, 
															atoi(sSize), 
															pGroupField);

					pGroupField->SetSubField(pField);
				}

				pSub = (DOMElement *)pSub->getNextSibling();
			}
			
			if (false_v == Data.Define(pGroupField))
				return XML_LOADER_ERROR;
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	return SUCCESS;
}
Exemplo n.º 21
0
OGRGeometry *ILI2Reader::getGeometry(DOMElement *elem, int type) {
  OGRGeometryCollection *gm = new OGRGeometryCollection();

  DOMElement *childElem = elem;
  while (childElem != NULL) {
    char* pszTagName = XMLString::transcode(childElem->getTagName());
    switch (type) {
      case ILI2_COORD_TYPE :
        if (cmpStr(ILI2_COORD, pszTagName) == 0)
        {
          delete gm;
          XMLString::release(&pszTagName);
          return getPoint(childElem);
        }
        break;
      case ILI2_ARC_TYPE :
        // is it possible here? It have to be a ARC or COORD before (getPreviousSibling)
        if (cmpStr(ILI2_ARC, pszTagName) == 0)
        {
          delete gm;
          XMLString::release(&pszTagName);
          return getArc(childElem);
        }
        break;
      case ILI2_POLYLINE_TYPE :
        if (cmpStr(ILI2_POLYLINE, pszTagName) == 0)
        {
          delete gm;
          XMLString::release(&pszTagName);
          return getLineString(childElem, FALSE);
        }
        break;
      case ILI2_BOUNDARY_TYPE :
        if (cmpStr(ILI2_BOUNDARY, pszTagName) == 0)
        {
          delete gm;
          XMLString::release(&pszTagName);
          return getLineString(childElem, FALSE);
        }
        break;
      case ILI2_AREA_TYPE :
        if ((cmpStr(ILI2_AREA, pszTagName) == 0) ||
          (cmpStr(ILI2_SURFACE, pszTagName) == 0))
        {
          delete gm;
          XMLString::release(&pszTagName);
          return getPolygon(childElem);
        }
        break;
      default :
        if (type >= ILI2_GEOMCOLL_TYPE) {
          int subType = getGeometryTypeOfElem(childElem); //????
          gm->addGeometryDirectly(getGeometry(childElem, subType));
        }
        break;
    }
    XMLString::release(&pszTagName);

    // GEOMCOLL
    childElem = (DOMElement *)childElem->getNextSibling();
  }

  return gm;
}
Exemplo n.º 22
0
ret_ CXMLLoaderActions::LoadProcessBlock(CProgram &Program,
										 const DOMElement *pElement,
										 const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

	if (!pChild)
		return XML_LOADER_ERROR;

	auto_xerces_str wsEmpty				("empty");
	auto_xerces_str	wsUnitaryCalculate	("unitary_calculate");
	auto_xerces_str	wsDualityCalculate	("duality_calculate");
	auto_xerces_str wsConfigGroup		("config_group");
	auto_xerces_str	wsIf				("if");
	auto_xerces_str	wsWhile				("while");
	auto_xerces_str wsContinue			("continue");
	auto_xerces_str wsBlock				("block");
	auto_xerces_str wsBreak				("break");
	auto_xerces_str	wsSend				("send");
	auto_xerces_str wsReadFile			("read_file");
	auto_xerces_str wsSaveFile			("save_file");
	auto_xerces_str wsDeleteFile		("delete_file");
	auto_xerces_str wsSplit				("split");
	auto_xerces_str	wsDie				("die");
	auto_xerces_str wsShowWindow		("show_window");
	auto_xerces_str wsWaitMessage		("wait_message");
	auto_xerces_str wsAlert				("alert");
	auto_xerces_str wsEnable			("enable");
	auto_xerces_str wsAddItem			("add_item");
	auto_xerces_str wsProgram			("program");

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsEmpty))
		{
			if (SUCCESS != LoadEmpty(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsUnitaryCalculate))
		{
			if (SUCCESS != LoadUnitaryCalculate(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDualityCalculate))
		{
			if (SUCCESS != LoadDualityCalculate(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsConfigGroup))
		{
			if (SUCCESS != LoadConfigGroup(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsIf))
		{
			if (SUCCESS != LoadIf(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsWhile))
		{
			if (SUCCESS != LoadWhile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsContinue))
		{
			if (SUCCESS != LoadContinue(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsBlock))
		{
			if (SUCCESS != LoadBlock(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsBreak))
		{
			if (SUCCESS != LoadBreak(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSend))
		{
			if (SUCCESS != LoadSend(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsReadFile))
		{
			if (SUCCESS != LoadReadFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSaveFile))
		{
			if (SUCCESS != LoadSaveFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDeleteFile))
		{
			if (SUCCESS != LoadDeleteFile(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSplit))
		{
			if (SUCCESS != LoadSplit(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsDie))
		{
			if (SUCCESS != LoadDie(Program))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsShowWindow))
		{
			if (SUCCESS != LoadShowWindow(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsWaitMessage))
		{
			if (SUCCESS != LoadWaitMessage(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsAlert))
		{
			if (SUCCESS != LoadAlert(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsEnable))
		{
			if (SUCCESS != LoadEnable(Program, pChild))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsAddItem))
		{
			if (SUCCESS != LoadAddItem(Program, pChild, pPDU))
				return XML_LOADER_ERROR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsProgram))
		{
			CProgram *pSubProgram = new CProgram();

			if (SUCCESS != LoadProgram(&Program.Data(),
										*pSubProgram,
										pChild,
										pPDU))
            {
				return XML_LOADER_ERROR;
            }

			if (false_v == Program.AddOperator(pSubProgram))
				return XML_LOADER_ERROR;
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	return SUCCESS;
}
Exemplo n.º 23
0
ret_ CXMLLoaderActions::Load(XercesDOMParser *pParser,
							 const ch_1 *pszEnvironmentPath)
{
#ifdef _DEBUG_
	if (!pParser)
		return PARAMETER_NULL | PARAMETER_1;

	if (!pszEnvironmentPath)
		return PARAMETER_NULL | PARAMETER_2;

	if (null_v == pszEnvironmentPath[0])
		return PARAMETER_EMPTY | PARAMETER_2;
#endif

	SetParser(pParser);

	ch_1 sActions[ENVIRONMENT_PATH_LENGTH];

	memset(sActions, 0, ENVIRONMENT_PATH_LENGTH);
	sprintf(sActions, "%s%s", pszEnvironmentPath, ACTIONS_XML_FILE);

	DOMDocument *pActionsDoc = null_v;

	try
	{
		GetParser()->parse(sActions);
        pActionsDoc = GetParser()->getDocument();
	}
    catch (const OutOfMemoryException &err)
    {
		auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		return XML_LOADER_ERROR;
    }
	catch (const XMLException &err)
    {
		auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		return XML_LOADER_ERROR;
	}
    catch (const DOMException &err)
    {
		auto_xerces_str sErr(err.msg);

		printf("%s\n", (const ch_1 *)sErr);

 		return XML_LOADER_ERROR;
	}
	catch (...)
    {
		printf("Unexpected error during parsing.\n");

		return XML_LOADER_ERROR;
    }

	if (!pActionsDoc)
		return XML_LOADER_ERROR;
	
	DOMElement *pRoot = pActionsDoc->getDocumentElement();

	if (!pRoot)
		return XML_LOADER_ERROR;

	DOMElement *pChild = (DOMElement *)pRoot->getFirstChild();

	if (!pChild)
		return XML_LOADER_ERROR;

	auto_xerces_str wsDataBlock("data_block");
	auto_xerces_str wsStart("start");
	auto_xerces_str wsProcessor("processor");
	auto_xerces_str wsEnd("end");

	while (pChild)
	{
		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsDataBlock))
		{
			if (SUCCESS != LoadDataBlock(CUIManager::Instance()->Data(),
										 pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsStart))
		{
			if (SUCCESS != LoadProgram(&CUIManager::Instance()->Data(),
									   CUIManager::Instance()->StartProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsProcessor))
		{
			if (SUCCESS != LoadProcessor(pChild))
				return XML_LOADER_ERROR;

			m_pTmpContainer = null_v;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsEnd))
		{
			if (SUCCESS != LoadProgram(&CUIManager::Instance()->Data(),
									   CUIManager::Instance()->EndProgram(),
									   pChild))
			{
				return XML_LOADER_ERROR;
			}
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	return SUCCESS;
}
Exemplo n.º 24
0
ret_ CXMLLoaderNetwork::Load(XercesDOMParser *pParser,
							 const ch_1 *pszEnvironmentPath)
{
	_START(LOAD);

#ifdef _DEBUG_
	if (!pParser)
		_RET(PARAMETER_NULL | PARAMETER_1);

	if (!pszEnvironmentPath)
		_RET(PARAMETER_NULL | PARAMETER_2);

	if (null_v == pszEnvironmentPath[0])
		_RET(PARAMETER_EMPTY | PARAMETER_2);
#endif

	SetParser(pParser);

	ch_1 sNetwork[ENVIRONMENT_PATH_LENGTH];

	memset(sNetwork, 0, ENVIRONMENT_PATH_LENGTH);
	strncpy(sNetwork, pszEnvironmentPath, ENVIRONMENT_PATH_LENGTH);
	strncat(sNetwork, NETWORK_XML_FILE, ENVIRONMENT_PATH_LENGTH);

	DOMDocument *pNetworkDoc = null_v;

	try
	{
		GetParser()->parse(sNetwork);
        pNetworkDoc = GetParser()->getDocument();
	}
    catch (const OutOfMemoryException &err)
    {
		auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		_RET(XML_LOADER_ERROR);
    }
	catch (const XMLException &err)
    {
		auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		_RET(XML_LOADER_ERROR);
	}
    catch (const DOMException &err)
    {
        auto_xerces_str sErr(err.getMessage());

		printf("%s\n", (const ch_1 *)sErr);

 		_RET(XML_LOADER_ERROR);
	}
	catch (...)
    {
		printf("Unexpected error during parsing.\n");

		_RET(XML_LOADER_ERROR);
    }

	DOMElement *pRoot = pNetworkDoc->getDocumentElement();

	if (!pRoot)
		_RET(XML_LOADER_ERROR);

	DOMElement *pChild = (DOMElement *)pRoot->getFirstChild();

	if (!pChild)
		_RET(XML_LOADER_ERROR);

	auto_xerces_str wsIdentity		("identity");
	auto_xerces_str wsPDU			("pdu");
	auto_xerces_str wsDirection		("direction");
	auto_xerces_str	wsName			("name");
	auto_xerces_str	wsProtocolName	("protocol");
	auto_xerces_str wsCommandID		("command_id");
	auto_xerces_str wsSizeID		("size_id");
	auto_xerces_str	wsLocalPort		("local_port");
	auto_xerces_str wsAuto			("auto");

	auto_xerces_str wsFilter		("filter");
	auto_xerces_str wsMaxConnections("max_connections");
	auto_xerces_str wsRemoteIP		("remote_ip");
	auto_xerces_str	wsRemotePort	("remote_port");
	auto_xerces_str wsReconnect		("reconnect");

	auto_xerces_str wsAcceptorName	("acceptor");
	auto_xerces_str	wsConnectorName	("connector");
 	auto_xerces_str wsReceiverName	("receiver");
	auto_xerces_str wsSenderName	("sender");

	auto_xerces_str wsType			("type");


	while (pChild)
    {
		ENetworkType NetworkType = NETWORK_NONE;
		CProtocolInfo *pProtocol = null_v;
		CField *pCommandIDField	= null_v;
		CField *pSizeIDField = null_v;
		bool_ bIsAutoStart = true_v;

		if (0 == XMLString::compareString(pChild->getNodeName(),
										  wsAcceptorName))
		{
			NetworkType = NETWORK_ACCEPTOR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsConnectorName))
		{
			NetworkType = NETWORK_CONNECTOR;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsReceiverName))
		{
			NetworkType = NETWORK_RECEIVER;
		}
		else if (0 == XMLString::compareString(pChild->getNodeName(),
											   wsSenderName))
		{
			NetworkType = NETWORK_SENDER;
		}
		else
		{
			pChild = (DOMElement *)pChild->getNextSibling();

			continue;
		}

		auto_xerces_str sProtocolName(pChild->getAttribute(wsProtocolName));

		if (SUCCESS != _ERR(
				CXMLLoaderProtocol::Instance()->Load(pParser,
													 pszEnvironmentPath,
													 sProtocolName)))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		if (SUCCESS != _ERR(
                CProtocolManager::instance()->getProtocol(sProtocolName,
                        pProtocol)))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		auto_xerces_str sCommandID(pChild->getAttribute(wsCommandID));

        if (SUCCESS != _ERR(pProtocol->getHeadField(sCommandID,
                pCommandIDField))
			|| FIELD_NORMAL_STYLE !=
                (pCommandIDField->type() & FIELD_NORMAL_STYLE)
                || 4 < _LEN(pCommandIDField->type()))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		auto_xerces_str sSizeID(pChild->getAttribute(wsSizeID));

        if (SUCCESS != _ERR(pProtocol->getHeadField(sSizeID,
                pSizeIDField))
			|| FIELD_NORMAL_STYLE !=
                (pSizeIDField->type() & FIELD_NORMAL_STYLE)
                || 4 < _LEN(pSizeIDField->type()))
		{
			_RET(XML_LOADER_ERROR);
		}

		//
		auto_xerces_str wsAutoFalse("false");

		if (0 == XMLString::compareString(wsAutoFalse,
										  pChild->getAttribute(wsAuto)))
		{
			bIsAutoStart = false_v;
		}

        CNode *pNetwork = null_v;
		auto_xerces_str sName(pChild->getAttribute(wsName));

		switch (NetworkType)
		{
		case NETWORK_NONE:
			_RET(XML_LOADER_ERROR);
		case NETWORK_ACCEPTOR:
			{
				auto_xerces_str	sLocalPort(pChild->getAttribute(wsLocalPort));
				auto_xerces_str
					sMaxConnections(pChild->getAttribute(wsMaxConnections));

				pNetwork = new CAcceptor(pProtocol,
										 pCommandIDField,
										 pSizeIDField,
										 (ub_2)atoi(sLocalPort),
										 (size_)atoi(sMaxConnections),
										 bIsAutoStart);
			}

			break;
		case NETWORK_CONNECTOR:
			{
				//
				auto_xerces_str	nLocalPort	(pChild->getAttribute(wsLocalPort));
				auto_xerces_str	sRemoteIP	(pChild->getAttribute(wsRemoteIP));
				auto_xerces_str	nRemotePort
					(pChild->getAttribute(wsRemotePort));
				auto_xerces_str	sReconnect	(pChild->getAttribute(wsReconnect));

				pNetwork = new CConnector(pProtocol,
										  pCommandIDField,
										  pSizeIDField,
										  (ub_2)atoi(nLocalPort),
										  (const ch_1 *)sRemoteIP,
										  (ub_2)atoi(nRemotePort),
										  (b_4)atoi(sReconnect),
										  bIsAutoStart);
			}

			break;
		case NETWORK_RECEIVER:
			{
				//
				auto_xerces_str sLocalPort(pChild->getAttribute(wsLocalPort));


				pNetwork = new CReceiver(pProtocol,
										 pCommandIDField,
										 pSizeIDField,
										 (ub_2)atoi(sLocalPort),
										 bIsAutoStart);
			}

			break;
		case NETWORK_SENDER:
			{
				//
				auto_xerces_str sLocalPort(pChild->getAttribute(wsLocalPort));

				pNetwork = new CSender(pProtocol,
									   pCommandIDField,
									   pSizeIDField,
									   (ub_2)atoi(sLocalPort),
									   bIsAutoStart);
			}
		}

        CNodeConf *pNetworkConf = (CNodeConf *) pNetwork->getConf();

		//
		DOMElement *pSub = (DOMElement *)pChild->getFirstChild();

		if (!pSub)
			_RET(XML_LOADER_ERROR);

		while (pSub)
		{
			if (0 == XMLString::compareString(pSub->getNodeName(),
											  wsIdentity))
			{
				//
				auto_xerces_str sIdentity(pSub->getAttribute(wsIdentity));
				ch_1 			*sIdentityName = null_v;

				if (SUCCESS != _ERR(GetLastName(sIdentity, sIdentityName)))
					_RET(XML_LOADER_ERROR);

                v_ *pV = pProtocol->data().value(sIdentityName);

				if (!pV)
					_RET(XML_LOADER_ERROR);

				//
				auto_xerces_str	sPDU(pSub->getAttribute(wsPDU));
                CPduInfo *pPDU = null_v;

                if (SUCCESS != _ERR(pProtocol->getPdu(sPDU, pPDU)))
					_RET(XML_LOADER_ERROR);

				//
				auto_xerces_str sDirection(pSub->getAttribute(wsDirection));
				EDirection		Direction;

				if (SUCCESS != _ERR(GetDirection(sDirection, Direction)))
					_RET(XML_LOADER_ERROR);

				//
				if (SUCCESS != _ERR(pNetworkConf->ConfigPDU(*pV,
															pPDU,
															Direction)))
				{
					_RET(XML_LOADER_ERROR);
				}
			}
			else if (0 == XMLString::compareString(pSub->getNodeName(),
												   wsFilter))
			{
				CIPFilter *pIPFilter = null_v;

				if (NETWORK_ACCEPTOR == NetworkType)
				{
					pIPFilter =
						&((CAcceptorConf *)pNetworkConf)->IPFilter();
				}
				else if (NETWORK_RECEIVER == NetworkType)
				{
					pIPFilter =
						&((CReceiverConf *)pNetworkConf)->IPFilter();
				}
				else
				{
					_RET(XML_LOADER_ERROR);
				}

				auto_xerces_str sType(pSub->getAttribute(wsType));

				if (0 == strcmp(sType, "forbid")) {
                    pIPFilter->setForbid(true_v);
                } else if (0 == strcmp(sType, "permit")) {
                    pIPFilter->setForbid(false_v);
                }

                auto_xerces_str sIPGroup(pSub->getTextContent());

                if (false_v == pIPFilter->addIpGroup((const ch_1 *) sIPGroup))
					_RET(XML_LOADER_ERROR);
			}

			pSub = (DOMElement *)pSub->getNextSibling();
		}

        if (SUCCESS != _ERR(CNetworkManager::instance()->AddNetwork(
														(const char *)sName,
														NetworkType,
														pNetwork)))
		{
			_RET(XML_LOADER_ERROR);
		}

		pChild = (DOMElement *)pChild->getNextSibling();
	}

	_RET(SUCCESS);
}