1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.state;
17
18 import org.fourthline.cling.model.Command;
19 import org.fourthline.cling.model.ServiceManager;
20 import org.fourthline.cling.model.meta.LocalService;
21 import org.fourthline.cling.model.meta.StateVariable;
22
23
24
25
26
27
28
29
30
31 public abstract class StateVariableAccessor {
32
33 public StateVariableValue read(final StateVariable<LocalService> stateVariable, final Object serviceImpl) throws Exception {
34
35 class AccessCommand implements Command {
36 Object result;
37 public void execute(ServiceManager serviceManager) throws Exception {
38 result = read(serviceImpl);
39 if (stateVariable.getService().isStringConvertibleType(result)) {
40 result = result.toString();
41 }
42 }
43 }
44
45 AccessCommand cmd = new AccessCommand();
46 stateVariable.getService().getManager().execute(cmd);
47 return new StateVariableValue(stateVariable, cmd.result);
48 }
49
50 public abstract Class<?> getReturnType();
51
52
53 public abstract Object read(Object serviceImpl) throws Exception;
54
55 @Override
56 public String toString() {
57 return "(" + getClass().getSimpleName() + ")";
58 }
59 }