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

Last change on this file since 78 was 78, checked in by psniegowski, 11 years ago

Add f0 parsing and f0->Model transformation.

File size: 2.0 KB
Line 
1package com.framsticks.params;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8/**
9 * The Class PropertiesAccess.
10 *
11 * @author Jarek Szymczak <name.surname@gmail.com> (please replace name and
12 *         surname with my personal data)
13 *
14 * @author Piotr Śniegowski
15 */
16public class PropertiesAccess extends SimpleAbstractAccess {
17
18        public Map<String, Object> properties;
19
20    @Override
21        public Map<String, Object> createAccessee() {
22                return PropertiesAccess.createPropertiesMap();
23        }
24
25        public static Map<String, Object> createPropertiesMap() {
26                return new HashMap<String, Object>();
27        }
28
29        public PropertiesAccess(FramsClass framsClass) {
30                setFramsClass(framsClass);
31        }
32
33        @Override
34        public void clearValues() {
35        assert properties != null;
36        properties.clear();
37        }
38
39        @Override
40        public <T> T get(Param param, Class<T> type) {
41        assert properties != null;
42        assert param != null;
43                Object object = null;
44                try {
45                        object = properties.get(param.getId());
46                        if (object == null) {
47                                return param.getDef(type);
48                        }
49                        return type.cast(object);
50                } catch (ClassCastException e) {
51                        throw new ClassCastException("property " + param.getId() + " type is " + object.getClass().getName() + ", not " + type.getName());
52                }
53
54        }
55
56        protected <T> void internalSet(Param param, T value) {
57                properties.put(param.getId(), value);
58        }
59
60        /**
61         * Sets the new values to operate on. It does not check whether the values
62         * which are set through this method are correct. If set values are not
63         * correct exceptions might occurred while getting / setting the parameters
64         * values
65         *
66         * @param object
67         *            the properties with parameters values
68         */
69        @Override
70        public void select(Object object) {
71                this.properties = (Map<String, Object>)object;
72        }
73
74        /** covariant */
75        @Override
76        public Map<String, Object> getSelected() {
77                return properties;
78        }
79
80        @Override
81        public PropertiesAccess cloneAccess() {
82                return new PropertiesAccess(framsClass);
83                //properties = createProperties();
84                //return access;
85        }
86
87
88}
Note: See TracBrowser for help on using the repository browser.