4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
BooleanAttribute.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: BooleanAttribute.java
5  * Description: Class representing attribute of type Boolean
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 BooleanAttribute.java
19  *
20  * @brief Class representing attribute of type Boolean
21  */
22 
23 /**
24  * Class representing attribute of type Boolean
25  *
26  * @brief Class representing attribute of type Boolean
27  */
28 @Entity
29 @DiscriminatorValue("Boolean")
30 @NamedQueries({
31  @NamedQuery(name = "Attribute.findByBoolVAlue", query = "SELECT a FROM Attribute a WHERE a.boolVAlue = :boolVAlue"),
32 })
33 public class BooleanAttribute extends BaseAttribute {
34 
35  /**
36  * Constructor
37  */
38  public BooleanAttribute() {
39  }
40 
41  /**
42  * Constructor
43  *
44  * @param name Name of the attribute
45  * @param value Value of the attribute
46  * @param refAnnotation Annotation to which this attribute belongs
47  */
48  public BooleanAttribute(String name, Boolean value, Annotation refAnnotation) {
49  this.name = name;
50  this.simpleType = "Boolean";
51  this.boolVAlue = value;
52  this.refAnnotation = refAnnotation;
53  }
54 
55  /**
56  * Sets value of the attribute. Value should already be a native java Boolean value.
57  *
58  * @param value new value of the attribute
59  */
60  @Override
61  public void setValue(Object value) {
62  this.boolVAlue = (Boolean) value;
63  }
64 
65  /**
66  * Gets value of the attribute
67  *
68  * @return value of the attribute
69  */
70  @Override
71  public Object getValue() {
72  return boolVAlue;
73  }
74 
75  /**
76  * Parses provided value and sets that value as a value of attribute
77  *
78  * @param value new value of the attribute in raw form from XML
79  */
80  @Override
81  public void setRawValue(String value) throws IllegalArgumentException {
82  if(value == null){
83  return;
84  }
85 
86  try{
87  this.boolVAlue = Boolean.parseBoolean(value);
88  }catch(IllegalArgumentException ex){
89  throw new IllegalArgumentException("Value " + value + " is not valid boolean value.");
90  }
91  }
92 
93  /**
94  * Gets URI addres in ontology for this type of attribute
95  *
96  * @return Return URI addres in ontology for this type of attribute.
97  */
98  @Override
99  public String getTypeOntologyUri(){
100  return Constants.BOOLEAN_URI;
101  }
102 
103 } // class BooleanAttribute
BooleanAttribute(String name, Boolean value, Annotation refAnnotation)
Base class representing attribute of annotation.
Class representing attribute of type Boolean.