-
Notifications
You must be signed in to change notification settings - Fork 0
/
Product.java
executable file
·71 lines (57 loc) · 1.57 KB
/
Product.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.manoelcampos.products;
import javax.xml.bind.annotation.*;
/**
* Classe que representa um produto e possibilita
* usar a biblioteca JAXB para fazer marshal e ummarshal,
* isto é, converter um objeto da classe para XML e converter
* uma String XML pra um objeto da classe.
*
* @author Manoel Campos da Silva Filho
*/
@XmlAccessorType(XmlAccessType.FIELD) //indica que os campos da classe vão ser convertidos de/para XML
public class Product {
/**
* Indica que o campo id da classe é definido como um atributo de uma tag no XML.
*/
@XmlAttribute
private int id;
/**
* Indica que o campo description na classe é definido como uma tag (elemento) no XML.
*/
@XmlElement
private String description;
@XmlElement
private String brand;
@XmlElement
private double price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return String.format(
"Product: id %d description: %s brand: %s price: %.2f",
id, description, brand, price);
}
}