4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
BinaryAttribute.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: BinaryAttribute.java
5  * Description: Class representing attribute of type Binary
6  */
7 
8 package cz.vutbr.fit.knot.annotations.entity.attribute;
9 
11 import javax.persistence.DiscriminatorValue;
12 import javax.persistence.Entity;
13 
14 /**
15  * @file BinaryAttribute.java
16  *
17  * @brief Class representing attribute of type Binary
18  */
19 
20 /**
21  * Class representing attribute of type Binary
22  *
23  * @brief Class representing attribute of type Binary
24  */
25 @Entity
26 @DiscriminatorValue("Binary")
27 public class BinaryAttribute extends BaseAttribute {
28 
29  /**
30  * Sets value of the attribute. Value should already be a native java value.
31  *
32  * @param value new value of the attribute
33  */
34  @Override
35  public void setValue(Object value) {
36  this.binValue = (byte[]) value;
37  }
38 
39  /**
40  * Gets value of the attribute
41  *
42  * @return value of the attribute
43  */
44  @Override
45  public Object getValue() {
46  return (Object) this.binValue;
47  }
48 
49 
50  /**
51  * Converts string value, which should be encoded in base64 and sets its
52  * binary representation as attribute value
53  *
54  * @param value Value of attribute encoded in base64
55  */
56  @Override
57  public void setRawValue(String value) throws IllegalArgumentException {
58  if(value == null){
59  return;
60  }
61  try{
62  this.binValue = org.apache.commons.codec.binary.Base64.decodeBase64(value);
63  }catch(IllegalArgumentException ex){
64  throw new IllegalArgumentException("Value " + value + "is not valid binary value");
65  }
66 
67  }
68 
69 
70  /**
71  * Formats attribute value for XML.
72  *
73  * @return base64 encoded attribute value
74  */
75  @Override
76  protected String xmlFormatValue() {
77  if (this.binValue == null) {
78  return "";
79  }
80  return org.apache.commons.codec.binary.Base64.encodeBase64String(this.binValue);
81  }
82 
83  /**
84  * Gets URI address in ontology for this type of attribute
85  *
86  * @return Return URI address in ontology for this type of attribute.
87  */
88  @Override
89  public String getTypeOntologyUri(){
90  return Constants.BINARY_URI;
91  }
92 
93 } // class BinaryAttribute
Base class representing attribute of annotation.
Class representing attribute of type Binary.