1 package org
.argeo
.slc
.castor
.execution
;
3 import org
.argeo
.slc
.core
.execution
.PrimitiveSpecAttribute
;
4 import org
.argeo
.slc
.core
.execution
.PrimitiveValue
;
5 import org
.exolab
.castor
.mapping
.AbstractFieldHandler
;
7 public class PrimitiveFieldHandler
extends AbstractFieldHandler
{
10 public Object
getValue(Object object
) throws IllegalStateException
{
15 if (object
instanceof PrimitiveSpecAttribute
)
16 value
= ((PrimitiveSpecAttribute
) object
).getValue();
17 else if (object
instanceof PrimitiveValue
)
18 value
= ((PrimitiveValue
) object
).getValue();
20 throw new IllegalStateException("Unkown type " + object
.getClass());
22 return value
!= null ? value
.toString() : null;
26 public Object
newInstance(Object parent
, Object
[] args
)
27 throws IllegalStateException
{
28 // TODO Auto-generated method stub
33 public Object
newInstance(Object parent
) throws IllegalStateException
{
34 // TODO Auto-generated method stub
39 public void resetValue(Object object
) throws IllegalStateException
,
40 IllegalArgumentException
{
41 // TODO Auto-generated method stub
46 public void setValue(Object object
, Object value
)
47 throws IllegalStateException
, IllegalArgumentException
{
48 // TODO: could probably be more generic
50 PrimitiveSpecAttribute attr
= (PrimitiveSpecAttribute
) object
;
51 String type
= attr
.getType();
52 String str
= value
.toString();
55 if (object
instanceof PrimitiveSpecAttribute
)
56 ((PrimitiveSpecAttribute
) object
).setValue(convert(type
, str
));
57 else if (object
instanceof PrimitiveValue
)
58 ((PrimitiveValue
) object
).setValue(convert(type
, str
));
60 throw new IllegalStateException("Unkown type " + object
.getClass());
63 protected Object
convert(String type
, String str
) {
64 if (PrimitiveSpecAttribute
.TYPE_STRING
.equals(type
)) {
66 } else if (PrimitiveSpecAttribute
.TYPE_INTEGER
.equals(type
)) {
67 return (Integer
.parseInt(str
));
68 } else if (PrimitiveSpecAttribute
.TYPE_LONG
.equals(type
)) {
69 return (Long
.parseLong(str
));
70 } else if (PrimitiveSpecAttribute
.TYPE_FLOAT
.equals(type
)) {
71 return (Float
.parseFloat(str
));
72 } else if (PrimitiveSpecAttribute
.TYPE_DOUBLE
.equals(type
)) {
73 return (Double
.parseDouble(str
));
74 } else if (PrimitiveSpecAttribute
.TYPE_BOOLEAN
.equals(type
)) {
75 return (Boolean
.parseBoolean(str
));