Example usage for javax.xml.bind DatatypeConverter parseDecimal

List of usage examples for javax.xml.bind DatatypeConverter parseDecimal

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseDecimal.

Prototype

public static java.math.BigDecimal parseDecimal(String lexicalXSDDecimal) 

Source Link

Document

Converts the string argument into a BigDecimal value.

Usage

From source file:com.labs64.netlicensing.domain.vo.Money.java

public static Money convertPrice(final String rawPrice, final String rawCurrency) {
    final Money target = new Money();
    if (StringUtils.isNotBlank(rawPrice)) {
        try {/* w w w.j a v  a  2 s  .  c  o  m*/
            target.setAmount(DatatypeConverter.parseDecimal(rawPrice));
        } catch (final NumberFormatException e) {
            throw new IllegalArgumentException(
                    "'" + Constants.PRICE + "' format is not correct, expected '0.00' format");
        }
        if (StringUtils.isNotBlank(rawCurrency)) {
            if (Currency.parseValueSafe(rawCurrency) == null) {
                throw new IllegalArgumentException("Unsupported currency!");
            }
            target.setCurrencyCode(rawCurrency);
        } else {
            throw new IllegalArgumentException("'" + Constants.PRICE + "' field must be accompanied with the '"
                    + Constants.CURRENCY + "' field");
        }
    } else { // 'price' is not provided
        if (StringUtils.isNotBlank(rawCurrency)) {
            throw new IllegalArgumentException("'" + Constants.CURRENCY
                    + "' field can not be used without the '" + Constants.PRICE + "' field");
        }
    }
    return target;
}

From source file:br.com.upic.camel.openedge.OpenEdgeEndpoint.java

