blob: 574c7c6d77ae82d93c07ae1095c1d98ca2f8e69a [file] [log] [blame]
// Copyright 2003-2004 The Apache Software Foundation.
// (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved
//
// 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.
// !!! This include file must be first thing in file !!!
#include "../../platforms/PlatformAutoSense.hpp"
#include "Integer.hpp"
AXIS_CPP_NAMESPACE_START
Integer::Integer()
{
}
Integer::~Integer()
{
}
Integer::Integer(const xsd__integer* value)
{
if (value)
{
setNil(false);
serialize(value);
}
}
XSDTYPE Integer::getType()
{
return XSD_INTEGER;
}
xsd__integer* Integer::getInteger()
{
if (isNil())
{
return NULL;
}
else
{
return deserializeInteger(m_Buf);
}
}
void * Integer::getValue()
{
return (void*) getInteger();
}
AxisChar* Integer::serialize(const xsd__integer* value) throw (AxisSoapException)
{
MinInclusive* minInclusive = getMinInclusive();
if (minInclusive->isSet())
{
if ( *value < minInclusive->getMinInclusiveAsLONGLONG() )
{
AxisString exceptionMessage =
"Value to be serialized is less than MinInclusive specified for this type. MinInclusive = ";
AxisChar length[100];
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, minInclusive->getMinInclusiveAsLONGLONG());
exceptionMessage += length;
exceptionMessage += ", Value = ";
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, *value);
exceptionMessage += length;
exceptionMessage += ".";
delete minInclusive;
throw AxisSoapException(CLIENT_SOAP_SOAP_CONTENT_ERROR,
const_cast<AxisChar*>(exceptionMessage.c_str()));
}
}
delete minInclusive;
MinExclusive* minExclusive = getMinExclusive();
if (minExclusive->isSet())
{
if ( *value <= minExclusive->getMinExclusiveAsLONGLONG() )
{
AxisString exceptionMessage =
"Value to be serialized is less than or equal to MinExclusive specified for this type. MinExclusive = ";
AxisChar length[100];
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, minExclusive->getMinExclusiveAsLONGLONG());
exceptionMessage += length;
exceptionMessage += ", Value = ";
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, *value);
exceptionMessage += length;
exceptionMessage += ".";
delete minExclusive;
throw AxisSoapException(CLIENT_SOAP_SOAP_CONTENT_ERROR,
const_cast<AxisChar*>(exceptionMessage.c_str()));
}
}
delete minExclusive;
MaxInclusive* maxInclusive = getMaxInclusive();
if (maxInclusive->isSet())
{
if ( *value > maxInclusive->getMaxInclusiveAsLONGLONG() )
{
AxisString exceptionMessage =
"Value to be serialized is greater than MaxInclusive specified for this type. MaxInclusive = ";
AxisChar length[100];
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, maxInclusive->getMaxInclusiveAsLONGLONG());
exceptionMessage += length;
exceptionMessage += ", Value = ";
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, *value);
exceptionMessage += length;
exceptionMessage += ".";
delete maxInclusive;
throw AxisSoapException(CLIENT_SOAP_SOAP_CONTENT_ERROR,
const_cast<AxisChar*>(exceptionMessage.c_str()));
}
}
delete maxInclusive;
MaxExclusive* maxExclusive = getMaxExclusive();
if (maxExclusive->isSet())
{
if ( *value >= maxExclusive->getMaxExclusiveAsLONGLONG() )
{
AxisString exceptionMessage =
"Value to be serialized is greater than or equal to MaxExclusive specified for this type. MaxExclusive = ";
AxisChar length[100];
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, maxExclusive->getMaxExclusiveAsLONGLONG());
exceptionMessage += length;
exceptionMessage += ", Value = ";
sprintf(length, PRINTF_LONGLONG_FORMAT_SPECIFIER, *value);
exceptionMessage += length;
exceptionMessage += ".";
delete maxExclusive;
throw AxisSoapException(CLIENT_SOAP_SOAP_CONTENT_ERROR,
const_cast<AxisChar*>(exceptionMessage.c_str()));
}
}
delete maxExclusive;
AxisString formatSpecifier = "%";
int valueSize = 80;
TotalDigits* totalDigits = getTotalDigits();
if (totalDigits->isSet())
{
valueSize = totalDigits->getTotalDigits() + 1;
AxisChar digits[10];
AxisSprintf (digits, 10, "%i", totalDigits->getTotalDigits());
formatSpecifier += digits;
}
delete totalDigits;
formatSpecifier += PRINTF_LONGLONG_FORMAT_SPECIFIER_CHARS;
AxisChar* serializedValue = new char[valueSize];
AxisSprintf (serializedValue, valueSize, formatSpecifier.c_str(), *value);
IAnySimpleType::serialize(serializedValue);
delete [] serializedValue;
return m_Buf;
}
xsd__integer* Integer::deserializeInteger(const AxisChar* valueAsChar) throw (AxisSoapException)
{
xsd__integer * value = new xsd__integer;
*value = 0;
AxisChar currentNumber[] = {'\0', '\0'};
int stringLength = strlen(valueAsChar);
if (stringLength > 0)
{
int count = 0;
if (valueAsChar[0] == '-')
{
count = 1;
}
for ( ; count < stringLength ; count ++)
{
*value *= 10;
currentNumber[0] = valueAsChar[count];
*value += atoi(currentNumber);
}
if (valueAsChar[0] == '-')
{
*value *= -1;
}
}
return value;
}
FractionDigits* Integer::getFractionDigits()
{
return new FractionDigits(0);
}
AXIS_CPP_NAMESPACE_END