Package com.wesabe.xmlson

Examples of com.wesabe.xmlson.XmlsonObject


    this.moneyPresenter = moneyPresenter;
    this.financialInstPresenter = financialInstPresenter;
  }

  public XmlsonObject present(Account account, Locale locale) {
    final XmlsonObject result = new XmlsonObject("account");
    result.addProperty("name", account.getName());
    result.addProperty("position", account.getPosition());
    // REVIEW coda@wesabe.com -- May 21, 2009: Replace account URI building once AccountResource is written
    result.addProperty("uri", String.format("/accounts/%d", account.getRelativeId()));
    result.addProperty("type", account.getAccountType().toString());
    result.addProperty("currency", account.getCurrency().getCurrencyCode());
    result.addProperty("status", account.getStatus().toString().toLowerCase(Locale.US));
    if (account.hasBalance()) {
      final Money balance = account.getBalance();
      result.add(moneyPresenter.present("balance", balance, locale));
      result.addProperty("last-balance-at", ISO_DATETIME.print(account.getLastActivityDate()));
    }
    FinancialInst financialInst = account.getFinancialInst();
    if (financialInst != null) {
      result.add(financialInstPresenter.present(financialInst));
    }
    return result;
  }
View Full Code Here


  public TagSummaryPresenter(SumOfMoneyPresenter moneyPresenter) {
    this.sumOfMoneyPresenter = moneyPresenter;
  }
 
  public XmlsonObject present(ImmutableMap<Tag, MonetarySummary> summaries, Locale locale) {
    final XmlsonObject root = new XmlsonObject("tag-summary");
    final XmlsonArray array = new XmlsonArray("summaries");
   
    for (Map.Entry<Tag, MonetarySummary> summary : summaries.entrySet()) {
      final XmlsonObject item = new XmlsonObject("summary");
     
      final XmlsonObject tag = new XmlsonObject("tag");
      tag.addProperty("name", summary.getKey().toString());
      item.add(tag);
      item.add(sumOfMoneyPresenter.present("spending", summary.getValue().getSpending(), locale));
      item.add(sumOfMoneyPresenter.present("earnings", summary.getValue().getEarnings(), locale));
      item.add(sumOfMoneyPresenter.present("net", summary.getValue().getNet(), locale));
     
View Full Code Here

  public NetWorthSummaryPresenter(MoneyPresenter moneyPresenter) {
    this.moneyPresenter = moneyPresenter;
  }
 
  public XmlsonObject present(ImmutableMap<Interval, Money> summaries, Locale locale) {
    final XmlsonObject root = new XmlsonObject("net-worth-summary");
    final XmlsonArray array = new XmlsonArray("summaries");
   
    for (Map.Entry<Interval, Money> summary : summaries.entrySet()) {
      final XmlsonObject item = new XmlsonObject("summary");
     
      final XmlsonObject interval = new XmlsonObject("interval");
      interval.addProperty("start", ISO_BASIC.print(summary.getKey().getStart()));
      interval.addProperty("end", ISO_BASIC.print(summary.getKey().getEnd()));
      item.add(interval);
      item.add(moneyPresenter.present("balance", summary.getValue(), locale));
     
      array.add(item);
    }
View Full Code Here

  public TaggedAmountPresenter(MoneyPresenter moneyPresenter) {
    this.moneyPresenter = moneyPresenter;
  }
 
  public XmlsonObject present(TaggedAmount taggedAmount, Locale locale) {
    final XmlsonObject root = new XmlsonObject("tag");
    root.addProperty("name", taggedAmount.getTag().toString());
    root.addProperty("uri", String.format("/tags/%s", taggedAmount.getTag()));
    if (taggedAmount.isSplit()) {
      root.add(moneyPresenter.present("amount", taggedAmount.getAmount(), locale));
    }
    return root;
  }
View Full Code Here

    this.moneyPresenter = moneyPresenter;
    this.investmentSecurityPresenter = investmentSecurityPresenter;
  }
 
  public XmlsonObject present(InvestmentPosition position, Locale locale) {
    final XmlsonObject root = new XmlsonObject("investment-position");
    if (position.getInvestmentSecurity() != null) {
      root.add(investmentSecurityPresenter.present(position.getInvestmentSecurity()));
    } else {
      root.addNullProperty("investment-security");
    }
    root.addProperty("units", position.getUnits());
    root.add(moneyPresenter.present("unit-price", position.getUnitPrice(), locale));
    root.add(moneyPresenter.present("market-value", position.getMarketValue(), locale));
    return root;
  }
View Full Code Here

* @author coda
*
*/
public class AttachmentPresenter {
  public XmlsonObject present(Attachment attachment) {
    final XmlsonObject root = new XmlsonObject("attachment");
    root.addProperty("guid", attachment.getGuid());
    root.addProperty("filename", attachment.getFilename());
    root.addProperty("content-type", attachment.getContentType());
    root.addProperty("size", attachment.getSize());
    root.addProperty("description", attachment.getDescription());
    return root;
  }
View Full Code Here

  public SumOfMoneyPresenter(MoneyPresenter moneyPresenter) {
    this.moneyPresenter = moneyPresenter;
  }
 
  public XmlsonObject present(String name, SumOfMoney sum, Locale locale) {
    final XmlsonObject root = moneyPresenter.present(name, sum.getAmount(), locale);
    root.addProperty("count", sum.getCount());
    return root;
  }
View Full Code Here

import com.wesabe.xmlson.XmlsonObject;

public class InvalidStateExceptionPresenter {

  public XmlsonObject present(InvalidStateException exception) {
    final XmlsonObject error = new XmlsonObject("error");
    error.addProperty("type", "validation");
   
    final XmlsonArray invalidValues = new XmlsonArray("invalid-values");
    for (InvalidValue invalidValue : exception.getInvalidValues()) {
      final XmlsonObject value = new XmlsonObject("invalid-value");
      value.addProperty("class", invalidValue.getBeanClass().getName());
      value.addProperty("field", invalidValue.getPropertyName());
      value.addProperty("message", invalidValue.getMessage());
      invalidValues.add(value);
    }
    error.add(invalidValues);
   
    return error;
View Full Code Here

  public TagHierarchyPresenter(SumOfMoneyPresenter moneyPresenter) {
    this.sumOfMoneyPresenter = moneyPresenter;
  }
 
  public XmlsonObject present(TagHierarchy tagHierarchy, Locale locale) {
    final XmlsonObject root = new XmlsonObject("tag-hierarchy");
    root.add(sumOfMoneyPresenter.present("sum", tagHierarchy.getSum(), locale));
   
    final XmlsonArray nodes = new XmlsonArray("nodes");
    for (Node node : tagHierarchy.getChildren().values()) {
      nodes.add(present(node, locale));
    }
    root.add(nodes);
   
    return root;
  }
View Full Code Here

   
    return root;
  }

  private XmlsonObject present(Node node, Locale locale) {
    final XmlsonObject root = new XmlsonObject("node");
   
    final XmlsonObject tag = new XmlsonObject("tag");
    tag.addProperty("name", node.getTag().toString());
    root.add(tag);
   
    root.add(sumOfMoneyPresenter.present("sum", node.getSum(), locale));
   
    if (!node.getChildren().isEmpty()) {
View Full Code Here

TOP

Related Classes of com.wesabe.xmlson.XmlsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.