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

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

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

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