4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
IntegerAttribute.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: IntegerAttribute.java
5  * Description: Class representing attribute of type Integer
6  */
7 
8 package cz.vutbr.fit.knot.annotations.entity.attribute;
9 
12 import javax.persistence.DiscriminatorValue;
13 import javax.persistence.Entity;
14 import javax.persistence.NamedQueries;
15 import javax.persistence.NamedQuery;
16 
17 /**
18  * @file IntegerAttribute.java
19  *
20  * @brief Class representing attribute of type Integer
21  */
22 
23 /**
24  * Class representing attribute of type Integer
25  *
26  * @brief Class representing attribute of type Integer
27  */
28 @Entity
29 @DiscriminatorValue("Integer")
30 @NamedQueries({
31  @NamedQuery(name = "Attribute.findByIntValue", query = "SELECT a FROM Attribute a WHERE a.intValue = :intValue"),
32 })
33 public class IntegerAttribute extends BaseAttribute {
34 
35  /**
36  * Constructor
37  */
38  public IntegerAttribute() {
39  }
40 
41  /**
42  * Constructor
43  *
44  * @param name Name of attribute
45  * @param value Value of attribute
46  * @param refAnnotation Annotation to which this attribute belongs
47  */
48  public IntegerAttribute(String name, Integer value, Annotation refAnnotation) {
49  this.name = name;
50  this.simpleType = "Integer";
51  this.intValue = value;
52  this.refAnnotation = refAnnotation;
53  }
54 
55 
56  /**
57  * Gets value of the attribute
58  *
59  * @return value of the attribute
60  */
61  @Override
62  public Object getValue() {
63  return this.intValue;
64  }
65 
66  /**
67  * Sets value of the attribute. Value should already be a native java Integer value.
68  *
69  * @param value New value of the attribute
70  */
71  @Override
72  public void setValue(Object value) {
73  this.intValue = (Integer) value;
74  }
75 
76 
77  /**
78  * Parses integer represented by string value and sets it as attribute
79  * value
80  *
81  * @param value String with value of type Integer
82  */
83  @Override
84  public void setRawValue(String value) throws IllegalArgumentException {
85  if(value == null){
86  return;
87  }
88 
89  try {
90  this.intValue = Integer.parseInt(value);
91  } catch (NumberFormatException e) {
92  throw new IllegalArgumentException("Value " + value + " is not a valid integer value");
93  }
94  }
95 
96  /**
97  * Gets URI addres in ontology for this type of attribute
98  *
99  * @return Return URI addres in ontology for this type of attribute.
100  */
101  @Override
102  public String getTypeOntologyUri(){
103  return Constants.INTEGER_URI;
104  }
105 
106 } // class IntegerAttribute
IntegerAttribute(String name, Integer value, Annotation refAnnotation)
Class representing attribute of type Integer.
Base class representing attribute of annotation.