package com.framsticks.params; import java.util.HashMap; import java.util.Map; /** * The Class PropertiesAccess. * * @author Jarek Szymczak (please replace name and * surname with my personal data) * * @author Piotr Ĺšniegowski */ public class PropertiesAccess extends SimpleAbstractAccess { public Map properties; @Override public Map createAccessee() { return PropertiesAccess.createPropertiesMap(); } public static Map createPropertiesMap() { return new HashMap(); } public PropertiesAccess(FramsClass framsClass) { super(framsClass); } @Override public void clearValues() { assert properties != null; properties.clear(); } @Override public T get(ValueParam param, Class type) { assert properties != null; assert param != null; Object object = properties.get(param.getId()); if (object != null) { try { return type.cast(object); } catch (ClassCastException e) { throw (ClassCastException) new ClassCastException("property " + param + " type is " + object.getClass().getName() + ", not " + type.getName()).initCause(e); } } try { return param.getDef(type); } catch (ClassCastException e) { throw (ClassCastException) new ClassCastException("default value of property " + param + " is not of type " + type.getName()).initCause(e); } } @Override protected void internalSet(ValueParam param, T value) { properties.put(param.getId(), value); } /** * Sets the new values to operate on. It does not check whether the values * which are set through this method are correct. If set values are not * correct exceptions might occurred while getting / setting the parameters * values * * @param object * the properties with parameters values */ @SuppressWarnings("unchecked") @Override public PropertiesAccess select(Object object) { this.properties = (Map)object; return this; } /** covariant */ @Override public Map getSelected() { return properties; } @Override public PropertiesAccess cloneAccess() { return new PropertiesAccess(framsClass); } @Override public boolean tryAutoAppend(Object object) { return false; } }