Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help with Castor Mapping

 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following codes, could anyone tell me what's wrong with my code:

<mapping>
<class name="com.desjardins.vmd.disnatv.hub.messages.MfGetOrderInfoRp" auto-complete="false">
<map-to xml="mf-get-order-info-rp" />

<field name="requestId" type="java.lang.String" direct="false">
<bind-xml name="request-id" location="request-id" node="element" />
</field>
<field name="result" type="java.lang.Boolean" direct="false">
<bind-xml name="result" location="result" node="element" />
</field>
<field name="errorCode" type="java.lang.String" direct="false">
<bind-xml name="error-code" location="error-code" node="element" />
</field>
<field name="errorMessage" type="java.lang.String" direct="false">
<bind-xml name="error-message" location="error-message" node="element" />
</field>
<field name="status" type="java.lang.String" direct="false">
<bind-xml name="status" location="status" node="element" />
</field>


<field name="contracts" direct="false"
type="com.desjardins.vmd.disnatv.hub.messages.Contract"
collection="arraylist">
<bind-xml name="contracts" />
</field>

</class>


<class name="com.desjardins.vmd.disnatv.hub.messages.Contract">



<field name="tradeDateGmt" type="java.util.Date" direct="false">
<bind-xml name="trade-date-gmt" location="contract/trade-date-gmt" node="element" />
</field>
<field name="settlementDateGmt" type="java.util.Date" direct="false">
<bind-xml name="settlement-date-gmt" location="contract/settlement-date-gmt" node="element" />
</field>
<field name="grossAmount" type="java.math.BigDecimal" direct="false">
<bind-xml name="gross-amount" location="contract/gross-amount" node="element" />
</field>
<field name="fees" type="java.math.BigDecimal" direct="false">
<bind-xml name="fees" location="contract/fees" node="element" />
</field>
<field name="commissions" type="java.math.BigDecimal" direct="false">
<bind-xml name="commissions" location="contract/commissions" node="element" />
</field>
<field name="noOfShares" type="java.lang.Long" direct="false">
<bind-xml name="no-of-shares" location="contract/no-of-shares" node="element" />
</field>
<field name="sharePrice" type="java.math.BigDecimal" direct="false">
<bind-xml name="share-price" location="contract/share-price" node="element" />
</field>
<field name="net" type="java.math.BigDecimal" direct="false">
<bind-xml name="net" location="contract/net" node="element" />
</field>
<field name="contractStatus" type="java.lang.String" direct="false">
<bind-xml name="contract-status" location="contract/contract-status" node="element" />
</field>
<field name="errorMsg" type="java.lang.String" direct="false">
<bind-xml name="error-msg" location="contract/error-msg" node="element" />
</field>

</class>


</mapping>
public class MfGetOrderInfoRp {
//member variables
protected String _status;
protected ArrayList _contracts;

//default constructor
public MfGetOrderInfoRp(){
super();
}

/**
* @return Contract contract
*/
public ArrayList getContracts()
{
return _contracts;
}

/**
* @return String status
*/
public String getStatus()
{
return _status;
}

/**
* @param Contract contracts
*/
public void setContracts(ArrayList contracts)
{
_contracts = contracts;
}

/**
* @param string status
*/
public void setStatus(String status)
{
_status = status;
}

}