@Override
protected void onExchange(final Exchange exchange) throws Exception {

    try {/*from www  . j  a  v  a  2  s.c o  m*/
        LOG.info("Unmarshalling the request");

        final Request req = (Request) unmarshaller.unmarshal(exchange.getIn().getBody(Document.class));

        LOG.info("Setting the input params");

        final List<JAXBElement<? extends Serializable>> reqParamElementList = req.getParamElementList();

        final ParamArray proParams = new ParamArray(reqParamElementList.size());

        for (final JAXBElement<? extends Serializable> reqParamElement : reqParamElementList) {
            final Serializable reqParam = reqParamElement.getValue();

            if (reqParam instanceof CharArrayParam) {
                final CharArrayParam charArrayParam = (CharArrayParam) reqParam;

                final ParamMode mode = charArrayParam.getMode();

                final int id = charArrayParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final List<String> value = new ArrayList<String>();

                    for (final JAXBElement<String> valueElement : charArrayParam.getValueElementList()) {

                        if (!valueElement.isNil())
                            value.add(DatatypeConverter.parseString(valueElement.getValue()));
                        else
                            value.add(null);

                    }

                    proParams.addCharacterArray(id, value.toArray(new String[] {}), mode.value(), value.size());
                } else {
                    proParams.addCharacterArray(id, null, mode.value(), 0);
                }

            } else if (reqParam instanceof CharParam) {
                final CharParam charParam = (CharParam) reqParam;

                final ParamMode mode = charParam.getMode();

                final int id = charParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil()))
                    proParams.addCharacter(id, DatatypeConverter.parseString(charParam.getContent()),
                            mode.value());
                else
                    proParams.addCharacter(id, null, mode.value());

            } else if (reqParam instanceof DateArrayParam) {
                final DateArrayParam dateArrayParam = (DateArrayParam) reqParam;

                final ParamMode mode = dateArrayParam.getMode();

                final int id = dateArrayParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>();

                    for (final JAXBElement<String> valueElement : dateArrayParam.getValueElementList()) {

                        if (!valueElement.isNil()) {
                            final GregorianCalendar cal = new GregorianCalendar();

                            cal.setTime(DatatypeConverter.parseDate(valueElement.getValue()).getTime());

                            value.add(cal);
                        } else {
                            value.add(null);
                        }

                    }

                    proParams.addDateArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(),
                            value.size());
                } else {
                    proParams.addDateArray(id, null, mode.value(), 0);
                }

            } else if (reqParam instanceof DateParam) {
                final DateParam dateParam = (DateParam) reqParam;

                final ParamMode mode = dateParam.getMode();

                final int id = dateParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final GregorianCalendar cal = new GregorianCalendar();

                    cal.setTime(DatatypeConverter.parseDate(dateParam.getContent()).getTime());

                    proParams.addDate(id, cal, mode.value());
                } else {
                    proParams.addDate(id, null, mode.value());
                }

            } else if (reqParam instanceof DateTimeArrayParam) {
                final DateTimeArrayParam dateTimeArrayParam = (DateTimeArrayParam) reqParam;

                final ParamMode mode = dateTimeArrayParam.getMode();

                final int id = dateTimeArrayParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>();

                    for (final JAXBElement<String> valueElement : dateTimeArrayParam.getValueElementList()) {

                        if (!valueElement.isNil()) {
                            final GregorianCalendar cal = new GregorianCalendar();

                            cal.setTime(DatatypeConverter.parseDateTime(valueElement.getValue()).getTime());

                            value.add(cal);
                        } else {
                            value.add(null);
                        }

                    }

                    proParams.addDatetimeArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(),
                            value.size());
                } else {
                    proParams.addDatetimeArray(id, null, mode.value(), 0);
                }

            } else if (reqParam instanceof DateTimeParam) {
                final DateTimeParam dateTimeParam = (DateTimeParam) reqParam;

                final ParamMode mode = dateTimeParam.getMode();

                final int id = dateTimeParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final GregorianCalendar cal = new GregorianCalendar();

                    cal.setTime(DatatypeConverter.parseDateTime(dateTimeParam.getContent()).getTime());

                    proParams.addDatetime(id, cal, mode.value());
                } else {
                    proParams.addDatetime(id, null, mode.value());
                }

            } else if (reqParam instanceof DateTimeTZArrayParam) {
                final DateTimeTZArrayParam dateTimeTZArrayParam = (DateTimeTZArrayParam) reqParam;

                final ParamMode mode = dateTimeTZArrayParam.getMode();

                final int id = dateTimeTZArrayParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final List<GregorianCalendar> value = new ArrayList<GregorianCalendar>();

                    for (final JAXBElement<String> valueElement : dateTimeTZArrayParam.getValueElementList()) {

                        if (!valueElement.isNil()) {
                            final GregorianCalendar cal = new GregorianCalendar();

                            cal.setTime(DatatypeConverter.parseDateTime(valueElement.getValue()).getTime());

                            value.add(cal);
                        } else {
                            value.add(null);
                        }

                    }

                    proParams.addDatetimeTZArray(id, value.toArray(new GregorianCalendar[] {}), mode.value(),
                            value.size());
                } else {
                    proParams.addDatetimeTZArray(id, null, mode.value(), 0);
                }

            } else if (reqParam instanceof DateTimeTZParam) {
                final DateTimeTZParam dateTimeTZParam = (DateTimeTZParam) reqParam;

                final ParamMode mode = dateTimeTZParam.getMode();

                final int id = dateTimeTZParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final GregorianCalendar cal = new GregorianCalendar();

                    cal.setTime(DatatypeConverter.parseDateTime(dateTimeTZParam.getContent()).getTime());

                    proParams.addDatetimeTZ(id, cal, mode.value());
                } else {
                    proParams.addDatetimeTZ(id, null, mode.value());
                }

            } else if (reqParam instanceof DecArrayParam) {
                final DecArrayParam decArrayParam = (DecArrayParam) reqParam;

                final ParamMode mode = decArrayParam.getMode();

                final int id = decArrayParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final List<BigDecimal> value = new ArrayList<BigDecimal>();

                    for (final JAXBElement<String> valueElement : decArrayParam.getValueElementList()) {

                        if (!valueElement.isNil())
                            value.add(DatatypeConverter.parseDecimal(valueElement.getValue()));
                        else
                            value.add(null);

                    }

                    proParams.addDecimalArray(id, value.toArray(new BigDecimal[] {}), mode.value(),
                            value.size());
                } else {
                    proParams.addDecimalArray(id, null, mode.value(), 0);
                }

            } else if (reqParam instanceof DecParam) {
                final DecParam decParam = (DecParam) reqParam;

                final ParamMode mode = decParam.getMode();

                final int id = decParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil()))
                    proParams.addDecimal(id, DatatypeConverter.parseDecimal(decParam.getContent()),
                            mode.value());
                else
                    proParams.addDecimal(id, null, mode.value());

            } else if (reqParam instanceof IntArrayParam) {
                final IntArrayParam intArrayParam = (IntArrayParam) reqParam;

                final ParamMode mode = intArrayParam.getMode();

                final int id = intArrayParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final List<Integer> value = new ArrayList<Integer>();

                    for (final JAXBElement<String> valueElement : intArrayParam.getValueElementList()) {

                        if (!valueElement.isNil())
                            value.add(DatatypeConverter.parseInt(valueElement.getValue()));
                        else
                            value.add(null);

                    }

                    proParams.addIntegerArray(id, value.toArray(new Integer[] {}), mode.value(), value.size());
                } else {
                    proParams.addIntegerArray(id, (Integer[]) null, mode.value(), 0);
                }

            } else if (reqParam instanceof IntParam) {
                final IntParam intParam = (IntParam) reqParam;

                final ParamMode mode = intParam.getMode();

                final int id = intParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil()))
                    proParams.addInteger(id, new Integer(DatatypeConverter.parseInt(intParam.getContent())),
                            mode.value());
                else
                    proParams.addInteger(id, null, mode.value());

            } else if (reqParam instanceof LogArrayParam) {
                final LogArrayParam logArrayParam = (LogArrayParam) reqParam;

                final ParamMode mode = logArrayParam.getMode();

                final int id = logArrayParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil())) {
                    final List<Boolean> value = new ArrayList<Boolean>();

                    for (final JAXBElement<String> valueElement : logArrayParam.getValueElementList()) {

                        if (!valueElement.isNil())
                            value.add(DatatypeConverter.parseBoolean(valueElement.getValue()));
                        else
                            value.add(null);

                    }

                    proParams.addLogicalArray(id, value.toArray(new Boolean[] {}), mode.value(), value.size());
                } else {
                    proParams.addLogicalArray(id, (Boolean[]) null, mode.value(), 0);
                }

            } else if (reqParam instanceof LogParam) {
                final LogParam logParam = (LogParam) reqParam;

                final ParamMode mode = logParam.getMode();

                final int id = logParam.getId();

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil()))
                    proParams.addLogical(id, new Boolean(DatatypeConverter.parseBoolean(logParam.getContent())),
                            mode.value());
                else
                    proParams.addLogical(id, null, mode.value());

            } else if (reqParam instanceof ResultSetParam) {
                final ResultSetParam rsParam = (ResultSetParam) reqParam;

                final ParamMode mode = rsParam.getMode();

                final int id = rsParam.getId();

                final ResultSetMetaData rsMetaData = rsParam.getResultSetMetaData();

                final List<Serializable> fieldMetaDataList = rsMetaData.getFieldMetaDataList();

                final ProResultSetMetaDataImpl proRsMetaData = new ProResultSetMetaDataImpl(
                        fieldMetaDataList.size());

                for (final Serializable fieldMetaData : fieldMetaDataList) {

                    if (fieldMetaData instanceof CharFieldMetaData) {
                        final CharFieldMetaData charFieldMetaData = (CharFieldMetaData) fieldMetaData;

                        proRsMetaData.setFieldMetaData(charFieldMetaData.getId(), charFieldMetaData.getName(),
                                charFieldMetaData.getExtent(), Parameter.PRO_CHARACTER);
                    } else if (fieldMetaData instanceof DateFieldMetaData) {
                        final DateFieldMetaData dateFieldMetaData = (DateFieldMetaData) fieldMetaData;

                        proRsMetaData.setFieldMetaData(dateFieldMetaData.getId(), dateFieldMetaData.getName(),
                                dateFieldMetaData.getExtent(), Parameter.PRO_DATE);
                    } else if (fieldMetaData instanceof DateTimeFieldMetaData) {
                        final DateTimeFieldMetaData dateTimeFieldMetaData = (DateTimeFieldMetaData) fieldMetaData;

                        proRsMetaData.setFieldMetaData(dateTimeFieldMetaData.getId(),
                                dateTimeFieldMetaData.getName(), dateTimeFieldMetaData.getExtent(),
                                Parameter.PRO_DATETIME);
                    } else if (fieldMetaData instanceof DateTimeTZFieldMetaData) {
                        final DateTimeTZFieldMetaData dateTimeTZFieldMetaData = (DateTimeTZFieldMetaData) fieldMetaData;

                        proRsMetaData.setFieldMetaData(dateTimeTZFieldMetaData.getId(),
                                dateTimeTZFieldMetaData.getName(), dateTimeTZFieldMetaData.getExtent(),
                                Parameter.PRO_DATETIMETZ);
                    } else if (fieldMetaData instanceof DecFieldMetaData) {
                        final DecFieldMetaData decFieldMetaData = (DecFieldMetaData) fieldMetaData;

                        proRsMetaData.setFieldMetaData(decFieldMetaData.getId(), decFieldMetaData.getName(),
                                decFieldMetaData.getExtent(), Parameter.PRO_DECIMAL);
                    } else if (fieldMetaData instanceof IntFieldMetaData) {
                        final IntFieldMetaData intFieldMetaData = (IntFieldMetaData) fieldMetaData;

                        proRsMetaData.setFieldMetaData(intFieldMetaData.getId(), intFieldMetaData.getName(),
                                intFieldMetaData.getExtent(), Parameter.PRO_INTEGER);
                    } else if (fieldMetaData instanceof LogFieldMetaData) {
                        final LogFieldMetaData logFieldMetaData = (LogFieldMetaData) fieldMetaData;

                        proRsMetaData.setFieldMetaData(logFieldMetaData.getId(), logFieldMetaData.getName(),
                                logFieldMetaData.getExtent(), Parameter.PRO_LOGICAL);
                    }

                }

                if (((ParamMode.INPUT == mode) || (ParamMode.INPUT_OUTPUT == mode))
                        && (!reqParamElement.isNil()))
                    proParams.addTable(id, new OpenEdgeResultSet(rsParam.getRowList().iterator()), mode.value(),
                            proRsMetaData);
                else
                    proParams.addTable(id, null, mode.value(), proRsMetaData);

            }

        }

        LOG.info("Connecting to the AppServer");

        if (SESSION_MODEL_MANAGED == sessionModel)
            RunTimeProperties.setSessionModel(0);
        else if (SESSION_MODEL_FREE == sessionModel)
            RunTimeProperties.setSessionModel(1);

        final OpenAppObject proAppObject = new OpenAppObject(url, user, password, null, null);

        proAppObject.runProc(req.getProgram(), proParams);

        LOG.info("Marshalling the response");

        final Response res = OBJECT_FACTORY.createResponse();

        res.setResult(proParams.getProcReturnString());

        LOG.info("Setting the output params");

        for (final JAXBElement<? extends Serializable> reqParamElement : reqParamElementList) {
            final Serializable reqParam = reqParamElement.getValue();

            if (reqParam instanceof CharArrayParam) {
                final CharArrayParam reqCharArrayParam = (CharArrayParam) reqParam;

                if (ParamMode.INPUT != reqCharArrayParam.getMode()) {
                    final JAXBElement<CharArrayParam> resParamElement = new JAXBElement<CharArrayParam>(
                            new QName(NS, "CharArray"), CharArrayParam.class, null);

                    final CharArrayParam resParam = OBJECT_FACTORY.createCharArrayParam();

                    resParam.setId(reqCharArrayParam.getId());

                    resParam.setName(reqCharArrayParam.getName());

                    final String[] proParam = (String[]) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        for (int i = 0; i < proParam.length; i++) {
                            final JAXBElement<String> valueElement = new JAXBElement<String>(
                                    new QName(NS, "Value"), String.class, null);

                            if (proParam[i] != null)
                                valueElement.setValue(DatatypeConverter.printString(proParam[i]));
                            else
                                valueElement.setNil(true);

                            resParam.getValueElementList().add(valueElement);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof CharParam) {
                final CharParam reqCharParam = (CharParam) reqParam;

                if (ParamMode.INPUT != reqCharParam.getMode()) {
                    final JAXBElement<CharParam> resParamElement = new JAXBElement<CharParam>(
                            new QName(NS, "Char"), CharParam.class, null);

                    final CharParam resParam = OBJECT_FACTORY.createCharParam();

                    resParam.setId(reqCharParam.getId());

                    resParam.setName(reqCharParam.getName());

                    final String proParam = (String) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {
                        resParam.setContent(DatatypeConverter.printString(proParam));

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DateArrayParam) {
                final DateArrayParam reqDateArrayParam = (DateArrayParam) reqParam;

                if (ParamMode.INPUT != reqDateArrayParam.getMode()) {
                    final JAXBElement<DateArrayParam> resParamElement = new JAXBElement<DateArrayParam>(
                            new QName(NS, "DateArray"), DateArrayParam.class, null);

                    final DateArrayParam resParam = OBJECT_FACTORY.createDateArrayParam();

                    resParam.setId(reqDateArrayParam.getId());

                    resParam.setName(reqDateArrayParam.getName());

                    final Date[] proParam = (Date[]) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        for (int i = 0; i < proParam.length; i++) {
                            final JAXBElement<String> valueElement = new JAXBElement<String>(
                                    new QName(NS, "Value"), String.class, null);

                            if (proParam[i] != null) {
                                final Calendar cal = Calendar.getInstance();

                                cal.setTime(proParam[i]);

                                valueElement.setValue(DatatypeConverter.printDate(cal));
                            } else {
                                valueElement.setNil(true);
                            }

                            resParam.getValueElementList().add(valueElement);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DateParam) {
                final DateParam reqDateParam = (DateParam) reqParam;

                if (ParamMode.INPUT != reqDateParam.getMode()) {
                    final JAXBElement<DateParam> resParamElement = new JAXBElement<DateParam>(
                            new QName(NS, "Date"), DateParam.class, null);

                    final DateParam resParam = OBJECT_FACTORY.createDateParam();

                    resParam.setId(reqDateParam.getId());

                    resParam.setName(reqDateParam.getName());

                    final Date proParam = (Date) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {
                        final Calendar cal = Calendar.getInstance();

                        cal.setTime(proParam);

                        resParam.setContent(DatatypeConverter.printDate(cal));

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DateTimeArrayParam) {
                final DateTimeArrayParam reqDateTimeArrayParam = (DateTimeArrayParam) reqParam;

                if (ParamMode.INPUT != reqDateTimeArrayParam.getMode()) {
                    final JAXBElement<DateTimeArrayParam> resParamElement = new JAXBElement<DateTimeArrayParam>(
                            new QName(NS, "DateTimeArray"), DateTimeArrayParam.class, null);

                    final DateTimeArrayParam resParam = OBJECT_FACTORY.createDateTimeArrayParam();

                    resParam.setId(reqDateTimeArrayParam.getId());

                    resParam.setName(reqDateTimeArrayParam.getName());

                    final GregorianCalendar[] proParam = (GregorianCalendar[]) proParams
                            .getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        for (int i = 0; i < proParam.length; i++) {
                            final JAXBElement<String> valueElement = new JAXBElement<String>(
                                    new QName(NS, "Value"), String.class, null);

                            if (proParam[i] != null)
                                valueElement.setValue(DatatypeConverter.printDateTime(proParam[i]));
                            else
                                valueElement.setNil(true);

                            resParam.getValueElementList().add(valueElement);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DateTimeParam) {
                final DateTimeParam reqDateTimeParam = (DateTimeParam) reqParam;

                if (ParamMode.INPUT != reqDateTimeParam.getMode()) {
                    final JAXBElement<DateTimeParam> resParamElement = new JAXBElement<DateTimeParam>(
                            new QName(NS, "DateTime"), DateTimeParam.class, null);

                    final DateTimeParam resParam = OBJECT_FACTORY.createDateTimeParam();

                    resParam.setId(reqDateTimeParam.getId());

                    resParam.setName(reqDateTimeParam.getName());

                    final GregorianCalendar proParam = (GregorianCalendar) proParams
                            .getOutputParameter(resParam.getId());

                    if (proParam != null) {
                        resParam.setContent(DatatypeConverter.printDateTime(proParam));

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DateTimeTZArrayParam) {
                final DateTimeTZArrayParam reqDateTimeTZArrayParam = (DateTimeTZArrayParam) reqParam;

                if (ParamMode.INPUT != reqDateTimeTZArrayParam.getMode()) {
                    final JAXBElement<DateTimeTZArrayParam> resParamElement = new JAXBElement<DateTimeTZArrayParam>(
                            new QName(NS, "DateTimeTZArray"), DateTimeTZArrayParam.class, null);

                    final DateTimeTZArrayParam resParam = OBJECT_FACTORY.createDateTimeTZArrayParam();

                    resParam.setId(reqDateTimeTZArrayParam.getId());

                    resParam.setName(reqDateTimeTZArrayParam.getName());

                    final GregorianCalendar[] proParam = (GregorianCalendar[]) proParams
                            .getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        for (int i = 0; i < proParam.length; i++) {
                            final JAXBElement<String> valueElement = new JAXBElement<String>(
                                    new QName(NS, "Value"), String.class, null);

                            if (proParam[i] != null)
                                valueElement.setValue(DatatypeConverter.printDateTime(proParam[i]));
                            else
                                valueElement.setNil(true);

                            resParam.getValueElementList().add(valueElement);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DateTimeTZParam) {
                final DateTimeTZParam reqDateTimeTZParam = (DateTimeTZParam) reqParam;

                if (ParamMode.INPUT != reqDateTimeTZParam.getMode()) {
                    final JAXBElement<DateTimeTZParam> resParamElement = new JAXBElement<DateTimeTZParam>(
                            new QName(NS, "DateTimeTZ"), DateTimeTZParam.class, null);

                    final DateTimeTZParam resParam = OBJECT_FACTORY.createDateTimeTZParam();

                    resParam.setId(reqDateTimeTZParam.getId());

                    resParam.setName(reqDateTimeTZParam.getName());

                    final GregorianCalendar proParam = (GregorianCalendar) proParams
                            .getOutputParameter(resParam.getId());

                    if (proParam != null) {
                        resParam.setContent(DatatypeConverter.printDateTime(proParam));

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DecArrayParam) {
                final DecArrayParam reqDecArrayParam = (DecArrayParam) reqParam;

                if (ParamMode.INPUT != reqDecArrayParam.getMode()) {
                    final JAXBElement<DecArrayParam> resParamElement = new JAXBElement<DecArrayParam>(
                            new QName(NS, "DecArray"), DecArrayParam.class, null);

                    final DecArrayParam resParam = OBJECT_FACTORY.createDecArrayParam();

                    resParam.setId(reqDecArrayParam.getId());

                    resParam.setName(reqDecArrayParam.getName());

                    final BigDecimal[] proParam = (BigDecimal[]) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        for (int i = 0; i < proParam.length; i++) {
                            final JAXBElement<String> valueElement = new JAXBElement<String>(
                                    new QName(NS, "Value"), String.class, null);

                            if (proParam[i] != null)
                                valueElement.setValue(DatatypeConverter.printDecimal(proParam[i]));
                            else
                                valueElement.setNil(true);

                            resParam.getValueElementList().add(valueElement);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof DecParam) {
                final DecParam reqDecParam = (DecParam) reqParam;

                if (ParamMode.INPUT != reqDecParam.getMode()) {
                    final JAXBElement<DecParam> resParamElement = new JAXBElement<DecParam>(
                            new QName(NS, "Dec"), DecParam.class, null);

                    final DecParam resParam = OBJECT_FACTORY.createDecParam();

                    resParam.setId(reqDecParam.getId());

                    resParam.setName(reqDecParam.getName());

                    final BigDecimal proParam = (BigDecimal) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {
                        resParam.setContent(DatatypeConverter.printDecimal(proParam));

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof IntArrayParam) {
                final IntArrayParam reqIntArrayParam = (IntArrayParam) reqParam;

                if (ParamMode.INPUT != reqIntArrayParam.getMode()) {
                    final JAXBElement<IntArrayParam> resParamElement = new JAXBElement<IntArrayParam>(
                            new QName(NS, "IntArray"), IntArrayParam.class, null);

                    final IntArrayParam resParam = OBJECT_FACTORY.createIntArrayParam();

                    resParam.setId(reqIntArrayParam.getId());

                    resParam.setName(reqIntArrayParam.getName());

                    final Integer[] proParam = (Integer[]) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        for (int i = 0; i < proParam.length; i++) {
                            final JAXBElement<String> valueElement = new JAXBElement<String>(
                                    new QName(NS, "Value"), String.class, null);

                            if (proParam[i] != null)
                                valueElement.setValue(DatatypeConverter.printInt(proParam[i]));
                            else
                                valueElement.setNil(true);

                            resParam.getValueElementList().add(valueElement);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof IntParam) {
                final IntParam reqIntParam = (IntParam) reqParam;

                if (ParamMode.INPUT != reqIntParam.getMode()) {
                    final JAXBElement<IntParam> resParamElement = new JAXBElement<IntParam>(
                            new QName(NS, "Int"), IntParam.class, null);

                    final IntParam resParam = OBJECT_FACTORY.createIntParam();

                    resParam.setId(reqIntParam.getId());

                    resParam.setName(reqIntParam.getName());

                    final Integer proParam = (Integer) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {
                        resParam.setContent(DatatypeConverter.printInt(proParam));

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof LogArrayParam) {
                final LogArrayParam reqLogArrayParam = (LogArrayParam) reqParam;

                if (ParamMode.INPUT != reqLogArrayParam.getMode()) {
                    final JAXBElement<LogArrayParam> resParamElement = new JAXBElement<LogArrayParam>(
                            new QName(NS, "LogArray"), LogArrayParam.class, null);

                    final LogArrayParam resParam = OBJECT_FACTORY.createLogArrayParam();

                    resParam.setId(reqLogArrayParam.getId());

                    resParam.setName(reqLogArrayParam.getName());

                    final Boolean[] proParam = (Boolean[]) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        for (int i = 0; i < proParam.length; i++) {
                            final JAXBElement<String> valueElement = new JAXBElement<String>(
                                    new QName(NS, "Value"), String.class, null);

                            if (proParam[i] != null)
                                valueElement.setValue(DatatypeConverter.printBoolean(proParam[i]));
                            else
                                valueElement.setNil(true);

                            resParam.getValueElementList().add(valueElement);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof LogParam) {
                final LogParam reqLogParam = (LogParam) reqParam;

                if (ParamMode.INPUT != reqLogParam.getMode()) {
                    final JAXBElement<LogParam> resParamElement = new JAXBElement<LogParam>(
                            new QName(NS, "Log"), LogParam.class, null);

                    final LogParam resParam = OBJECT_FACTORY.createLogParam();

                    resParam.setId(reqLogParam.getId());

                    resParam.setName(reqLogParam.getName());

                    final Boolean proParam = (Boolean) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {
                        resParam.setContent(DatatypeConverter.printBoolean(proParam));

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            } else if (reqParam instanceof ResultSetParam) {
                final ResultSetParam reqResultSetParam = (ResultSetParam) reqParam;

                if (ParamMode.INPUT != reqResultSetParam.getMode()) {
                    final JAXBElement<ResultSetParam> resParamElement = new JAXBElement<ResultSetParam>(
                            new QName(NS, "ResultSet"), ResultSetParam.class, null);

                    final ResultSetParam resParam = OBJECT_FACTORY.createResultSetParam();

                    resParam.setId(reqResultSetParam.getId());

                    resParam.setName(reqResultSetParam.getName());

                    final ProResultSet proParam = (ProResultSet) proParams.getOutputParameter(resParam.getId());

                    if (proParam != null) {

                        while (proParam.next()) {
                            final Row row = OBJECT_FACTORY.createRow();

                            final ResultSetMetaData rsMetaData = reqResultSetParam.getResultSetMetaData();

                            for (final Serializable fieldMetaData : rsMetaData.getFieldMetaDataList()) {

                                if (fieldMetaData instanceof CharFieldMetaData) {
                                    final CharFieldMetaData charFieldMetaData = (CharFieldMetaData) fieldMetaData;

                                    final int extent = charFieldMetaData.getExtent();

                                    if (extent < 1) {
                                        final JAXBElement<CharField> fieldElement = new JAXBElement<CharField>(
                                                new QName(NS, "Char"), CharField.class, null);

                                        final CharField field = OBJECT_FACTORY.createCharField();

                                        field.setId(charFieldMetaData.getId());

                                        field.setName(charFieldMetaData.getName());

                                        final String value = proParam.getString(field.getId());

                                        if (value != null) {
                                            field.setContent(DatatypeConverter.printString(value));

                                            fieldElement.setValue(field);
                                        } else {
                                            fieldElement.setNil(true);
                                        }

                                        row.getFieldElementList().add(fieldElement);
                                    } else {

                                        for (int i = 1; i <= extent; i++) {
                                            final JAXBElement<CharField> fieldElement = new JAXBElement<CharField>(
                                                    new QName(NS, "Char"), CharField.class, null);

                                            final CharField field = OBJECT_FACTORY.createCharField();

                                            field.setId(charFieldMetaData.getId());

                                            field.setName(charFieldMetaData.getName());

                                            final String value = proParam.getString(field.getId(), i);

                                            if (value != null) {
                                                field.setContent(DatatypeConverter.printString(value));

                                                fieldElement.setValue(field);
                                            } else {
                                                fieldElement.setNil(true);
                                            }

                                            row.getFieldElementList().add(fieldElement);
                                        }

                                    }

                                } else if (fieldMetaData instanceof DateFieldMetaData) {
                                    final DateFieldMetaData dateFieldMetaData = (DateFieldMetaData) fieldMetaData;

                                    final int extent = dateFieldMetaData.getExtent();

                                    if (extent < 1) {
                                        final JAXBElement<DateField> fieldElement = new JAXBElement<DateField>(
                                                new QName(NS, "Date"), DateField.class, null);

                                        final DateField field = OBJECT_FACTORY.createDateField();

                                        field.setId(dateFieldMetaData.getId());

                                        field.setName(dateFieldMetaData.getName());

                                        final Date value = proParam.getDate(field.getId());

                                        if (value != null) {
                                            final Calendar cal = Calendar.getInstance();

                                            cal.setTime(value);

                                            field.setContent(DatatypeConverter.printDate(cal));

                                            fieldElement.setValue(field);
                                        } else {
                                            fieldElement.setNil(true);
                                        }

                                        row.getFieldElementList().add(fieldElement);
                                    } else {

                                        for (int i = 1; i <= extent; i++) {
                                            final JAXBElement<DateField> fieldElement = new JAXBElement<DateField>(
                                                    new QName(NS, "Date"), DateField.class, null);

                                            final DateField field = OBJECT_FACTORY.createDateField();

                                            field.setId(dateFieldMetaData.getId());

                                            field.setName(dateFieldMetaData.getName());

                                            final Date value = proParam.getDate(field.getId(), i);

                                            if (value != null) {
                                                final Calendar cal = Calendar.getInstance();

                                                cal.setTime(value);

                                                field.setContent(DatatypeConverter.printDate(cal));

                                                fieldElement.setValue(field);
                                            } else {
                                                fieldElement.setNil(true);
                                            }

                                            row.getFieldElementList().add(fieldElement);
                                        }

                                    }

                                } else if (fieldMetaData instanceof DateTimeFieldMetaData) {
                                    final DateTimeFieldMetaData dateTimeFieldMetaData = (DateTimeFieldMetaData) fieldMetaData;

                                    final int extent = dateTimeFieldMetaData.getExtent();

                                    if (extent < 1) {
                                        final JAXBElement<DateTimeField> fieldElement = new JAXBElement<DateTimeField>(
                                                new QName(NS, "DateTime"), DateTimeField.class, null);

                                        final DateTimeField field = OBJECT_FACTORY.createDateTimeField();

                                        field.setId(dateTimeFieldMetaData.getId());

                                        field.setName(dateTimeFieldMetaData.getName());

                                        final GregorianCalendar value = (GregorianCalendar) proParam
                                                .getObject(field.getId());

                                        if (value != null) {
                                            field.setContent(DatatypeConverter.printDateTime(value));

                                            fieldElement.setValue(field);
                                        } else {
                                            fieldElement.setNil(true);
                                        }

                                        row.getFieldElementList().add(fieldElement);
                                    } else {

                                        for (int i = 1; i <= extent; i++) {
                                            final JAXBElement<DateTimeField> fieldElement = new JAXBElement<DateTimeField>(
                                                    new QName(NS, "DateTime"), DateTimeField.class, null);

                                            final DateTimeField field = OBJECT_FACTORY.createDateTimeField();

                                            field.setId(dateTimeFieldMetaData.getId());

                                            field.setName(dateTimeFieldMetaData.getName());

                                            final GregorianCalendar value = (GregorianCalendar) proParam
                                                    .getObject(field.getId(), i);

                                            if (value != null) {
                                                field.setContent(DatatypeConverter.printDateTime(value));

                                                fieldElement.setValue(field);
                                            } else {
                                                fieldElement.setNil(true);
                                            }

                                            row.getFieldElementList().add(fieldElement);
                                        }

                                    }

                                } else if (fieldMetaData instanceof DateTimeTZFieldMetaData) {
                                    final DateTimeTZFieldMetaData dateTimeTZFieldMetaData = (DateTimeTZFieldMetaData) fieldMetaData;

                                    final int extent = dateTimeTZFieldMetaData.getExtent();

                                    if (extent < 1) {
                                        final JAXBElement<DateTimeTZField> fieldElement = new JAXBElement<DateTimeTZField>(
                                                new QName(NS, "DateTimeTZ"), DateTimeTZField.class, null);

                                        final DateTimeTZField field = OBJECT_FACTORY.createDateTimeTZField();

                                        field.setId(dateTimeTZFieldMetaData.getId());

                                        field.setName(dateTimeTZFieldMetaData.getName());

                                        final GregorianCalendar value = (GregorianCalendar) proParam
                                                .getObject(field.getId());

                                        if (value != null) {
                                            field.setContent(DatatypeConverter.printDateTime(value));

                                            fieldElement.setValue(field);
                                        } else {
                                            fieldElement.setNil(true);
                                        }

                                        row.getFieldElementList().add(fieldElement);
                                    } else {

                                        for (int i = 1; i <= extent; i++) {
                                            final JAXBElement<DateTimeTZField> fieldElement = new JAXBElement<DateTimeTZField>(
                                                    new QName(NS, "DateTimeTZ"), DateTimeTZField.class, null);

                                            final DateTimeTZField field = OBJECT_FACTORY
                                                    .createDateTimeTZField();

                                            field.setId(dateTimeTZFieldMetaData.getId());

                                            field.setName(dateTimeTZFieldMetaData.getName());

                                            final GregorianCalendar value = (GregorianCalendar) proParam
                                                    .getObject(field.getId(), i);

                                            if (value != null) {
                                                field.setContent(DatatypeConverter.printDateTime(value));

                                                fieldElement.setValue(field);
                                            } else {
                                                fieldElement.setNil(true);
                                            }

                                            row.getFieldElementList().add(fieldElement);
                                        }

                                    }

                                } else if (fieldMetaData instanceof DecFieldMetaData) {
                                    final DecFieldMetaData decFieldMetaData = (DecFieldMetaData) fieldMetaData;

                                    final int extent = decFieldMetaData.getExtent();

                                    if (extent < 1) {
                                        final JAXBElement<DecField> fieldElement = new JAXBElement<DecField>(
                                                new QName(NS, "Dec"), DecField.class, null);

                                        final DecField field = OBJECT_FACTORY.createDecField();

                                        field.setId(decFieldMetaData.getId());

                                        field.setName(decFieldMetaData.getName());

                                        final BigDecimal value = proParam.getBigDecimal(field.getId());

                                        if (value != null) {
                                            field.setContent(DatatypeConverter.printDecimal(value));

                                            fieldElement.setValue(field);
                                        } else {
                                            fieldElement.setNil(true);
                                        }

                                        row.getFieldElementList().add(fieldElement);
                                    } else {

                                        for (int i = 1; i <= extent; i++) {
                                            final JAXBElement<DecField> fieldElement = new JAXBElement<DecField>(
                                                    new QName(NS, "Dec"), DecField.class, null);

                                            final DecField field = OBJECT_FACTORY.createDecField();

                                            field.setId(decFieldMetaData.getId());

                                            field.setName(decFieldMetaData.getName());

                                            final BigDecimal value = proParam.getBigDecimal(field.getId(), i,
                                                    0);

                                            if (value != null) {
                                                field.setContent(DatatypeConverter.printDecimal(value));

                                                fieldElement.setValue(field);
                                            } else {
                                                fieldElement.setNil(true);
                                            }

                                            row.getFieldElementList().add(fieldElement);
                                        }

                                    }

                                } else if (fieldMetaData instanceof IntFieldMetaData) {
                                    final IntFieldMetaData intFieldMetaData = (IntFieldMetaData) fieldMetaData;

                                    final int extent = intFieldMetaData.getExtent();

                                    if (extent < 1) {
                                        final JAXBElement<IntField> fieldElement = new JAXBElement<IntField>(
                                                new QName(NS, "Int"), IntField.class, null);

                                        final IntField field = OBJECT_FACTORY.createIntField();

                                        field.setId(intFieldMetaData.getId());

                                        field.setName(intFieldMetaData.getName());

                                        final String value = proParam.getString(field.getId());

                                        if (value != null) {
                                            field.setContent(
                                                    DatatypeConverter.printInt(Integer.parseInt(value)));

                                            fieldElement.setValue(field);
                                        } else {
                                            fieldElement.setNil(true);
                                        }

                                        row.getFieldElementList().add(fieldElement);
                                    } else {

                                        for (int i = 1; i <= extent; i++) {
                                            final JAXBElement<IntField> fieldElement = new JAXBElement<IntField>(
                                                    new QName(NS, "Int"), IntField.class, null);

                                            final IntField field = OBJECT_FACTORY.createIntField();

                                            field.setId(intFieldMetaData.getId());

                                            field.setName(intFieldMetaData.getName());

                                            final String value = proParam.getString(field.getId(), i);

                                            if (value != null) {
                                                field.setContent(
                                                        DatatypeConverter.printInt(Integer.parseInt(value)));

                                                fieldElement.setValue(field);
                                            } else {
                                                fieldElement.setNil(true);
                                            }

                                            row.getFieldElementList().add(fieldElement);
                                        }

                                    }

                                } else if (fieldMetaData instanceof LogFieldMetaData) {
                                    final LogFieldMetaData logFieldMetaData = (LogFieldMetaData) fieldMetaData;

                                    final int extent = logFieldMetaData.getExtent();

                                    if (extent < 1) {
                                        final JAXBElement<LogField> fieldElement = new JAXBElement<LogField>(
                                                new QName(NS, "Log"), LogField.class, null);

                                        final LogField field = OBJECT_FACTORY.createLogField();

                                        field.setId(logFieldMetaData.getId());

                                        field.setName(logFieldMetaData.getName());

                                        final String value = proParam.getString(field.getId());

                                        if (value != null) {
                                            field.setContent(
                                                    DatatypeConverter.printBoolean(Boolean.valueOf(value)));

                                            fieldElement.setValue(field);
                                        } else {
                                            fieldElement.setNil(true);
                                        }

                                        row.getFieldElementList().add(fieldElement);
                                    } else {

                                        for (int i = 1; i <= extent; i++) {
                                            final JAXBElement<LogField> fieldElement = new JAXBElement<LogField>(
                                                    new QName(NS, "Log"), LogField.class, null);

                                            final LogField field = OBJECT_FACTORY.createLogField();

                                            field.setId(logFieldMetaData.getId());

                                            field.setName(logFieldMetaData.getName());

                                            final String value = proParam.getString(field.getId(), i);

                                            if (value != null) {
                                                field.setContent(
                                                        DatatypeConverter.printBoolean(Boolean.valueOf(value)));

                                                fieldElement.setValue(field);
                                            } else {
                                                fieldElement.setNil(true);
                                            }

                                            row.getFieldElementList().add(fieldElement);
                                        }

                                    }

                                }

                            }

                            resParam.getRowList().add(row);
                        }

                        resParamElement.setValue(resParam);
                    } else {
                        resParamElement.setNil(true);
                    }

                    res.getParamElementList().add(resParamElement);
                }

            }

        }

        final Document doc = builder.newDocument();

        marshaller.marshal(res, doc);

        exchange.getOut().setBody(doc);
    } catch (final RunTime4GLErrorException e) {
        LOG.error(e.getProcReturnString(), e);

        throw new OpenEdgeException(e.getProcReturnString(), e);
    }

}

From source file:org.openestate.io.casa_it.CasaItUtils.java

public static BigDecimal parseDouble(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}

From source file:org.openestate.io.daft_ie.DaftIeUtils.java

public static BigDecimal parsePositiveDecimal(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}

From source file:org.openestate.io.immobiliare_it.ImmobiliareItUtils.java

public static BigDecimal parseLatitude(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}

From source file:org.openestate.io.immobiliare_it.ImmobiliareItUtils.java

public static BigDecimal parseLongitude(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}

From source file:org.openestate.io.immoxml.ImmoXmlUtils.java

public static BigDecimal parseDecimal(String value) {
    value = StringUtils.trimToNull(value);
    if (value == null)
        return null;
    try {//www  . ja v  a  2 s . com
        return DatatypeConverter.parseDecimal(value);
    } catch (NumberFormatException ex) {
        //LOGGER.warn( "Can't parse value '" + value + "' as decimal!" );
        //LOGGER.warn( "> " + ex.getLocalizedMessage(), ex );
    }
    try {
        return BigDecimal.valueOf(NumberUtils.parseNumber(value, Locale.GERMANY).doubleValue());
    } catch (NumberFormatException ex) {
        //LOGGER.warn( "Can't parse value '" + value + "' as decimal!" );
        //LOGGER.warn( "> " + ex.getLocalizedMessage(), ex );
    }
    throw new IllegalArgumentException("Can't parse decimal value '" + value + "'!");
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static BigDecimal parsePreisAufAnfrage(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static BigDecimal parseZahl31(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}

From source file:org.openestate.io.is24_xml.Is24XmlUtils.java

public static BigDecimal parseZahl32(String value) {
    value = StringUtils.trimToNull(value);
    return (value != null) ? DatatypeConverter.parseDecimal(value) : null;
}