[77] | 1 | package com.framsticks.params; |
---|
| 2 | |
---|
| 3 | import java.util.ArrayList; |
---|
| 4 | import java.util.HashMap; |
---|
| 5 | import java.util.List; |
---|
| 6 | import 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 | */ |
---|
| 16 | public class PropertiesAccess extends SimpleAbstractAccess { |
---|
| 17 | |
---|
| 18 | public Map<String, Object> properties; |
---|
| 19 | |
---|
| 20 | @Override |
---|
| 21 | public Map<String, Object> createAccessee() { |
---|
[78] | 22 | return PropertiesAccess.createPropertiesMap(); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | public static Map<String, Object> createPropertiesMap() { |
---|
[77] | 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 | } |
---|