1 | package com.framsticks.params; |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | import com.framsticks.params.types.EventParam; |
---|
7 | import com.framsticks.params.types.ProcedureParam; |
---|
8 | |
---|
9 | /** |
---|
10 | * @author Piotr Sniegowski |
---|
11 | */ |
---|
12 | public abstract class ListAccess implements Access { |
---|
13 | |
---|
14 | final Access elementAccess; |
---|
15 | final String containedTypeName; |
---|
16 | |
---|
17 | protected final ParamBuilder paramBuilder; |
---|
18 | |
---|
19 | public ListAccess(Access elementAccess) { |
---|
20 | this.elementAccess = elementAccess; |
---|
21 | this.containedTypeName = elementAccess.getTypeId(); |
---|
22 | paramBuilder = elementAccess.buildParam(new ParamBuilder()); |
---|
23 | } |
---|
24 | |
---|
25 | // @Override |
---|
26 | // public Param getGroupMember(int gi, int n) { |
---|
27 | // return null; |
---|
28 | // } |
---|
29 | |
---|
30 | |
---|
31 | public Access getElementAccess() { |
---|
32 | return elementAccess; |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * @return the containedTypeName |
---|
37 | */ |
---|
38 | public String getContainedTypeName() { |
---|
39 | return containedTypeName; |
---|
40 | } |
---|
41 | |
---|
42 | @Override |
---|
43 | public final FramsClass getFramsClass() { |
---|
44 | return elementAccess.getFramsClass(); |
---|
45 | } |
---|
46 | |
---|
47 | @Override |
---|
48 | public void tryAutoAppend(Object object) { |
---|
49 | throw new InvalidOperationException().msg("It could actually be used also, the Access.select could be used to check whether type is correct"); |
---|
50 | } |
---|
51 | |
---|
52 | @Override |
---|
53 | public Object call(String id, Object... arguments) { |
---|
54 | throw new InvalidOperationException().msg("list access does not support calling methods").arg("id", id).arg("access", this); |
---|
55 | } |
---|
56 | |
---|
57 | @Override |
---|
58 | public Object call(ProcedureParam param, Object... arguments) { |
---|
59 | throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param).arg("access", this); |
---|
60 | } |
---|
61 | |
---|
62 | @Override |
---|
63 | public void reg(EventParam param, EventListener<?> listener) { |
---|
64 | throw new InvalidOperationException().msg("list access does not support registering events").arg("param", param).arg("access", this); |
---|
65 | } |
---|
66 | |
---|
67 | @Override |
---|
68 | public void regRemove(EventParam param, EventListener<?> listener) { |
---|
69 | throw new InvalidOperationException().msg("list access does not support registering events").arg("param", param).arg("access", this); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | @Override |
---|
74 | public String toString() { |
---|
75 | StringBuilder b = new StringBuilder(); |
---|
76 | b.append("list of ").append(containedTypeName); |
---|
77 | if (getSelected() != null) { |
---|
78 | b.append("[").append(getParamCount()).append("]"); |
---|
79 | } |
---|
80 | return b.toString(); |
---|
81 | } |
---|
82 | |
---|
83 | public CompositeParam prepareParamFor(String id) { |
---|
84 | return paramBuilder.id(id).finish(CompositeParam.class); |
---|
85 | } |
---|
86 | }; |
---|