/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache license, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.internna.iwebmvc.model;
import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Locale;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.RemoteProperty;
import org.hibernate.validator.NotNull;
/**
* Represents an amount of money in any currency
*
* @author Jose Noheda
* @since 2.0
*/
@Embeddable
@DataTransferObject(javascript = "Amount")
public class Amount implements Displayable, Serializable {
private static final long serialVersionUID = 3587051472782903886L;
@RemoteProperty
@Column(name = "AMOUNT")
Double amount;
@NotNull
@RemoteProperty
@JoinColumn(name = "CURRENCY")
@ManyToOne(fetch = FetchType.EAGER)
Currency currency;
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public Currency getCurrency() {
return currency;
}
public void setCurrency(Currency currency) {
this.currency = currency;
}
@Override public String getCaption(Locale locale) {
NumberFormat formatter = locale == null ? NumberFormat.getCurrencyInstance() : NumberFormat.getCurrencyInstance(locale);
formatter.setCurrency(currency.getCurrency());
return formatter.format(amount);
}
}