4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
DecimalAttribute.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz, Jan Planer xplane01@stud.fit.vutbr.cz
4  * File: DecimalAttribute.java
5  * Description: Class representing attribute of type Decimal
6  */
7 
8 package cz.vutbr.fit.knot.annotations.entity.attribute;
9 
11 import java.math.BigDecimal;
12 import javax.persistence.DiscriminatorValue;
13 import javax.persistence.Entity;
14 import javax.persistence.NamedQueries;
15 import javax.persistence.NamedQuery;
16 
17 /**
18  * @file DecimalAttribute.java
19  *
20  * @brief Class representing attribute of type Decimal
21  */
22 
23 /**
24  * Class representing attribute of type Decimal
25  *
26  * @brief Class representing attribute of type Decimal
27  */
28 @Entity
29 @DiscriminatorValue("Decimal")
30 @NamedQueries({
31  @NamedQuery(name = "Attribute.findByDecValue", query = "SELECT a FROM Attribute a WHERE a.decValue = :decValue"),
32 })
33 public class DecimalAttribute extends BaseAttribute {
34 
35  /**
36  * Gets value of the attribute
37  *
38  * @return value of the attribute
39  */
40  @Override
41  public Object getValue() {
42  return this.decValue;
43  }
44 
45  /**
46  * Sets value of the attribute. Value should already be a native java BigDecimal value.
47  *
48  * @param value new value of the attribute
49  */
50  @Override
51  public void setValue(Object value) {
52  this.decValue = (BigDecimal) value;
53  }
54 
55  /**
56  * Parses BigDecimal value represented by string value and sets it as
57  * attribute value
58  *
59  * @param value String representing BigDecimal value
60  */
61  @Override
62  public void setRawValue(String value) throws IllegalArgumentException {
63  if(value == null){
64  return;
65  }
66 
67  try {
68  this.decValue = new BigDecimal(value);
69  } catch (NumberFormatException e) {
70  throw new IllegalArgumentException("Value " + value + " is not a valid Decimal value");
71  }
72  }
73 
74  /**
75  * Gets URI addres in ontology for this type of attribute
76  *
77  * @return Return URI addres in ontology for this type of attribute.
78  */
79  @Override
80  public String getTypeOntologyUri(){
81  return Constants.DECIMAL_URI;
82  }
83 
84 } // class DecimalAttribute
Class representing attribute of type Decimal.
Base class representing attribute of annotation.