public class Contract
{
//member variables
protected Date _tradeDateGmt;
protected Date _settlementDateGmt;
protected BigDecimal _grossAmount;
protected BigDecimal _fees;
protected BigDecimal _commissions;
protected Long _noOfShares;
protected BigDecimal _sharePrice;
protected BigDecimal _net;
protected String _contractStatus;
protected String _errorMsg;

protected Contract _contract;

public Contract()
{
super();
}

/**
* @return String Commissions
*/
public BigDecimal getCommissions()
{
return _commissions;
}

/**
* @return String Contract Status
*/
public String getContractStatus()
{
return _contractStatus;
}

/**
* @return
*/
public String getErrorMsg()
{
return _errorMsg;
}

/**
* @return BigDecimal fees
*/
public BigDecimal getFees()
{
return _fees;
}

/**
* @return BigDecimal Gross Ammount
*/
public BigDecimal getGrossAmount()
{
return _grossAmount;
}

/**
* @return BigDecimal Net
*/
public BigDecimal getNet()
{
return _net;
}

/**
* @return Long Number Of Shares
*/
public Long getNoOfShares()
{
return _noOfShares;
}

/**
* @return Date Settlement Date Mgt
*/
public Date getSettlementDateGmt()
{
return _settlementDateGmt;
}

/**
* @return BigDecimal Share Price
*/
public BigDecimal getSharePrice()
{
return _sharePrice;
}

/**
* @return Date Trade Date Mgt
*/
public Date getTradeDateGmt()
{
return _tradeDateGmt;
}

/**
* @param BigDecimal commissions
*/
public void setCommissions(BigDecimal commissions)
{
_commissions = commissions;
}

/**
* @param string contractStatus
*/
public void setContractStatus(String contractStatus)
{
_contractStatus = contractStatus;
}

/**
* @param string errorMsg
*/
public void setErrorMsg(String errorMsg)
{
_errorMsg = errorMsg;
}

/**
* @param BigDecimal fees
*/
public void setFees(BigDecimal fees)
{
_fees = fees;
}

/**
* @param BigDecimal grossAmount
*/
public void setGrossAmount(BigDecimal grossAmount)
{
_grossAmount = grossAmount;
}

/**
* @param BigDecimal net
*/
public void setNet(BigDecimal net)
{
_net = net;
}

/**
* @param Long noOfShares
*/
public void setNoOfShares(Long noOfShares)
{
_noOfShares = noOfShares;
}

/**
* @param Date
*/
public void setSettlementDateGmt(Date settlementDateGmt)
{
_settlementDateGmt = settlementDateGmt;
}

/**
* @param BigDecimal sharePrice
*/
public void setSharePrice(BigDecimal sharePrice)
{
_sharePrice = sharePrice;
}

/**
* @param Date tradeDateMgt
*/
public void setTradeDateGmt(Date tradeDateGmt)
{
_tradeDateGmt = tradeDateGmt;
}

/**
* @return
*/
public Contract getContract()
{
return _contract;
}

/**
* @param contract
*/
public void setContracts(Contract contract)
{
_contract = contract;
}

}
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this thread to the Object Relational Mapping forum. Please continue this discussion there. Thank you
 
Jez Nicholson
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmmm....bit of a long listing to debug without even an error message

I generally call the MappingTool to see what it creates as default then edit that file to give my mapping.


import org.exolab.castor.tools.MappingTool;
import java.io.*;

/**
* generate a Castor mapping file ready for editing
*/
public class CastorMapper {

/**
* generate a Castor mapping file ready for editing
*/
public CastorMapper()
{
try
{
MappingTool tool = new MappingTool();
tool.addClass(xxx.class);
tool.addClass(yyy.class);

OutputStream file = new FileOutputStream("gen_mapping.xml");
Writer writer = new OutputStreamWriter(file);

tool.write(writer);
}
catch (Exception ex)
{
ex.printStackTrace();
}

}

public static void main(String[] args)
{
new CastorMapper();
}
}
 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very cool! I don't use it because, I use java reflection. So my mapping is very short and clean. Nice feature anyways I was wondering if you can create Java Classes from an XML schemas.


Originally posted by Jeremy Nicholson:
hmmmm....bit of a long listing to debug without even an error message

I generally call the MappingTool to see what it creates as default then edit that file to give my mapping.


import org.exolab.castor.tools.MappingTool;
import java.io.*;

/**
* generate a Castor mapping file ready for editing
*/
public class CastorMapper {

/**
* generate a Castor mapping file ready for editing
*/
public CastorMapper()
{
try
{
MappingTool tool = new MappingTool();
tool.addClass(xxx.class);
tool.addClass(yyy.class);

OutputStream file = new FileOutputStream("gen_mapping.xml");
Writer writer = new OutputStreamWriter(file);

tool.write(writer);
}
catch (Exception ex)
{
ex.printStackTrace();
}

}

public static void main(String[] args)
{
new CastorMapper();
}
}
 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<class name="com.desjardins.vmd.disnatv.hub.messages.MfGetOrderInfoRp" auto-complete="true">
<map-to xml="mf-get-order-info-rp" />
<class>
 
Jez Nicholson
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That mean that you are not mapping it manually then....you know, you don't have to mention classes at all if you want to use the default Castor attempt. I only map classes where the default is not what I wanted, or I have a method that will cause Castor to go into a loop.

In answer to your Q about XMLSchemas, yes you can generate classes from XMLSchema. See http://www.castor.org/xmlschema.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic