]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java
Add generate script
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / PrimitiveSpecAttribute.java
1 package org.argeo.slc.core.execution;
2
3 import org.argeo.slc.SlcException;
4
5 public class PrimitiveSpecAttribute extends AbstractSpecAttribute implements
6 PrimitiveAccessor {
7 // public enum Type {
8 // string, integer
9 // }
10
11 public final static String TYPE_STRING = "string";
12 public final static String TYPE_INTEGER = "integer";
13 public final static String TYPE_LONG = "long";
14 public final static String TYPE_FLOAT = "float";
15 public final static String TYPE_DOUBLE = "double";
16 public final static String TYPE_BOOLEAN = "boolean";
17
18 private String type = "string";
19 private Object value = null;
20
21 public Object getValue() {
22 return value;
23 }
24
25 public void setValue(Object value) {
26 this.value = value;
27 }
28
29 public String getType() {
30 return type;
31 }
32
33 public Class<?> getTypeAsClass() {
34 return typeAsClass(type);
35 }
36
37 public void setType(String type) {
38 this.type = type;
39
40 // check whether type is recognized.
41 // TODO: make validation cleaner
42 typeAsClass(type);
43 }
44
45 public static Class<?> typeAsClass(String type) {
46 if (TYPE_STRING.equals(type))
47 return String.class;
48 else if (TYPE_INTEGER.equals(type))
49 return Integer.class;
50 else if (TYPE_LONG.equals(type))
51 return Long.class;
52 else if (TYPE_FLOAT.equals(type))
53 return Float.class;
54 else if (TYPE_DOUBLE.equals(type))
55 return Double.class;
56 else if (TYPE_BOOLEAN.equals(type))
57 return Boolean.class;
58 else
59 throw new SlcException("Unrecognized type " + type);
60 }
61
62 }