1 package fr.in2p3.jsaga.impl.attributes;
2
3 import fr.in2p3.jsaga.helpers.AttributeSerializer;
4 import fr.in2p3.jsaga.impl.monitoring.MetricMode;
5 import fr.in2p3.jsaga.impl.monitoring.MetricType;
6 import org.ogf.saga.error.*;
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public class ScalarAttributeImpl<E> implements AttributeScalar {
21 protected String m_key;
22 protected E m_object;
23 private MetricMode m_mode;
24 private MetricType m_type;
25
26
27 public ScalarAttributeImpl(String key, String desc, MetricMode mode, MetricType type, E initialObject) {
28 m_key = key;
29 m_object = initialObject;
30 m_mode = mode;
31 m_type = type;
32 }
33
34
35 public ScalarAttributeImpl<E> clone() throws CloneNotSupportedException {
36 return new ScalarAttributeImpl<E>(m_key, null, m_mode, m_type, m_object);
37 }
38
39
40
41
42 public void setObject(E object) {
43 m_object = object;
44 }
45
46
47 public E getObject() {
48 return m_object;
49 }
50
51
52
53 public String getKey() {
54 return m_key;
55 }
56
57 public MetricMode getMode() {
58 return m_mode;
59 }
60
61 public MetricType getType() {
62 return m_type;
63 }
64
65 public boolean isReadOnly() {
66 switch(m_mode) {
67 case ReadOnly:
68 case Final:
69 return true;
70 case ReadWrite:
71 default:
72 return false;
73 }
74 }
75
76 public void setValue(String value) throws NotImplementedException, IncorrectStateException, PermissionDeniedException {
77 try {
78 m_object = new AttributeSerializer<E>(m_type).fromString(value);
79 } catch (DoesNotExistException e) {
80 throw new NotImplementedException("INTERNAL ERROR: unexpected exception", e);
81 }
82 }
83
84 public String getValue() throws NotImplementedException, IncorrectStateException, NoSuccessException {
85 try {
86 return new AttributeSerializer<E>(m_type).toString(m_object);
87 } catch (DoesNotExistException e) {
88 throw new NotImplementedException("INTERNAL ERROR: unexpected exception", e);
89 }
90 }
91
92 public void setValues(String[] values) throws IncorrectStateException {
93 throw new IncorrectStateException("Attribute "+m_key+" not vector");
94 }
95
96 public String[] getValues() throws IncorrectStateException {
97 throw new IncorrectStateException("Attribute "+m_key+" not vector");
98 }
99
100 public boolean equals(Object o) {
101 if (o instanceof ScalarAttributeImpl) {
102 ScalarAttributeImpl scalarAttribute = (ScalarAttributeImpl) o;
103 return m_key.equals(scalarAttribute.getKey()) &&
104 (
105 (m_object ==null && scalarAttribute.getObject()==null) ||
106 (m_object !=null && m_object.equals(scalarAttribute.getObject()))
107 );
108 } else {
109 return false;
110 }
111 }
112 }