source: java/main/src/main/java/com/framsticks/params/PropertiesAccess.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.params.types.EventParam;
4import com.framsticks.params.types.ProcedureParam;
5
6/**
7 * The Class PropertiesAccess.
8 *
9 * @author Jarek Szymczak <name.surname@gmail.com> (please replace name and
10 *         surname with my personal data)
11 *
12 * @author Piotr Śniegowski
13 */
14public class PropertiesAccess extends SimpleAbstractAccess {
15
16        protected PropertiesObject properties;
17
18        @Override
19        public PropertiesObject createAccessee() {
20                return new PropertiesObject(framsClass.getId());
21        }
22
23        public PropertiesAccess(FramsClass framsClass) {
24                super(framsClass);
25        }
26
27        @Override
28        public void clearValues() {
29                assert properties != null;
30                properties.clear();
31        }
32
33        @Override
34        public <T> T get(ValueParam param, Class<T> type) {
35                assert properties != null;
36                assert param != null;
37                Object object = properties.get(param.getId(), Object.class);
38                if (object == null) {
39                        return null;
40                }
41                try {
42                        return type.cast(object);
43                } catch (ClassCastException e) {
44                        throw (ClassCastException) new ClassCastException("property " + param + " type is " + object.getClass().getName() + ", not " + type.getName()).initCause(e);
45                }
46        }
47
48        @Override
49        protected <T> void internalSet(ValueParam param, T value) {
50                properties.set(param.getId(), value);
51        }
52
53        /**
54         * Sets the new values to operate on. It does not check whether the values
55         * which are set through this method are correct. If set values are not
56         * correct exceptions might occurred while getting / setting the parameters
57         * values
58         *
59         * @param object
60         *            the properties with parameters values
61         */
62        @Override
63        public PropertiesAccess select(Object object) {
64                properties = ParamsUtil.selectObjectForAccess(this, object, PropertiesObject.class);
65                return this;
66        }
67
68        /** covariant */
69        @Override
70        public PropertiesObject getSelected() {
71                return properties;
72        }
73
74        @Override
75        public PropertiesAccess cloneAccess() {
76                return new PropertiesAccess(framsClass);
77        }
78
79        @Override
80        public void tryAutoAppend(Object object) {
81                throw new InvalidOperationException();
82        }
83
84        @Override
85        public Object call(String id, Object... arguments) {
86                throw new InvalidOperationException().msg("properties access does not support calling methods").arg("id", id);
87        }
88
89        @Override
90        public Object call(ProcedureParam param, Object... arguments) {
91                throw new InvalidOperationException().msg("properties access does not support calling methods").arg("param", param);
92        }
93
94        @Override
95        public void reg(EventParam param, EventListener<?> listener) {
96                throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this);
97        }
98
99        @Override
100        public void regRemove(EventParam param, EventListener<?> listener) {
101                throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this);
102        }
103
104        @Override
105        public String toString() {
106                StringBuilder b = new StringBuilder();
107                b.append(framsClass);
108                if (getSelected() != null) {
109                        b.append("(").append(getSelected().size()).append(")");
110                }
111                return b.toString();
112        }
113}
114
Note: See TracBrowser for help on using the repository browser.