You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2004/03/31 14:20:04 UTC
cvs commit: ws-axis/c/src/soap XercesHandler.h XercesHandler.cpp SoapParserXerces.h SoapParserXerces.cpp SoapInputSource.h SoapInputSource.cpp SoapBinInputStream.h SoapBinInputStream.cpp
sanjaya 2004/03/31 04:20:04
Added: c/src/soap XercesHandler.h XercesHandler.cpp
SoapParserXerces.h SoapParserXerces.cpp
SoapInputSource.h SoapInputSource.cpp
SoapBinInputStream.h SoapBinInputStream.cpp
Log:
adding files for xerces parser support
Revision Changes Path
1.1 ws-axis/c/src/soap/XercesHandler.h
Index: XercesHandler.h
===================================================================
/* -*- C++ -*- */
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author sanjaya singharage (sanjayas@opensource.lk)
*/
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/sax2/DefaultHandler.hpp>
#include <axis/server/AnyElement.h>
#include <stdlib.h>
#include <map>
#include <string>
#include "../../include/axis/server/GDefine.h"
XERCES_CPP_NAMESPACE_USE
using namespace std;
class XercesHandler : public XERCES_CPP_NAMESPACE::DefaultHandler
{
public :
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
XercesHandler();
~XercesHandler();
// -----------------------------------------------------------------------
// Handlers for the SAX DocumentHandler interface
// -----------------------------------------------------------------------
void startElement(const XMLCh *const uri,const XMLCh *const localname,const XMLCh *const qname,const Attributes &attrs);
void endElement (const XMLCh *const uri,const XMLCh *const localname,const XMLCh *const qname);
void characters(const XMLCh* const chars, const unsigned int length);
void startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri);
void endPrefixMapping(const XMLCh* const prefix);
void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
void resetDocument();
// -----------------------------------------------------------------------
// Implementations of the SAX ErrorHandler interface
// -----------------------------------------------------------------------
void warning(const SAXParseException& exception);
void error(const SAXParseException& exception);
void fatalError(const SAXParseException& exception);
const XML_Ch* XercesHandler::NS4Prefix(const XML_Ch* prefix);
int getTest()
{
return test;
}
AnyElement* getAnyElement()
{
return Nelement;
}
private:
int test;
AnyElement * Nelement;
map<AxisXMLString, AxisXMLString> m_NsStack;
void initAnyElement()
{
Nelement->m_pchNameOrValue = NULL;
Nelement->m_pchNamespace = NULL;
}
};
1.1 ws-axis/c/src/soap/XercesHandler.cpp
Index: XercesHandler.cpp
===================================================================
/* -*- C++ -*- */
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author sanjaya singharage (sanjayas@opensource.lk)
*/
#include "XercesHandler.h"
#include <xercesc/sax2/Attributes.hpp>
#include <stdio.h>
XercesHandler::XercesHandler()
{
test = 0;
Nelement = (AnyElement*)malloc(sizeof (AnyElement));
}
XercesHandler::~XercesHandler()
{
}
void XercesHandler::startElement(const XMLCh *const uri,const XMLCh *const localname,const XMLCh *const qname,const Attributes &attrs)
{
printf("%s", "in start element");
test++;
Nelement->m_type = START_ELEMENT;
Nelement->m_pchNameOrValue = XMLString::transcode(localname);
Nelement->m_pchNamespace = XMLString::transcode(uri);
unsigned int len = attrs.getLength();
for (unsigned int index = 0, int nextattrindex =-1 ; index < len; index++)
{
Nelement->m_pchAttributes[index+1] = XMLString::transcode(attrs.getLocalName(index));
Nelement->m_pchAttributes[index+2] = XMLString::transcode(attrs.getURI(index));
Nelement->m_pchAttributes[index+3] = XMLString::transcode(attrs.getValue(index));
nextattrindex += 3;
}
Nelement->m_pchAttributes[len*3]=NULL;
}
const XML_Ch* XercesHandler::NS4Prefix(const XML_Ch* prefix)
{
if (m_NsStack.find(prefix) != m_NsStack.end())
{
return m_NsStack[prefix].c_str();
}
return NULL;
}
void XercesHandler::characters(const XMLCh* const chars, const unsigned int length)
{
printf("%s", XMLString::transcode(chars));
test++;
Nelement->m_type = CHARACTER_ELEMENT;
Nelement->m_pchNameOrValue = XMLString::transcode(chars);
}
void XercesHandler::ignorableWhitespace(const XMLCh* const chars, const unsigned int length)
{}
void XercesHandler::resetDocument()
{}
void XercesHandler::warning(const SAXParseException& exception)
{}
void XercesHandler::error(const SAXParseException& exception)
{}
void XercesHandler::fatalError(const SAXParseException& exception)
{}
void XercesHandler::endElement (const XMLCh *const uri,const XMLCh *const localname,const XMLCh *const qname)
{
Nelement->m_type = END_ELEMENT;
Nelement->m_pchNameOrValue = XMLString::transcode(localname);
Nelement->m_pchNamespace = XMLString::transcode(uri);
Nelement->m_pchAttributes[0] = NULL;
}
void XercesHandler::startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri)
{
Nelement->m_type = START_PREFIX;
Nelement->m_pchNameOrValue = XMLString::transcode(prefix);
Nelement->m_pchNamespace = XMLString::transcode(uri);
m_NsStack[XMLString::transcode(prefix)] = XMLString::transcode(uri);
}
void XercesHandler::endPrefixMapping(const XMLCh* const prefix)
{
Nelement->m_type = END_PREFIX;
Nelement->m_pchNameOrValue = XMLString::transcode(prefix);
m_NsStack.erase(XMLString::transcode(prefix));
}
1.1 ws-axis/c/src/soap/SoapParserXerces.h
Index: SoapParserXerces.h
===================================================================
/* -*- C++ -*- */
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author sanjaya singharage (sanjayas@opensource.lk)
*/
#ifdef WIN32
#pragma warning (disable : 4786)
#endif
#if !defined(__SoapParserXerces_H_INCLUDED__)
#define __SoapParserXerces_H_INCLUDED__
#include <axis/server/Packet.h>
#include "../xml/Qname.h"
#include "../xml/Event.h"
#include <axis/server/AnyElement.h>
#include <axis/server/XMLParser.h>
#include "XercesHandler.h"
#include <xercesc/sax2/SAX2XMLReader.hpp>
#include <xercesc/parsers/SAXParser.hpp>
#include <xercesc/framework/XMLPScanToken.hpp>
#include "SoapInputSource.h"
//using namespace std;
XERCES_CPP_NAMESPACE_USE
class SoapParserXerces: public XMLParser
{
public:
SoapParserXerces();
~SoapParserXerces();
int SetInputStream(const Ax_soapstream* pInputStream);
const Ax_soapstream* GetInputStream(){return m_pInputStream;};
int Init();
const XML_Ch* GetNS4Prefix(const XML_Ch* prefix);
int GetStatus();
const AnyElement* Next();
AXIS_TRANSPORT_STATUS GetTransportStatus(){ return m_nTransportStatus;};
void SetTransportStatus(AXIS_TRANSPORT_STATUS nStatus){ m_nTransportStatus = nStatus;};
private:
int m_nStatus;
SAX2XMLReader* m_pParser;
//SAXParser* m_pParser;
const Ax_soapstream* m_pInputStream;
AXIS_TRANSPORT_STATUS m_nTransportStatus;
XMLPScanToken token;
XercesHandler Xhandler;
bool firstParsed;
SoapInputSource* is;
};
#endif
1.1 ws-axis/c/src/soap/SoapParserXerces.cpp
Index: SoapParserXerces.cpp
===================================================================
/* -*- C++ -*- */
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author sanjaya singharage (sanjayas@opensource.lk)
*/
#ifdef WIN32
#pragma warning (disable : 4786)
#endif
#include "SoapParserXerces.h"
#include <xercesc/sax2/XMLReaderFactory.hpp>
SoapParserXerces::SoapParserXerces()
{
m_nStatus = NULL;
firstParsed = false;
m_pParser = XMLReaderFactory::createXMLReader();
}
SoapParserXerces::~SoapParserXerces()
{
m_nStatus = NULL;
}
int SoapParserXerces::SetInputStream(const Ax_soapstream* pInputStream)
{
m_pInputStream = pInputStream;
is = new SoapInputSource(m_pInputStream->transport.pGetFunct, m_pInputStream->str.ip_stream);
//SoapInputSource is(m_pInputStream->transport.pGetFunct, m_pInputStream->str.ip_stream);
m_pParser->setContentHandler(&Xhandler);
//return m_pHandler->Success();
return AXIS_SUCCESS;
}
int SoapParserXerces::Init()
{
return 0;
}
const XML_Ch* SoapParserXerces::GetNS4Prefix(const XML_Ch* prefix)
{
return Xhandler.NS4Prefix(prefix);
}
int SoapParserXerces::GetStatus()
{
m_nStatus = AXIS_SUCCESS; /*TODO:Check if an error occured in expat */
return m_nStatus;
}
const AnyElement* SoapParserXerces::Next()
{
if(!firstParsed)
{
m_pParser->parseFirst(*is, token);
firstParsed = true;
}
m_pParser->parseNext(token);
return Xhandler.getAnyElement();
//handler
//return NULL;
}
1.1 ws-axis/c/src/soap/SoapInputSource.h
Index: SoapInputSource.h
===================================================================
/*
* @author sanjaya singharage (sanjayas@opensource.lk)
*/
// SoapInputSource.h: interface for the SoapInputSource class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SOAPINPUTSOURCE_H__CB5BD78C_76E6_4246_8EB8_D011ED7505FA__INCLUDED_)
#define AFX_SOAPINPUTSOURCE_H__CB5BD78C_76E6_4246_8EB8_D011ED7505FA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <xercesc/sax/InputSource.hpp>
#include "SoapBinInputStream.h"
XERCES_CPP_NAMESPACE_USE
class SoapInputSource : public InputSource
{
private:
SoapBinInputStream* m_pInputStream;
public:
SoapInputSource(AXIS_MODULE_CALLBACK_GET_MESSAGE_BYTES pReadFunct, const void* pContext);
virtual ~SoapInputSource();
BinInputStream* makeStream() const;
};
#endif // !defined(AFX_SOAPINPUTSOURCE_H__CB5BD78C_76E6_4246_8EB8_D011ED7505FA__INCLUDED_)
1.2 +41 -0 ws-axis/c/src/soap/SoapInputSource.cpp
1.1 ws-axis/c/src/soap/SoapBinInputStream.h
Index: SoapBinInputStream.h
===================================================================
/* -*- C++ -*- */
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// SoapBinInputStream.h: interface for the SoapBinInputStream class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_SOAPBININPUTSTREAM_H__E578FB79_0694_4FAA_B2A4_446751A793EA__INCLUDED_)
#define AFX_SOAPBININPUTSTREAM_H__E578FB79_0694_4FAA_B2A4_446751A793EA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <xercesc/util/BinInputStream.hpp>
#include <axis/server/Packet.h>
XERCES_CPP_NAMESPACE_USE
class SoapBinInputStream : public BinInputStream
{
private:
AXIS_MODULE_CALLBACK_GET_MESSAGE_BYTES m_pReadFunct;
unsigned int m_nByteCount;
const void* m_pContext;
public:
SoapBinInputStream(AXIS_MODULE_CALLBACK_GET_MESSAGE_BYTES pReadFunct, const void* pContext);
virtual ~SoapBinInputStream();
unsigned int curPos() const;
unsigned int readBytes(XMLByte* const toFill, const unsigned int maxToRead);
};
#endif // !defined(AFX_SOAPBININPUTSTREAM_H__E578FB79_0694_4FAA_B2A4_446751A793EA__INCLUDED_)
1.2 +54 -0 ws-axis/c/src/soap/SoapBinInputStream.cpp