Я пытаюсь внести некоторые изменения в программу на работе, которая довольно сложна. Эта программа использует JAXB и имеет множество различных классов и функций. В основе этого лежит задача разрешить пользователю создавать XML-файл, который представляет собой транзакцию на основе карты. Сейчас пользователь имеет возможность вводить сумму, которая затем помещается в окончательный XML. Мне нужно расширить это, предоставив пользователю возможность разделить транзакцию на несколько частей. Это означает, что мне нужно изменить поле суммы. К сожалению, для меня, как автор разработал поле количества, немного запутанно, поэтому я надеюсь, что кто-то может пролить свет. Есть тонны кода, и я не могу вставить его все, но я сделаю все возможное, чтобы показать проблему.Переменная литья в bigDecimal
Основной раздел кода я работаю так:
while(allocationCounter>0){
StructuredRemittanceInformation9 Strd = objectFactory
.createStructuredRemittanceInformation9(); // create Strd
ReferredDocumentInformation3 RfrdDocInf = objectFactory
.createReferredDocumentInformation3(); // create RfrdDocInf
ReferredDocumentType2 tpdoc = objectFactory
.createReferredDocumentType2(); // create tp
ReferredDocumentType1Choice cdOrPrtry = objectFactory
.createReferredDocumentType1Choice(); // create CdOrPrtry
cdOrPrtry.setCd(DocumentType5Code.SOAC);
tpdoc.setCdOrPrtry(cdOrPrtry); // set CdorPrtry
RfrdDocInf.setTp(tpdoc); // set Tp
RfrdDocInf.setNb("0001");
Strd.getRfrdDocInf().add(RfrdDocInf); // set RfrdDocInf
RemittanceAmount2 RfrdDocAmt = objectFactory.createRemittanceAmount2(); // create
// RfrdDocAmt
DocumentAdjustment1 adjstmntAmt = objectFactory
.createDocumentAdjustment1(); // create AdjstmntAmtAndRsn
ActiveOrHistoricCurrencyAndAmount adjAmt = objectFactory
.createActiveOrHistoricCurrencyAndAmount(); // create Amt
adjAmt.setCcy("USD");
adjAmt.setValue((BigDecimal) transInfo.get("amount"));
adjstmntAmt.setAmt(adjAmt); // set Amt
adjstmntAmt.setCdtDbtInd(CreditDebitCode.DBIT); // set CdtDbtInd
adjstmntAmt.setAddtlInf(transInfo.get("dbtrName").toString()); // set
// AddtlInf
RfrdDocAmt.getAdjstmntAmtAndRsn().add(adjstmntAmt); // set
// AdjstmntAmtAndRsn
Strd.setRfrdDocAmt(RfrdDocAmt); // set RfrdDocAmt
CreditorReferenceInformation2 cdtrRefInf = objectFactory
.createCreditorReferenceInformation2(); // create CdtrRefInf
CreditorReferenceType2 cdtrTp = objectFactory
.createCreditorReferenceType2(); // create Tp
CreditorReferenceType1Choice CdorPrtryTp = objectFactory
.createCreditorReferenceType1Choice(); // create cdPrtry
CdorPrtryTp.setPrtry("BNR");
cdtrTp.setCdOrPrtry(CdorPrtryTp);// set CdPrtry
cdtrRefInf.setTp(cdtrTp); // set Tp
cdtrRefInf.setRef(transInfo.get("referenceNumber").toString());
Strd.setCdtrRefInf(cdtrRefInf);// set CdtrRefInf
rmtInf.getStrd().add(Strd); // set strd
System.out.println("TEST PASSED");
allocationCounter--;
}
В частности, эта строка кода
adjstmntAmt.setAmt(adjAmt); // set Amt
То есть то, что отличает сумму, и это то, что мне нужно изменить. Эта сумма ссылка обратно через несколько классов, но начинается здесь:
transactionInfo.put("amount", amount);
В этом классе пользователь помещает количество в текстовом поле и затем сохраняется adjstmntAmt (adjAmt) я разместил выше упоминаются в другом классе: в hash транзакции и вызывается позже.
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2015.07.01 at 10:11:45 AM EDT
//
package jaxBClasses;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
/**
* <p>Java class for ActiveOrHistoricCurrencyAndAmount complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="ActiveOrHistoricCurrencyAndAmount">
* <simpleContent>
* <extension base="<urn:iso:std:iso:20022:tech:xsd:pain.008.001.04>ActiveOrHistoricCurrencyAndAmount_SimpleType">
* <attribute name="Ccy" use="required" type="{urn:iso:std:iso:20022:tech:xsd:pain.008.001.04}ActiveOrHistoricCurrencyCode" />
* </extension>
* </simpleContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ActiveOrHistoricCurrencyAndAmount", propOrder = {
"value"
})
public class ActiveOrHistoricCurrencyAndAmount {
@XmlValue
protected BigDecimal value;
@XmlAttribute(name = "Ccy", required = true)
protected String ccy;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link BigDecimal }
*
*/
public BigDecimal getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link BigDecimal }
*
*/
public void setValue(BigDecimal value) {
this.value = value;
}
/**
* Gets the value of the ccy property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCcy() {
return ccy;
}
/**
* Sets the value of the ccy property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCcy(String value) {
this.ccy = value;
}
}
и он также появляется в этом классе:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2015.07.01 at 10:11:45 AM EDT
//
package jaxBClasses;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for DocumentAdjustment1 complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="DocumentAdjustment1">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="Amt" type="{urn:iso:std:iso:20022:tech:xsd:pain.008.001.04}ActiveOrHistoricCurrencyAndAmount"/>
* <element name="CdtDbtInd" type="{urn:iso:std:iso:20022:tech:xsd:pain.008.001.04}CreditDebitCode" minOccurs="0"/>
* <element name="Rsn" type="{urn:iso:std:iso:20022:tech:xsd:pain.008.001.04}Max4Text" minOccurs="0"/>
* <element name="AddtlInf" type="{urn:iso:std:iso:20022:tech:xsd:pain.008.001.04}Max140Text" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DocumentAdjustment1", propOrder = {
"amt",
"cdtDbtInd",
"rsn",
"addtlInf"
})
public class DocumentAdjustment1 {
@XmlElement(name = "Amt", required = true)
protected ActiveOrHistoricCurrencyAndAmount amt;
@XmlElement(name = "CdtDbtInd")
protected CreditDebitCode cdtDbtInd;
@XmlElement(name = "Rsn")
protected String rsn;
@XmlElement(name = "AddtlInf")
protected String addtlInf;
/**
* Gets the value of the amt property.
*
* @return
* possible object is
* {@link ActiveOrHistoricCurrencyAndAmount }
*
*/
public ActiveOrHistoricCurrencyAndAmount getAmt() {
return amt;
}
/**
* Sets the value of the amt property.
*
* @param value
* allowed object is
* {@link ActiveOrHistoricCurrencyAndAmount }
*
*/
public void setAmt(ActiveOrHistoricCurrencyAndAmount value) {
this.amt = value;
}
/**
* Gets the value of the cdtDbtInd property.
*
* @return
* possible object is
* {@link CreditDebitCode }
*
*/
public CreditDebitCode getCdtDbtInd() {
return cdtDbtInd;
}
/**
* Sets the value of the cdtDbtInd property.
*
* @param value
* allowed object is
* {@link CreditDebitCode }
*
*/
public void setCdtDbtInd(CreditDebitCode value) {
this.cdtDbtInd = value;
}
/**
* Gets the value of the rsn property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getRsn() {
return rsn;
}
/**
* Sets the value of the rsn property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setRsn(String value) {
this.rsn = value;
}
/**
* Gets the value of the addtlInf property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getAddtlInf() {
return addtlInf;
}
/**
* Sets the value of the addtlInf property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setAddtlInf(String value) {
this.addtlInf = value;
}
}
Так что мой вопрос просто: Что мне нужно сделать, чтобы сделать это так, что я могу поставить любую переменную в этой строке кода, гласит:
adjstmntAmt.setAmt(adjAmt); // set Amt
Я попытался заменить adjAmt с моей собственной переменной, но я получаю сообщение об ошибке: тип должен быть ActiveOrHistoricCurrencyAndAmount ..
Любая помощь очень ценится!