mirror of https://github.com/apache/activemq.git
AMQ-656: Applying patch_060518.zip. Moving scripts (under gram) to activemq-core.
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@409828 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
14fda24c87
commit
a3b0e8ad7f
|
@ -29,7 +29,7 @@ public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
filePostFix = getFilePostFix();
|
filePostFix = getFilePostFix();
|
||||||
if (destDir == null) {
|
if (destDir == null) {
|
||||||
destDir = new File("../openwire-cpp/src/command");
|
destDir = new File("../openwire-cpp/src/main/cpp/activemq/command");
|
||||||
}
|
}
|
||||||
return super.run();
|
return super.run();
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
|
||||||
else if( name.equals("DataStructure[]") )
|
else if( name.equals("DataStructure[]") )
|
||||||
name = "IDataStructure[]" ;
|
name = "IDataStructure[]" ;
|
||||||
|
|
||||||
return "ap<" + name.substring(0, name.length()-2) + ">";
|
return "array<" + name.substring(0, name.length()-2) + ">";
|
||||||
}
|
}
|
||||||
else if (name.equals("Throwable") || name.equals("Exception")) {
|
else if (name.equals("Throwable") || name.equals("Exception")) {
|
||||||
return "p<BrokerError>";
|
return "p<BrokerError>";
|
||||||
}
|
}
|
||||||
else if (name.equals("ByteSequence")) {
|
else if (name.equals("ByteSequence")) {
|
||||||
return "char*";
|
return "array<char>";
|
||||||
}
|
}
|
||||||
else if (name.equals("boolean")) {
|
else if (name.equals("boolean")) {
|
||||||
return "bool";
|
return "bool";
|
||||||
|
@ -84,6 +84,126 @@ public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
|
||||||
* Converts the Java type to a C++ default value
|
* Converts the Java type to a C++ default value
|
||||||
*/
|
*/
|
||||||
public String toCppDefaultValue(JClass type) {
|
public String toCppDefaultValue(JClass type) {
|
||||||
return "0";
|
String name = type.getSimpleName();
|
||||||
|
|
||||||
|
if ( name.equals("boolean") ) {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
else if (!type.isPrimitiveType()) {
|
||||||
|
return "NULL";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the Java type to the name of the C++ marshal method
|
||||||
|
* to be used
|
||||||
|
*/
|
||||||
|
public String toMarshalMethodName(JClass type) {
|
||||||
|
String name = type.getSimpleName();
|
||||||
|
if (name.equals("String")) {
|
||||||
|
return "marshalString";
|
||||||
|
}
|
||||||
|
else if (type.isArrayType()) {
|
||||||
|
if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
|
||||||
|
return "marshalByteArray" ;
|
||||||
|
else
|
||||||
|
return "marshalObjectArray" ;
|
||||||
|
}
|
||||||
|
else if ( name.equals("ByteSequence") ) {
|
||||||
|
return "marshalByteArray";
|
||||||
|
}
|
||||||
|
else if (name.equals("short") ) {
|
||||||
|
return "marshalShort";
|
||||||
|
}
|
||||||
|
else if (name.equals("int") ) {
|
||||||
|
return "marshalInt";
|
||||||
|
}
|
||||||
|
else if (name.equals("long") ) {
|
||||||
|
return "marshalLong";
|
||||||
|
}
|
||||||
|
else if (name.equals("byte")) {
|
||||||
|
return "marshalByte";
|
||||||
|
}
|
||||||
|
else if (name.equals("double")) {
|
||||||
|
return "marshalDouble";
|
||||||
|
}
|
||||||
|
else if (name.equals("float")) {
|
||||||
|
return "marshalFloat";
|
||||||
|
}
|
||||||
|
else if (name.equals("boolean")) {
|
||||||
|
return "marshalBoolean";
|
||||||
|
}
|
||||||
|
else if( !type.isPrimitiveType() ) {
|
||||||
|
return "marshalObject" ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return name ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the Java type to the name of the C++ unmarshal method
|
||||||
|
* to be used
|
||||||
|
*/
|
||||||
|
public String toUnmarshalMethodName(JClass type) {
|
||||||
|
String name = type.getSimpleName();
|
||||||
|
if (name.equals("String")) {
|
||||||
|
return "unmarshalString";
|
||||||
|
}
|
||||||
|
else if (type.isArrayType()) {
|
||||||
|
if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
|
||||||
|
return "unmarshalByteArray" ;
|
||||||
|
else
|
||||||
|
return "unmarshalObjectArray" ;
|
||||||
|
}
|
||||||
|
else if ( name.equals("ByteSequence") ) {
|
||||||
|
return "unmarshalByteArray";
|
||||||
|
}
|
||||||
|
else if (name.equals("short") ) {
|
||||||
|
return "unmarshalShort";
|
||||||
|
}
|
||||||
|
else if (name.equals("int") ) {
|
||||||
|
return "unmarshalInt";
|
||||||
|
}
|
||||||
|
else if (name.equals("long") ) {
|
||||||
|
return "unmarshalLong";
|
||||||
|
}
|
||||||
|
else if (name.equals("byte")) {
|
||||||
|
return "unmarshalByte";
|
||||||
|
}
|
||||||
|
else if (name.equals("double")) {
|
||||||
|
return "unmarshalDouble";
|
||||||
|
}
|
||||||
|
else if (name.equals("float")) {
|
||||||
|
return "unmarshalFloat";
|
||||||
|
}
|
||||||
|
else if (name.equals("boolean")) {
|
||||||
|
return "unmarshalBoolean";
|
||||||
|
}
|
||||||
|
else if( !type.isPrimitiveType() ) {
|
||||||
|
return "unmarshalObject" ;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return name ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the Java type to a C++ pointer cast
|
||||||
|
*/
|
||||||
|
public String toUnmarshalCast(JClass type) {
|
||||||
|
String name = toCppType(type) ;
|
||||||
|
|
||||||
|
if( name.startsWith("p<") )
|
||||||
|
return "p_cast<" + name.substring(2) ;
|
||||||
|
else if( name.startsWith("array<") &&
|
||||||
|
(type.isArrayType() && !type.getArrayComponentType().isPrimitiveType()) &&
|
||||||
|
!type.getSimpleName().equals("ByteSequence") )
|
||||||
|
return "array_cast<" + name.substring(6) ;
|
||||||
|
else
|
||||||
|
return "" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,92 +1,125 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2005-2006 The Apache Software Foundation
|
* Copyright 2005-2006 The Apache Software Foundation
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import org.apache.activemq.openwire.tool.OpenWireCppClassesScript
|
import org.apache.activemq.openwire.tool.OpenWireCppClassesScript
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the C++ commands for the Open Wire Format
|
* Generates the C++ commands for the Open Wire Format
|
||||||
*
|
*
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
class GenerateCppClasses extends OpenWireCppClassesScript {
|
class GenerateCppClasses extends OpenWireCppClassesScript {
|
||||||
|
|
||||||
void generateFile(PrintWriter out) {
|
void generateFile(PrintWriter out) {
|
||||||
out << """/*
|
out << """/*
|
||||||
* Copyright 2006 The Apache Software Foundation or its licensors, as
|
* Copyright 2006 The Apache Software Foundation or its licensors, as
|
||||||
* applicable.
|
* applicable.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "command/${className}.hpp"
|
#include "activemq/command/${className}.hpp"
|
||||||
|
|
||||||
using namespace apache::activemq::client::command;
|
using namespace apache::activemq::command;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Marshalling code for Open Wire Format for ${className}
|
* Command and marshalling code for OpenWire format for ${className}
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE!: This file is autogenerated - do not modify!
|
* NOTE!: This file is autogenerated - do not modify!
|
||||||
* if you need to make a change, please see the Groovy scripts in the
|
* if you need to make a change, please see the Groovy scripts in the
|
||||||
* activemq-core module
|
* activemq-core module
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
${className}::${className}()
|
${className}::${className}()
|
||||||
{"""
|
{"""
|
||||||
for (property in properties) {
|
for (property in properties) {
|
||||||
def value = toCppDefaultValue(property.type)
|
def value = toCppDefaultValue(property.type)
|
||||||
def propertyName = property.simpleName
|
def propertyName = property.simpleName
|
||||||
def parameterName = decapitalize(propertyName)
|
def parameterName = decapitalize(propertyName)
|
||||||
out << """
|
out << """
|
||||||
this->${parameterName} = ${value} ;"""
|
this->${parameterName} = ${value} ;"""
|
||||||
}
|
}
|
||||||
out << """
|
out << """
|
||||||
}
|
}
|
||||||
|
|
||||||
${className}::~${className}()
|
${className}::~${className}()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
"""
|
|
||||||
for (property in properties) {
|
unsigned char ${className}::getDataStructureType()
|
||||||
def type = toCppType(property.type)
|
{
|
||||||
def propertyName = property.simpleName
|
return ${className}::TYPE ;
|
||||||
def parameterName = decapitalize(propertyName)
|
}
|
||||||
out << """
|
"""
|
||||||
|
for (property in properties) {
|
||||||
${type} ${className}::get${propertyName}()
|
def type = toCppType(property.type)
|
||||||
{
|
def propertyName = property.simpleName
|
||||||
return ${parameterName} ;
|
def parameterName = decapitalize(propertyName)
|
||||||
}
|
out << """
|
||||||
|
|
||||||
void ${className}::set${propertyName}(${type} ${parameterName})
|
${type} ${className}::get${propertyName}()
|
||||||
{
|
{
|
||||||
this->${parameterName} = ${parameterName} ;
|
return ${parameterName} ;
|
||||||
}
|
}
|
||||||
"""
|
|
||||||
|
void ${className}::set${propertyName}(${type} ${parameterName})
|
||||||
}
|
{
|
||||||
}
|
this->${parameterName} = ${parameterName} ;
|
||||||
}
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
out << """
|
||||||
|
int ${className}::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)
|
||||||
|
{
|
||||||
|
int size = 0 ;
|
||||||
|
|
||||||
|
size += ${baseClass}::marshal(marshaller, mode, ostream) ; """
|
||||||
|
for (property in properties) {
|
||||||
|
def marshalMethod = toMarshalMethodName(property.type)
|
||||||
|
def propertyName = decapitalize(property.simpleName)
|
||||||
|
out << """
|
||||||
|
size += marshaller->${marshalMethod}(${propertyName}, mode, ostream) ; """
|
||||||
|
}
|
||||||
|
out << """
|
||||||
|
return size ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ${className}::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)
|
||||||
|
{
|
||||||
|
${baseClass}::unmarshal(marshaller, mode, istream) ; """
|
||||||
|
for (property in properties) {
|
||||||
|
def cast = toUnmarshalCast(property.type)
|
||||||
|
def unmarshalMethod = toUnmarshalMethodName(property.type)
|
||||||
|
def propertyName = decapitalize(property.simpleName)
|
||||||
|
out << """
|
||||||
|
${propertyName} = ${cast}(marshaller->${unmarshalMethod}(mode, istream)) ; """
|
||||||
|
}
|
||||||
|
out << """
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,17 +40,17 @@ class GenerateCppHeaders extends OpenWireCppHeadersScript {
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#ifndef ${className}_hpp_
|
#ifndef ActiveMQ_${className}_hpp_
|
||||||
#define ${className}_hpp_
|
#define ActiveMQ_${className}_hpp_
|
||||||
|
|
||||||
|
// Turn off warning message for ignored exception specification
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning( disable : 4290 )
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
"""
|
"""
|
||||||
if( baseClass.equals("BrokerError") )
|
out << """#include "activemq/command/${baseClass}.hpp"
|
||||||
out << """#include "${baseClass}.hpp"
|
|
||||||
"""
|
|
||||||
else
|
|
||||||
out << """#include "command/${baseClass}.hpp"
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
for (property in properties)
|
for (property in properties)
|
||||||
{
|
{
|
||||||
|
@ -65,38 +65,42 @@ for (property in properties)
|
||||||
if( arrayType.isPrimitiveType() )
|
if( arrayType.isPrimitiveType() )
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
if( includeName.startsWith("ap<") )
|
if( includeName.startsWith("array<") )
|
||||||
includeName = includeName.substring(3, includeName.length()-1) ;
|
includeName = includeName.substring(6, includeName.length()-1) ;
|
||||||
else if( includeName.startsWith("p<") )
|
else if( includeName.startsWith("p<") )
|
||||||
includeName = includeName.substring(2, includeName.length()-1)
|
includeName = includeName.substring(2, includeName.length()-1)
|
||||||
|
|
||||||
if( includeName.equals("BrokerError") )
|
if( includeName.equals("IDataStructure") )
|
||||||
out << """#include "${includeName}.hpp"
|
out << """#include "activemq/${includeName}.hpp"
|
||||||
"""
|
"""
|
||||||
else
|
else
|
||||||
out << """#include "command/${includeName}.hpp"
|
out << """#include "activemq/command/${includeName}.hpp"
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << """
|
out << """
|
||||||
#include "util/ifr/ap.hpp"
|
#include "activemq/protocol/IMarshaller.hpp"
|
||||||
#include "util/ifr/p.hpp"
|
#include "ppr/io/IOutputStream.hpp"
|
||||||
|
#include "ppr/io/IInputStream.hpp"
|
||||||
|
#include "ppr/io/IOException.hpp"
|
||||||
|
#include "ppr/util/ifr/array"
|
||||||
|
#include "ppr/util/ifr/p"
|
||||||
|
|
||||||
namespace apache
|
namespace apache
|
||||||
{
|
{
|
||||||
namespace activemq
|
namespace activemq
|
||||||
{
|
{
|
||||||
namespace client
|
namespace command
|
||||||
{
|
{
|
||||||
namespace command
|
using namespace ifr;
|
||||||
{
|
using namespace std;
|
||||||
using namespace ifr;
|
using namespace apache::activemq;
|
||||||
using namespace std;
|
using namespace apache::activemq::protocol;
|
||||||
using namespace apache::activemq::client;
|
using namespace apache::ppr::io;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Marshalling code for Open Wire Format for ${className}
|
* Command and marshalling code for OpenWire format for ${className}
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* NOTE!: This file is autogenerated - do not modify!
|
* NOTE!: This file is autogenerated - do not modify!
|
||||||
|
@ -106,7 +110,7 @@ namespace apache
|
||||||
*/
|
*/
|
||||||
class ${className} : public ${baseClass}
|
class ${className} : public ${baseClass}
|
||||||
{
|
{
|
||||||
private:
|
protected:
|
||||||
"""
|
"""
|
||||||
for (property in properties) {
|
for (property in properties) {
|
||||||
def type = toCppType(property.type)
|
def type = toCppType(property.type)
|
||||||
|
@ -116,13 +120,13 @@ private:
|
||||||
}
|
}
|
||||||
out << """
|
out << """
|
||||||
public:
|
public:
|
||||||
const static int TYPE = ${getOpenWireOpCode(jclass)};
|
const static unsigned char TYPE = ${getOpenWireOpCode(jclass)};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
${className}() ;
|
${className}() ;
|
||||||
virtual ~${className}() ;
|
virtual ~${className}() ;
|
||||||
|
|
||||||
virtual int getCommandType() ;
|
virtual unsigned char getDataStructureType() ;
|
||||||
"""
|
"""
|
||||||
for (property in properties) {
|
for (property in properties) {
|
||||||
def type = toCppType(property.type)
|
def type = toCppType(property.type)
|
||||||
|
@ -134,16 +138,16 @@ public:
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
out << """
|
out << """
|
||||||
|
virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;
|
||||||
|
virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/* namespace */
|
/* namespace */
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /*${className}_hpp_*/
|
#endif /*ActiveMQ_${className}_hpp_*/
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,8 @@
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
AdditionalIncludeDirectories="src"
|
AdditionalIncludeDirectories="src\main\cpp"
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0400"
|
||||||
RuntimeLibrary="2"
|
RuntimeLibrary="2"
|
||||||
UsePrecompiledHeader="0"
|
UsePrecompiledHeader="0"
|
||||||
ProgramDataBaseFileName="$(IntDir)\amqlib.pdb"
|
ProgramDataBaseFileName="$(IntDir)\amqlib.pdb"
|
||||||
|
@ -1098,6 +1098,10 @@
|
||||||
RelativePath=".\src\main\cpp\ppr\io\encoding\CharsetEncoderRegistry.hpp"
|
RelativePath=".\src\main\cpp\ppr\io\encoding\CharsetEncoderRegistry.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\main\cpp\ppr\io\encoding\CharsetEncodingException.hpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\main\cpp\ppr\io\encoding\ICharsetEncoder.hpp"
|
RelativePath=".\src\main\cpp\ppr\io\encoding\ICharsetEncoder.hpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -119,10 +119,10 @@
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
AdditionalIncludeDirectories="..\src"
|
AdditionalIncludeDirectories="src\main\cpp"
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0400"
|
||||||
RuntimeLibrary="2"
|
RuntimeLibrary="2"
|
||||||
UsePrecompiledHeader="2"
|
UsePrecompiledHeader="0"
|
||||||
ProgramDataBaseFileName="$(IntDir)\test.pdb"
|
ProgramDataBaseFileName="$(IntDir)\test.pdb"
|
||||||
WarningLevel="3"
|
WarningLevel="3"
|
||||||
Detect64BitPortabilityProblems="true"
|
Detect64BitPortabilityProblems="true"
|
||||||
|
@ -139,8 +139,9 @@
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
|
AdditionalDependencies="wsock32.lib"
|
||||||
LinkIncremental="1"
|
LinkIncremental="1"
|
||||||
GenerateDebugInformation="true"
|
GenerateDebugInformation="false"
|
||||||
SubSystem="1"
|
SubSystem="1"
|
||||||
OptimizeReferences="2"
|
OptimizeReferences="2"
|
||||||
EnableCOMDATFolding="2"
|
EnableCOMDATFolding="2"
|
||||||
|
|
|
@ -1,209 +0,0 @@
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Copyright 2005-2006 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.
|
|
||||||
*/
|
|
||||||
package org.apache.activemq.openwire.tool;
|
|
||||||
|
|
||||||
import org.codehaus.jam.JClass;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @version $Revision: 379824 $
|
|
||||||
*/
|
|
||||||
public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
|
|
||||||
|
|
||||||
public Object run() {
|
|
||||||
filePostFix = getFilePostFix();
|
|
||||||
if (destDir == null) {
|
|
||||||
destDir = new File("../openwire-cpp/src/main/cpp/activemq/command");
|
|
||||||
}
|
|
||||||
return super.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getFilePostFix() {
|
|
||||||
return ".cpp";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the Java type to a C++ type name
|
|
||||||
*/
|
|
||||||
public String toCppType(JClass type) {
|
|
||||||
String name = type.getSimpleName();
|
|
||||||
if (name.equals("String")) {
|
|
||||||
return "p<string>";
|
|
||||||
}
|
|
||||||
else if (type.isArrayType()) {
|
|
||||||
if( name.equals("byte[]") )
|
|
||||||
name = "char[]" ;
|
|
||||||
else if( name.equals("DataStructure[]") )
|
|
||||||
name = "IDataStructure[]" ;
|
|
||||||
|
|
||||||
return "array<" + name.substring(0, name.length()-2) + ">";
|
|
||||||
}
|
|
||||||
else if (name.equals("Throwable") || name.equals("Exception")) {
|
|
||||||
return "p<BrokerError>";
|
|
||||||
}
|
|
||||||
else if (name.equals("ByteSequence")) {
|
|
||||||
return "array<char>";
|
|
||||||
}
|
|
||||||
else if (name.equals("boolean")) {
|
|
||||||
return "bool";
|
|
||||||
}
|
|
||||||
else if (name.equals("long")) {
|
|
||||||
return "long long";
|
|
||||||
}
|
|
||||||
else if (name.equals("byte")) {
|
|
||||||
return "char";
|
|
||||||
}
|
|
||||||
else if( name.equals("Command") || name.equals("DataStructure") ) {
|
|
||||||
return "p<I" + name + ">" ;
|
|
||||||
}
|
|
||||||
else if( !type.isPrimitiveType() ) {
|
|
||||||
return "p<" + name + ">" ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return name ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the Java type to a C++ default value
|
|
||||||
*/
|
|
||||||
public String toCppDefaultValue(JClass type) {
|
|
||||||
String name = type.getSimpleName();
|
|
||||||
|
|
||||||
if ( name.equals("boolean") ) {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
else if (!type.isPrimitiveType()) {
|
|
||||||
return "NULL";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the Java type to the name of the C++ marshal method
|
|
||||||
* to be used
|
|
||||||
*/
|
|
||||||
public String toMarshalMethodName(JClass type) {
|
|
||||||
String name = type.getSimpleName();
|
|
||||||
if (name.equals("String")) {
|
|
||||||
return "marshalString";
|
|
||||||
}
|
|
||||||
else if (type.isArrayType()) {
|
|
||||||
if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
|
|
||||||
return "marshalByteArray" ;
|
|
||||||
else
|
|
||||||
return "marshalObjectArray" ;
|
|
||||||
}
|
|
||||||
else if ( name.equals("ByteSequence") ) {
|
|
||||||
return "marshalByteArray";
|
|
||||||
}
|
|
||||||
else if (name.equals("short") ) {
|
|
||||||
return "marshalShort";
|
|
||||||
}
|
|
||||||
else if (name.equals("int") ) {
|
|
||||||
return "marshalInt";
|
|
||||||
}
|
|
||||||
else if (name.equals("long") ) {
|
|
||||||
return "marshalLong";
|
|
||||||
}
|
|
||||||
else if (name.equals("byte")) {
|
|
||||||
return "marshalByte";
|
|
||||||
}
|
|
||||||
else if (name.equals("double")) {
|
|
||||||
return "marshalDouble";
|
|
||||||
}
|
|
||||||
else if (name.equals("float")) {
|
|
||||||
return "marshalFloat";
|
|
||||||
}
|
|
||||||
else if (name.equals("boolean")) {
|
|
||||||
return "marshalBoolean";
|
|
||||||
}
|
|
||||||
else if( !type.isPrimitiveType() ) {
|
|
||||||
return "marshalObject" ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return name ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the Java type to the name of the C++ unmarshal method
|
|
||||||
* to be used
|
|
||||||
*/
|
|
||||||
public String toUnmarshalMethodName(JClass type) {
|
|
||||||
String name = type.getSimpleName();
|
|
||||||
if (name.equals("String")) {
|
|
||||||
return "unmarshalString";
|
|
||||||
}
|
|
||||||
else if (type.isArrayType()) {
|
|
||||||
if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
|
|
||||||
return "unmarshalByteArray" ;
|
|
||||||
else
|
|
||||||
return "unmarshalObjectArray" ;
|
|
||||||
}
|
|
||||||
else if ( name.equals("ByteSequence") ) {
|
|
||||||
return "unmarshalByteArray";
|
|
||||||
}
|
|
||||||
else if (name.equals("short") ) {
|
|
||||||
return "unmarshalShort";
|
|
||||||
}
|
|
||||||
else if (name.equals("int") ) {
|
|
||||||
return "unmarshalInt";
|
|
||||||
}
|
|
||||||
else if (name.equals("long") ) {
|
|
||||||
return "unmarshalLong";
|
|
||||||
}
|
|
||||||
else if (name.equals("byte")) {
|
|
||||||
return "unmarshalByte";
|
|
||||||
}
|
|
||||||
else if (name.equals("double")) {
|
|
||||||
return "unmarshalDouble";
|
|
||||||
}
|
|
||||||
else if (name.equals("float")) {
|
|
||||||
return "unmarshalFloat";
|
|
||||||
}
|
|
||||||
else if (name.equals("boolean")) {
|
|
||||||
return "unmarshalBoolean";
|
|
||||||
}
|
|
||||||
else if( !type.isPrimitiveType() ) {
|
|
||||||
return "unmarshalObject" ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return name ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the Java type to a C++ pointer cast
|
|
||||||
*/
|
|
||||||
public String toUnmarshalCast(JClass type) {
|
|
||||||
String name = toCppType(type) ;
|
|
||||||
|
|
||||||
if( name.startsWith("p<") )
|
|
||||||
return "p_cast<" + name.substring(2) ;
|
|
||||||
else if( name.startsWith("array<") &&
|
|
||||||
(type.isArrayType() && !type.getArrayComponentType().isPrimitiveType()) &&
|
|
||||||
!type.getSimpleName().equals("ByteSequence") )
|
|
||||||
return "array_cast<" + name.substring(6) ;
|
|
||||||
else
|
|
||||||
return "" ;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright 2005-2006 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.
|
|
||||||
*/
|
|
||||||
package org.apache.activemq.openwire.tool;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @version $Revision: 379734 $
|
|
||||||
*/
|
|
||||||
public abstract class OpenWireCppHeadersScript extends OpenWireCppClassesScript {
|
|
||||||
|
|
||||||
protected String getFilePostFix() {
|
|
||||||
return ".hpp";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,125 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright 2005-2006 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.
|
|
||||||
*/
|
|
||||||
import org.apache.activemq.openwire.tool.OpenWireCppClassesScript
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates the C++ commands for the Open Wire Format
|
|
||||||
*
|
|
||||||
* @version $Revision$
|
|
||||||
*/
|
|
||||||
class GenerateCppClasses extends OpenWireCppClassesScript {
|
|
||||||
|
|
||||||
void generateFile(PrintWriter out) {
|
|
||||||
out << """/*
|
|
||||||
* Copyright 2006 The Apache Software Foundation or its licensors, as
|
|
||||||
* applicable.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#include "activemq/command/${className}.hpp"
|
|
||||||
|
|
||||||
using namespace apache::activemq::command;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Command and marshalling code for OpenWire format for ${className}
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NOTE!: This file is autogenerated - do not modify!
|
|
||||||
* if you need to make a change, please see the Groovy scripts in the
|
|
||||||
* activemq-core module
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
${className}::${className}()
|
|
||||||
{"""
|
|
||||||
for (property in properties) {
|
|
||||||
def value = toCppDefaultValue(property.type)
|
|
||||||
def propertyName = property.simpleName
|
|
||||||
def parameterName = decapitalize(propertyName)
|
|
||||||
out << """
|
|
||||||
this->${parameterName} = ${value} ;"""
|
|
||||||
}
|
|
||||||
out << """
|
|
||||||
}
|
|
||||||
|
|
||||||
${className}::~${className}()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char ${className}::getDataStructureType()
|
|
||||||
{
|
|
||||||
return ${className}::TYPE ;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
for (property in properties) {
|
|
||||||
def type = toCppType(property.type)
|
|
||||||
def propertyName = property.simpleName
|
|
||||||
def parameterName = decapitalize(propertyName)
|
|
||||||
out << """
|
|
||||||
|
|
||||||
${type} ${className}::get${propertyName}()
|
|
||||||
{
|
|
||||||
return ${parameterName} ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ${className}::set${propertyName}(${type} ${parameterName})
|
|
||||||
{
|
|
||||||
this->${parameterName} = ${parameterName} ;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
out << """
|
|
||||||
int ${className}::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)
|
|
||||||
{
|
|
||||||
int size = 0 ;
|
|
||||||
|
|
||||||
size += ${baseClass}::marshal(marshaller, mode, ostream) ; """
|
|
||||||
for (property in properties) {
|
|
||||||
def marshalMethod = toMarshalMethodName(property.type)
|
|
||||||
def propertyName = decapitalize(property.simpleName)
|
|
||||||
out << """
|
|
||||||
size += marshaller->${marshalMethod}(${propertyName}, mode, ostream) ; """
|
|
||||||
}
|
|
||||||
out << """
|
|
||||||
return size ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ${className}::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)
|
|
||||||
{
|
|
||||||
${baseClass}::unmarshal(marshaller, mode, istream) ; """
|
|
||||||
for (property in properties) {
|
|
||||||
def cast = toUnmarshalCast(property.type)
|
|
||||||
def unmarshalMethod = toUnmarshalMethodName(property.type)
|
|
||||||
def propertyName = decapitalize(property.simpleName)
|
|
||||||
out << """
|
|
||||||
${propertyName} = ${cast}(marshaller->${unmarshalMethod}(mode, istream)) ; """
|
|
||||||
}
|
|
||||||
out << """
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,153 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright 2005-2006 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.
|
|
||||||
*/
|
|
||||||
import org.apache.activemq.openwire.tool.OpenWireCppHeadersScript
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates the C++ commands for the Open Wire Format
|
|
||||||
*
|
|
||||||
* @version $Revision$
|
|
||||||
*/
|
|
||||||
class GenerateCppHeaders extends OpenWireCppHeadersScript {
|
|
||||||
|
|
||||||
void generateFile(PrintWriter out) {
|
|
||||||
out << """/*
|
|
||||||
* Copyright 2006 The Apache Software Foundation or its licensors, as
|
|
||||||
* applicable.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#ifndef ActiveMQ_${className}_hpp_
|
|
||||||
#define ActiveMQ_${className}_hpp_
|
|
||||||
|
|
||||||
// Turn off warning message for ignored exception specification
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning( disable : 4290 )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
"""
|
|
||||||
out << """#include "activemq/command/${baseClass}.hpp"
|
|
||||||
"""
|
|
||||||
for (property in properties)
|
|
||||||
{
|
|
||||||
if( !property.type.isPrimitiveType() &&
|
|
||||||
property.type.simpleName != "String" &&
|
|
||||||
property.type.simpleName != "ByteSequence" )
|
|
||||||
{
|
|
||||||
def includeName = toCppType(property.type)
|
|
||||||
if( property.type.isArrayType() )
|
|
||||||
{
|
|
||||||
def arrayType = property.type.arrayComponentType ;
|
|
||||||
if( arrayType.isPrimitiveType() )
|
|
||||||
continue ;
|
|
||||||
}
|
|
||||||
if( includeName.startsWith("array<") )
|
|
||||||
includeName = includeName.substring(6, includeName.length()-1) ;
|
|
||||||
else if( includeName.startsWith("p<") )
|
|
||||||
includeName = includeName.substring(2, includeName.length()-1)
|
|
||||||
|
|
||||||
if( includeName.equals("IDataStructure") )
|
|
||||||
out << """#include "activemq/${includeName}.hpp"
|
|
||||||
"""
|
|
||||||
else
|
|
||||||
out << """#include "activemq/command/${includeName}.hpp"
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out << """
|
|
||||||
#include "activemq/protocol/IMarshaller.hpp"
|
|
||||||
#include "ppr/io/IOutputStream.hpp"
|
|
||||||
#include "ppr/io/IInputStream.hpp"
|
|
||||||
#include "ppr/io/IOException.hpp"
|
|
||||||
#include "ppr/util/ifr/array"
|
|
||||||
#include "ppr/util/ifr/p"
|
|
||||||
|
|
||||||
namespace apache
|
|
||||||
{
|
|
||||||
namespace activemq
|
|
||||||
{
|
|
||||||
namespace command
|
|
||||||
{
|
|
||||||
using namespace ifr;
|
|
||||||
using namespace std;
|
|
||||||
using namespace apache::activemq;
|
|
||||||
using namespace apache::activemq::protocol;
|
|
||||||
using namespace apache::ppr::io;
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* Command and marshalling code for OpenWire format for ${className}
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NOTE!: This file is autogenerated - do not modify!
|
|
||||||
* if you need to make a change, please see the Groovy scripts in the
|
|
||||||
* activemq-core module
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class ${className} : public ${baseClass}
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
"""
|
|
||||||
for (property in properties) {
|
|
||||||
def type = toCppType(property.type)
|
|
||||||
def name = decapitalize(property.simpleName)
|
|
||||||
out << """ $type $name ;
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
out << """
|
|
||||||
public:
|
|
||||||
const static unsigned char TYPE = ${getOpenWireOpCode(jclass)};
|
|
||||||
|
|
||||||
public:
|
|
||||||
${className}() ;
|
|
||||||
virtual ~${className}() ;
|
|
||||||
|
|
||||||
virtual unsigned char getDataStructureType() ;
|
|
||||||
"""
|
|
||||||
for (property in properties) {
|
|
||||||
def type = toCppType(property.type)
|
|
||||||
def propertyName = property.simpleName
|
|
||||||
def parameterName = decapitalize(propertyName)
|
|
||||||
out << """
|
|
||||||
virtual ${type} get${propertyName}() ;
|
|
||||||
virtual void set${propertyName}(${type} ${parameterName}) ;
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
out << """
|
|
||||||
virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;
|
|
||||||
virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
/* namespace */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /*ActiveMQ_${className}_hpp_*/
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -248,8 +248,7 @@ void MessageConsumer::doClientAcknowledge(p<ActiveMQMessage> message)
|
||||||
void MessageConsumer::doAcknowledge(p<Message> message)
|
void MessageConsumer::doAcknowledge(p<Message> message)
|
||||||
{
|
{
|
||||||
p<MessageAck> ack = createMessageAck(message) ;
|
p<MessageAck> ack = createMessageAck(message) ;
|
||||||
//cout << "Sending Ack: " << ack->getAckType() << endl ;
|
session->getConnection()->oneway(ack) ;
|
||||||
session->getConnection()->syncRequest(ack) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -32,8 +32,9 @@ using namespace apache::activemq::protocol::openwire;
|
||||||
*/
|
*/
|
||||||
OpenWireMarshaller::OpenWireMarshaller(p<WireFormatInfo> formatInfo)
|
OpenWireMarshaller::OpenWireMarshaller(p<WireFormatInfo> formatInfo)
|
||||||
{
|
{
|
||||||
this->formatInfo = formatInfo ;
|
this->formatInfo = formatInfo ;
|
||||||
this->encoder = CharsetEncoderRegistry::getEncoder() ;
|
this->encoder = CharsetEncoderRegistry::getEncoder() ;
|
||||||
|
this->useTightEncoding = formatInfo->getTightEncodingEnabled() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Operation methods --------------------------------------------
|
// --- Operation methods --------------------------------------------
|
||||||
|
@ -46,7 +47,7 @@ int OpenWireMarshaller::marshalBoolean(bool value, int mode, p<IOutputStream> os
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
dos->writeBoolean(value) ;
|
dos->writeBoolean(value) ;
|
||||||
|
@ -68,7 +69,7 @@ int OpenWireMarshaller::marshalByte(char value, int mode, p<IOutputStream> ostre
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
dos->writeByte(value) ;
|
dos->writeByte(value) ;
|
||||||
|
@ -90,7 +91,7 @@ int OpenWireMarshaller::marshalShort(short value, int mode, p<IOutputStream> ost
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
dos->writeShort(value) ;
|
dos->writeShort(value) ;
|
||||||
|
@ -112,7 +113,7 @@ int OpenWireMarshaller::marshalInt(int value, int mode, p<IOutputStream> ostream
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
dos->writeInt(value) ;
|
dos->writeInt(value) ;
|
||||||
|
@ -134,7 +135,7 @@ int OpenWireMarshaller::marshalLong(long long value, int mode, p<IOutputStream>
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
dos->writeLong(value) ;
|
dos->writeLong(value) ;
|
||||||
|
@ -156,7 +157,7 @@ int OpenWireMarshaller::marshalFloat(float value, int mode, p<IOutputStream> ost
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
dos->writeFloat(value) ;
|
dos->writeFloat(value) ;
|
||||||
|
@ -178,7 +179,7 @@ int OpenWireMarshaller::marshalDouble(double value, int mode, p<IOutputStream> o
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
dos->writeDouble(value) ;
|
dos->writeDouble(value) ;
|
||||||
|
@ -200,7 +201,7 @@ int OpenWireMarshaller::marshalString(p<string> value, int mode, p<IOutputStream
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( mode == IMarshaller::MARSHAL_WRITE )
|
if( mode == IMarshaller::MARSHAL_WRITE )
|
||||||
{
|
{
|
||||||
|
@ -235,7 +236,7 @@ int OpenWireMarshaller::marshalObject(p<IDataStructure> object, int mode, p<IOut
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
int size = 0 ;
|
int size = 0 ;
|
||||||
|
|
||||||
|
@ -278,7 +279,7 @@ int OpenWireMarshaller::marshalObjectArray(array<IDataStructure> objects, int mo
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
int size = 0 ;
|
int size = 0 ;
|
||||||
|
|
||||||
|
@ -323,7 +324,7 @@ int OpenWireMarshaller::marshalByteArray(array<char> values, int mode, p<IOutput
|
||||||
// Assert that supplied output stream is a data output stream
|
// Assert that supplied output stream is a data output stream
|
||||||
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
p<DataOutputStream> dos = checkOutputStream(ostream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
int size = 0 ;
|
int size = 0 ;
|
||||||
|
|
||||||
|
@ -367,7 +368,7 @@ int OpenWireMarshaller::marshalByteArray(array<char> values, int mode, p<IOutput
|
||||||
*/
|
*/
|
||||||
int OpenWireMarshaller::marshalMap(p<PropertyMap> object, int mode, p<IOutputStream> ostream) throw(IOException)
|
int OpenWireMarshaller::marshalMap(p<PropertyMap> object, int mode, p<IOutputStream> ostream) throw(IOException)
|
||||||
{
|
{
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
int size = 0 ;
|
int size = 0 ;
|
||||||
|
|
||||||
|
@ -541,7 +542,7 @@ bool OpenWireMarshaller::unmarshalBoolean(int mode, p<IInputStream> istream) thr
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
return dis->readBoolean() ;
|
return dis->readBoolean() ;
|
||||||
}
|
}
|
||||||
|
@ -560,7 +561,7 @@ char OpenWireMarshaller::unmarshalByte(int mode, p<IInputStream> istream) throw(
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
return dis->readByte() ;
|
return dis->readByte() ;
|
||||||
}
|
}
|
||||||
|
@ -578,7 +579,7 @@ short OpenWireMarshaller::unmarshalShort(int mode, p<IInputStream> istream) thro
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
return dis->readShort() ;
|
return dis->readShort() ;
|
||||||
}
|
}
|
||||||
|
@ -597,7 +598,7 @@ int OpenWireMarshaller::unmarshalInt(int mode, p<IInputStream> istream) throw(IO
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
return dis->readInt() ;
|
return dis->readInt() ;
|
||||||
}
|
}
|
||||||
|
@ -616,7 +617,7 @@ long long OpenWireMarshaller::unmarshalLong(int mode, p<IInputStream> istream) t
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
return dis->readLong() ;
|
return dis->readLong() ;
|
||||||
}
|
}
|
||||||
|
@ -635,7 +636,7 @@ float OpenWireMarshaller::unmarshalFloat(int mode, p<IInputStream> istream) thro
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
return dis->readFloat() ;
|
return dis->readFloat() ;
|
||||||
}
|
}
|
||||||
|
@ -654,7 +655,7 @@ double OpenWireMarshaller::unmarshalDouble(int mode, p<IInputStream> istream) th
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
return dis->readFloat() ;
|
return dis->readFloat() ;
|
||||||
}
|
}
|
||||||
|
@ -673,7 +674,7 @@ p<string> OpenWireMarshaller::unmarshalString(int mode, p<IInputStream> istream)
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
if( dis->readBoolean() )
|
if( dis->readBoolean() )
|
||||||
return dis->readString() ;
|
return dis->readString() ;
|
||||||
|
@ -695,7 +696,7 @@ p<IDataStructure> OpenWireMarshaller::unmarshalObject(int mode, p<IInputStream>
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
// Null marker
|
// Null marker
|
||||||
if( !dis->readBoolean() )
|
if( !dis->readBoolean() )
|
||||||
|
@ -728,7 +729,7 @@ array<IDataStructure> OpenWireMarshaller::unmarshalObjectArray(int mode, p<IInpu
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
// Null marker
|
// Null marker
|
||||||
if( !dis->readBoolean() )
|
if( !dis->readBoolean() )
|
||||||
|
@ -766,7 +767,7 @@ array<char> OpenWireMarshaller::unmarshalByteArray(int mode, p<IInputStream> ist
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
// Null marker
|
// Null marker
|
||||||
if( !dis->readBoolean() )
|
if( !dis->readBoolean() )
|
||||||
|
@ -801,7 +802,7 @@ p<PropertyMap> OpenWireMarshaller::unmarshalMap(int mode, p<IInputStream> istrea
|
||||||
// Assert that supplied input stream is a data input stream
|
// Assert that supplied input stream is a data input stream
|
||||||
p<DataInputStream> dis = checkInputStream(istream) ;
|
p<DataInputStream> dis = checkInputStream(istream) ;
|
||||||
|
|
||||||
if( !formatInfo->getTightEncodingEnabled() )
|
if( !useTightEncoding )
|
||||||
{
|
{
|
||||||
// Get size of map
|
// Get size of map
|
||||||
int size = dis->readInt() ;
|
int size = dis->readInt() ;
|
||||||
|
|
|
@ -62,6 +62,7 @@ class OpenWireMarshaller : public IMarshaller
|
||||||
private:
|
private:
|
||||||
p<WireFormatInfo> formatInfo ;
|
p<WireFormatInfo> formatInfo ;
|
||||||
p<ICharsetEncoder> encoder ;
|
p<ICharsetEncoder> encoder ;
|
||||||
|
bool useTightEncoding ;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Primitive types
|
// Primitive types
|
||||||
|
|
|
@ -43,6 +43,9 @@ OpenWireProtocol::OpenWireProtocol()
|
||||||
wireFormatInfo->setSizePrefixDisabled(false) ;
|
wireFormatInfo->setSizePrefixDisabled(false) ;
|
||||||
wireFormatInfo->setTightEncodingEnabled(false) ;
|
wireFormatInfo->setTightEncodingEnabled(false) ;
|
||||||
|
|
||||||
|
// Use variable instead of map lookup for performance reason
|
||||||
|
this->sizePrefixDisabled = wireFormatInfo->getSizePrefixDisabled() ;
|
||||||
|
|
||||||
// Create wire marshaller
|
// Create wire marshaller
|
||||||
wireMarshaller = new OpenWireMarshaller(wireFormatInfo) ;
|
wireMarshaller = new OpenWireMarshaller(wireFormatInfo) ;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +90,7 @@ void OpenWireProtocol::marshal(p<IDataStructure> object, p<IOutputStream> ostrea
|
||||||
unsigned char dataType = object->getDataStructureType() ;
|
unsigned char dataType = object->getDataStructureType() ;
|
||||||
|
|
||||||
// Calculate size to be marshalled if configured
|
// Calculate size to be marshalled if configured
|
||||||
if( !wireFormatInfo->getSizePrefixDisabled() )
|
if( !sizePrefixDisabled )
|
||||||
{
|
{
|
||||||
size = 1 ; // data structure type
|
size = 1 ; // data structure type
|
||||||
size += object->marshal(wireMarshaller, IMarshaller::MARSHAL_SIZE, ostream) ;
|
size += object->marshal(wireMarshaller, IMarshaller::MARSHAL_SIZE, ostream) ;
|
||||||
|
@ -102,7 +105,7 @@ void OpenWireProtocol::marshal(p<IDataStructure> object, p<IOutputStream> ostrea
|
||||||
else // ...NULL object
|
else // ...NULL object
|
||||||
{
|
{
|
||||||
// Calculate size to be marshalled if configured
|
// Calculate size to be marshalled if configured
|
||||||
if( !wireFormatInfo->getSizePrefixDisabled() )
|
if( !sizePrefixDisabled )
|
||||||
{
|
{
|
||||||
// Calculate size to be marshalled
|
// Calculate size to be marshalled
|
||||||
size = 1 ; // data structure type
|
size = 1 ; // data structure type
|
||||||
|
@ -125,7 +128,7 @@ p<IDataStructure> OpenWireProtocol::unmarshal(p<IInputStream> istream) throw(IOE
|
||||||
int size = 0 ;
|
int size = 0 ;
|
||||||
|
|
||||||
// Read packet size if configured
|
// Read packet size if configured
|
||||||
if( !wireFormatInfo->getSizePrefixDisabled() )
|
if( !sizePrefixDisabled )
|
||||||
size = dis->readInt() ;
|
size = dis->readInt() ;
|
||||||
|
|
||||||
// First byte is the data structure type
|
// First byte is the data structure type
|
||||||
|
|
|
@ -57,6 +57,7 @@ class OpenWireProtocol : public IProtocol
|
||||||
private:
|
private:
|
||||||
p<OpenWireMarshaller> wireMarshaller ;
|
p<OpenWireMarshaller> wireMarshaller ;
|
||||||
p<WireFormatInfo> wireFormatInfo ;
|
p<WireFormatInfo> wireFormatInfo ;
|
||||||
|
bool sizePrefixDisabled ;
|
||||||
|
|
||||||
static const char NULL_TYPE ;
|
static const char NULL_TYPE ;
|
||||||
static const int PROTOCOL_VERSION ;
|
static const int PROTOCOL_VERSION ;
|
||||||
|
|
|
@ -33,11 +33,11 @@ FutureResponse::FutureResponse()
|
||||||
p<Response> FutureResponse::getResponse()
|
p<Response> FutureResponse::getResponse()
|
||||||
{
|
{
|
||||||
// Wait for response to arrive
|
// Wait for response to arrive
|
||||||
LOCKED_SCOPE (mutex);
|
LOCKED_SCOPE (mutex) ;
|
||||||
while ( response == NULL )
|
if ( response == NULL )
|
||||||
{
|
{
|
||||||
LOCKED_SCOPE_UNLOCK;
|
LOCKED_SCOPE_UNLOCK;
|
||||||
semaphore->wait(maxWait); // BUG: Why have a max wait when what you do is just to wait again and again? //dafah
|
semaphore->wait();
|
||||||
LOCKED_SCOPE_RELOCK;
|
LOCKED_SCOPE_RELOCK;
|
||||||
}
|
}
|
||||||
return response ;
|
return response ;
|
||||||
|
|
|
@ -197,7 +197,14 @@ p<string> DataInputStream::readString() throw(IOException)
|
||||||
|
|
||||||
// Decode string if charset encoder has been configured
|
// Decode string if charset encoder has been configured
|
||||||
if( encoder != NULL )
|
if( encoder != NULL )
|
||||||
value = encoder->decode(value) ;
|
{
|
||||||
|
try {
|
||||||
|
value = encoder->decode(value) ;
|
||||||
|
}
|
||||||
|
catch( CharsetEncodingException &cee ) {
|
||||||
|
throw new IOException( cee.what() ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else // ...empty string
|
else // ...empty string
|
||||||
value = new string("") ;
|
value = new string("") ;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "ppr/io/IInputStream.hpp"
|
#include "ppr/io/IInputStream.hpp"
|
||||||
#include "ppr/io/encoding/ICharsetEncoder.hpp"
|
#include "ppr/io/encoding/ICharsetEncoder.hpp"
|
||||||
#include "ppr/io/encoding/CharsetEncoderRegistry.hpp"
|
#include "ppr/io/encoding/CharsetEncoderRegistry.hpp"
|
||||||
|
#include "ppr/io/encoding/CharsetEncodingException.hpp"
|
||||||
#include "ppr/util/Endian.hpp"
|
#include "ppr/util/Endian.hpp"
|
||||||
#include "ppr/util/ifr/p"
|
#include "ppr/util/ifr/p"
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,14 @@ int DataOutputStream::writeString(p<string> value) throw(IOException)
|
||||||
|
|
||||||
// Encode string if an charset encoder has been configured
|
// Encode string if an charset encoder has been configured
|
||||||
if( encoder != NULL )
|
if( encoder != NULL )
|
||||||
data = encoder->encode(value, &length) ;
|
{
|
||||||
|
try {
|
||||||
|
data = encoder->encode(value, &length) ;
|
||||||
|
}
|
||||||
|
catch( CharsetEncodingException &cee ) {
|
||||||
|
throw IOException( cee.what() ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
data = value ;
|
data = value ;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "ppr/io/IOutputStream.hpp"
|
#include "ppr/io/IOutputStream.hpp"
|
||||||
#include "ppr/io/encoding/ICharsetEncoder.hpp"
|
#include "ppr/io/encoding/ICharsetEncoder.hpp"
|
||||||
#include "ppr/io/encoding/CharsetEncoderRegistry.hpp"
|
#include "ppr/io/encoding/CharsetEncoderRegistry.hpp"
|
||||||
|
#include "ppr/io/encoding/CharsetEncodingException.hpp"
|
||||||
#include "ppr/util/Endian.hpp"
|
#include "ppr/util/Endian.hpp"
|
||||||
#include "ppr/util/ifr/p"
|
#include "ppr/util/ifr/p"
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ int AsciiToUTF8Encoder::length(p<string> str)
|
||||||
/*
|
/*
|
||||||
* Encodes given string from ASCII into modified UTF-8.
|
* Encodes given string from ASCII into modified UTF-8.
|
||||||
*/
|
*/
|
||||||
p<string> AsciiToUTF8Encoder::encode(p<string> str, int *enclen)
|
p<string> AsciiToUTF8Encoder::encode(p<string> str, int *enclen) throw (CharsetEncodingException)
|
||||||
{
|
{
|
||||||
// Assert parameter
|
// Assert parameter
|
||||||
if( str == NULL )
|
if( str == NULL )
|
||||||
|
@ -125,7 +125,7 @@ p<string> AsciiToUTF8Encoder::encode(p<string> str, int *enclen)
|
||||||
/*
|
/*
|
||||||
* Decodes given string from modified UTF-8 into ASCII.
|
* Decodes given string from modified UTF-8 into ASCII.
|
||||||
*/
|
*/
|
||||||
p<string> AsciiToUTF8Encoder::decode(p<string> str)
|
p<string> AsciiToUTF8Encoder::decode(p<string> str) throw (CharsetEncodingException)
|
||||||
{
|
{
|
||||||
// Assert argument
|
// Assert argument
|
||||||
if( str == NULL || str->length() == 0 )
|
if( str == NULL || str->length() == 0 )
|
||||||
|
@ -159,28 +159,28 @@ p<string> AsciiToUTF8Encoder::decode(p<string> str)
|
||||||
i += 2 ;
|
i += 2 ;
|
||||||
|
|
||||||
if( i > length )
|
if( i > length )
|
||||||
throw exception() ;
|
throw CharsetEncodingException("Missing character in double pair") ;
|
||||||
|
|
||||||
ch2 = (*str)[i - 1] ;
|
ch2 = (*str)[i - 1] ;
|
||||||
if( (ch2 & 0xC0) != 0x80 )
|
if( (ch2 & 0xC0) != 0x80 )
|
||||||
throw exception() ;
|
throw CharsetEncodingException("Invalid second character in double byte pair") ;
|
||||||
|
|
||||||
decstr->append( 1, (char)(((ch & 0x1F) << 6) | (ch2 & 0x3F)) ) ;
|
decstr->append( 1, (char)(((ch & 0x1F) << 6) | (ch2 & 0x3F)) ) ;
|
||||||
break ;
|
break ;
|
||||||
case 14: // Triple bytes char, 1110xxxx 10xxxxxx 10xxxxxx
|
case 14: // Triple bytes char, 1110xxxx 10xxxxxx 10xxxxxx
|
||||||
i += 3 ;
|
i += 3 ;
|
||||||
if( i > length )
|
if( i > length )
|
||||||
throw exception() ;
|
throw CharsetEncodingException("Missing character in triple set") ;
|
||||||
|
|
||||||
ch2 = (*str)[i - 2] ;
|
ch2 = (*str)[i - 2] ;
|
||||||
ch3 = (*str)[i - 1] ;
|
ch3 = (*str)[i - 1] ;
|
||||||
if( ((ch2 & 0xC0) != 0x80) || ((ch3 & 0xC0) != 0x80) )
|
if( ((ch2 & 0xC0) != 0x80) || ((ch3 & 0xC0) != 0x80) )
|
||||||
throw exception();
|
throw CharsetEncodingException("Invalid second and/or third character in triple set") ;
|
||||||
|
|
||||||
decstr->append( 1, (char)(((ch & 0x0F) << 12) | ((ch2 & 0x3F) << 6) | ((ch3 & 0x3F) << 0)) ) ;
|
decstr->append( 1, (char)(((ch & 0x0F) << 12) | ((ch2 & 0x3F) << 6) | ((ch3 & 0x3F) << 0)) ) ;
|
||||||
break ;
|
break ;
|
||||||
default: // Unsupported, 10xxxxxx 1111xxxx
|
default: // Unsupported, 10xxxxxx 1111xxxx
|
||||||
throw exception() ;
|
throw CharsetEncodingException("Unsupported type flag") ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return decstr ;
|
return decstr ;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ppr/io/ByteArrayOutputStream.hpp>
|
#include <ppr/io/ByteArrayOutputStream.hpp>
|
||||||
#include <ppr/io/encoding/ICharsetEncoder.hpp>
|
#include <ppr/io/encoding/ICharsetEncoder.hpp>
|
||||||
|
#include <ppr/io/encoding/CharsetEncodingException.hpp>
|
||||||
#include <ppr/util/ifr/array>
|
#include <ppr/util/ifr/array>
|
||||||
#include <ppr/util/ifr/p>
|
#include <ppr/util/ifr/p>
|
||||||
|
|
||||||
|
@ -50,8 +51,8 @@ public:
|
||||||
virtual ~AsciiToUTF8Encoder() ;
|
virtual ~AsciiToUTF8Encoder() ;
|
||||||
|
|
||||||
virtual int length(p<string> str) ;
|
virtual int length(p<string> str) ;
|
||||||
virtual p<string> encode(p<string> str, int *enclen) ;
|
virtual p<string> encode(p<string> str, int *enclen) throw (CharsetEncodingException) ;
|
||||||
virtual p<string> decode(p<string> str) ;
|
virtual p<string> decode(p<string> str) throw (CharsetEncodingException) ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/* namespace */
|
/* namespace */
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2006 The Apache Software Foundation or its licensors, as
|
||||||
|
* applicable.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
#ifndef Ppr_CharsetEncodingException_hpp_
|
||||||
|
#define Ppr_CharsetEncodingException_hpp_
|
||||||
|
|
||||||
|
#include "ppr/TraceException.hpp"
|
||||||
|
|
||||||
|
namespace apache
|
||||||
|
{
|
||||||
|
namespace ppr
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Signals that a character encoding or decoding error has occurred.
|
||||||
|
*/
|
||||||
|
class CharsetEncodingException : public TraceException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CharsetEncodingException() : TraceException()
|
||||||
|
{ /* no-op */ } ;
|
||||||
|
CharsetEncodingException(const char *const& msg) : TraceException(msg)
|
||||||
|
{ /* no-op */ } ;
|
||||||
|
CharsetEncodingException(const char* fileName, int lineNo, const char* msg) : TraceException(msg)
|
||||||
|
{ /* no-op */ } ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
/* namespace */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /*Ppr_CharsetEncodingException_hpp_*/
|
|
@ -18,6 +18,7 @@
|
||||||
#define Ppr_ICharsetEncoder_hpp_
|
#define Ppr_ICharsetEncoder_hpp_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <ppr/io/encoding/CharsetEncodingException.hpp>
|
||||||
#include "ppr/util/ifr/array"
|
#include "ppr/util/ifr/array"
|
||||||
#include "ppr/util/ifr/p"
|
#include "ppr/util/ifr/p"
|
||||||
|
|
||||||
|
@ -39,8 +40,8 @@ namespace apache
|
||||||
struct ICharsetEncoder : Interface
|
struct ICharsetEncoder : Interface
|
||||||
{
|
{
|
||||||
virtual int length(p<string> str) = 0 ;
|
virtual int length(p<string> str) = 0 ;
|
||||||
virtual p<string> encode(p<string> str, int *enclen) = 0 ;
|
virtual p<string> encode(p<string> str, int *enclen) throw (CharsetEncodingException) = 0 ;
|
||||||
virtual p<string> decode(p<string> str) = 0 ;
|
virtual p<string> decode(p<string> str) throw (CharsetEncodingException) = 0 ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/* namespace */
|
/* namespace */
|
||||||
|
|
|
@ -56,11 +56,10 @@ void TestSynchQueue::execute() throw (exception)
|
||||||
|
|
||||||
// Connect to queue
|
// Connect to queue
|
||||||
queue = session->getQueue("FOO.BAR") ;
|
queue = session->getQueue("FOO.BAR") ;
|
||||||
|
|
||||||
// Create a consumer and producer
|
// Create a consumer and producer
|
||||||
consumer = session->createConsumer(queue) ;
|
consumer = session->createConsumer(queue) ;
|
||||||
producer = session->createProducer(queue) ;
|
producer = session->createProducer(queue) ;
|
||||||
producer->setPersistent(true) ;
|
|
||||||
|
|
||||||
// Create a message
|
// Create a message
|
||||||
reqMessage = session->createTextMessage("Hello World!") ;
|
reqMessage = session->createTextMessage("Hello World!") ;
|
||||||
|
@ -78,17 +77,26 @@ void TestSynchQueue::execute() throw (exception)
|
||||||
throw TraceException("Received a null message") ;
|
throw TraceException("Received a null message") ;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
p<string> str ;
|
||||||
|
|
||||||
props = rspMessage->getProperties() ;
|
props = rspMessage->getProperties() ;
|
||||||
item = (*props)["someHeader"] ;
|
item = (*props)["someHeader"] ;
|
||||||
|
|
||||||
// Verify message
|
// Verify message
|
||||||
if( rspMessage->getJMSCorrelationID()->compare("abc") != 0 )
|
str = rspMessage->getJMSCorrelationID() ;
|
||||||
|
if( str == NULL || str->compare("abc") != 0 )
|
||||||
throw TraceException("Returned message has invalid correlation ID") ;
|
throw TraceException("Returned message has invalid correlation ID") ;
|
||||||
if( rspMessage->getJMSXGroupID()->compare("cheese") != 0 )
|
|
||||||
|
str = rspMessage->getJMSXGroupID() ;
|
||||||
|
if( str == NULL || str->compare("cheese") != 0 )
|
||||||
throw TraceException("Returned message has invalid group ID") ;
|
throw TraceException("Returned message has invalid group ID") ;
|
||||||
if( rspMessage->getText()->compare("Hello World!") != 0 )
|
|
||||||
|
str = rspMessage->getText() ;
|
||||||
|
if( str == NULL || str->compare("Hello World!") != 0 )
|
||||||
throw TraceException("Returned message has altered body text") ;
|
throw TraceException("Returned message has altered body text") ;
|
||||||
if( item.getString()->compare("James") != 0 )
|
|
||||||
|
str = item.getString() ;
|
||||||
|
if( str == NULL || str->compare("James") != 0 )
|
||||||
throw TraceException("Returned message has invalid properties") ;
|
throw TraceException("Returned message has invalid properties") ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue