Skip to content

Commit

Permalink
feat: use appropriate methods to convert the numbers in XML
Browse files Browse the repository at this point in the history
Conversion of the numbers using appropriate methods of each different type.

ING-3965
  • Loading branch information
emanuelaepure10 committed May 14, 2024
1 parent d56e083 commit f08c2bc
Show file tree
Hide file tree
Showing 18 changed files with 677 additions and 0 deletions.
36 changes: 36 additions & 0 deletions io/plugins/eu.esdihumboldt.hale.io.gml/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,42 @@
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlTimeToTimestamp">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlIntegerToInteger">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.IntegerToXmlInteger">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.FloatToXmlFloat">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlFloatToFloat">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.LongToXmlLong">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlLongToLong">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.DoubleToXmlDouble">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlDoubleToDouble">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.BigDecimalToXmlDecimal">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlDecimalToBigDecimal">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.BigIntegerToXmlBigInteger">
</converter>
<converter
class="eu.esdihumboldt.hale.io.gml.internal.simpletype.converters.XmlIntegerToBigInteger">
</converter>
</extension>
<extension
point="eu.esdihumboldt.util.groovy.sandbox">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
import org.apache.xmlbeans.XmlAnySimpleType;
import org.apache.xmlbeans.XmlDate;
import org.apache.xmlbeans.XmlDateTime;
import org.apache.xmlbeans.XmlDecimal;
import org.apache.xmlbeans.XmlDouble;
import org.apache.xmlbeans.XmlFloat;
import org.apache.xmlbeans.XmlInt;
import org.apache.xmlbeans.XmlInteger;
import org.apache.xmlbeans.XmlLong;
import org.apache.xmlbeans.XmlShort;
import org.apache.xmlbeans.XmlTime;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConversionService;
Expand Down Expand Up @@ -62,6 +69,14 @@ public class SimpleTypeUtil {
TYPE_MAP.put("dateTime", XmlDateTime.class); //$NON-NLS-1$
TYPE_MAP.put("date", XmlDate.class); //$NON-NLS-1$
TYPE_MAP.put("time", XmlTime.class); //$NON-NLS-1$

TYPE_MAP.put("int", XmlInt.class); //$NON-NLS-1$
TYPE_MAP.put("integer", XmlInteger.class); //$NON-NLS-1$
TYPE_MAP.put("short", XmlShort.class); //$NON-NLS-1$
TYPE_MAP.put("float", XmlFloat.class); //$NON-NLS-1$
TYPE_MAP.put("double", XmlDouble.class); //$NON-NLS-1$
TYPE_MAP.put("long", XmlLong.class); //$NON-NLS-1$
TYPE_MAP.put("decimal", XmlDecimal.class); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -111,6 +126,7 @@ else if (simpleTypeValue instanceof XmlDateTime) {
xmlDateTime.setGDateValue(gdate);
}

// Numbers should be handled here
if (simpleTypeValue != null) {
return simpleTypeValue.getStringValue();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import java.math.BigDecimal;

import org.apache.xmlbeans.XmlDecimal;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:BigDecimal to {@link XmlDecimal}
*/
public class BigDecimalToXmlDecimal implements Converter<BigDecimal, XmlDecimal> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlDecimal convert(BigDecimal value) {
if (value == null) {
return null;
}

// Convert BigDecimal to string
String stringValue = value.toPlainString();

XmlDecimal xmlDecimalValue = XmlDecimal.Factory.newInstance();
xmlDecimalValue.setStringValue(stringValue);
return xmlDecimalValue;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import java.math.BigInteger;

import org.apache.xmlbeans.XmlInteger;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:BigInteger to {@link XmlInteger}
*/
public class BigIntegerToXmlBigInteger implements Converter<BigInteger, XmlInteger> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlInteger convert(BigInteger value) {
if (value == null) {
return null;
}
return XmlInteger.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlDouble;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Double to {@link XmlDouble}
*/
public class DoubleToXmlDouble implements Converter<Double, XmlDouble> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlDouble convert(Double value) {
if (value == null) {
return null;
}
return XmlDouble.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* aFloat with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlFloat;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Float to {@link XmlFloat}
*/
public class FloatToXmlFloat implements Converter<Float, XmlFloat> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlFloat convert(Float value) {
if (value == null) {
return null;
}
return XmlFloat.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlInt;
import org.apache.xmlbeans.XmlInteger;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Int to {@link XmlInteger}
*/
public class IntegerToXmlInt implements Converter<Integer, XmlInt> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlInt convert(Integer value) {
if (value == null) {
return null;
}
return XmlInt.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlInteger;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Integer to {@link XmlInteger}
*/
public class IntegerToXmlInteger implements Converter<Integer, XmlInteger> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlInteger convert(Integer value) {
if (value == null) {
return null;
}
return XmlInteger.Factory.newValue(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Data Harmonisation Panel
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* HUMBOLDT EU Integrated Project #030962
* Data Harmonisation Panel <http://www.dhpanel.eu>
*/

package eu.esdihumboldt.hale.io.gml.internal.simpletype.converters;

import org.apache.xmlbeans.XmlLong;
import org.springframework.core.convert.converter.Converter;

/**
* Convert xs:Long to {@link XmlLong}
*/
public class LongToXmlLong implements Converter<Long, XmlLong> {

/**
* @see Converter#convert(Object)
*/
@Override
public XmlLong convert(Long value) {
if (value == null) {
return null;
}
return XmlLong.Factory.newValue(value);
}

}
Loading

0 comments on commit f08c2bc

Please sign in to comment.