package com.framsticks.params; import com.framsticks.params.types.EventParam; import com.framsticks.params.types.ProcedureParam; /** * The Class PropertiesAccess. * * @author Jarek Szymczak (please replace name and * surname with my personal data) * * @author Piotr Ĺšniegowski */ public class PropertiesAccess extends SimpleAbstractAccess { protected PropertiesObject properties; @Override public PropertiesObject createAccessee() { return new PropertiesObject(framsClass.getId()); } 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(), Object.class); if (object == null) { return 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); } } @Override protected void internalSet(ValueParam param, T value) { properties.set(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 */ @Override public PropertiesAccess select(Object object) { properties = ParamsUtil.selectObjectForAccess(this, object, PropertiesObject.class); return this; } /** covariant */ @Override public PropertiesObject getSelected() { return properties; } @Override public PropertiesAccess cloneAccess() { return new PropertiesAccess(framsClass); } @Override public void tryAutoAppend(Object object) { throw new InvalidOperationException(); } @Override public Object call(String id, Object... arguments) { throw new InvalidOperationException().msg("properties access does not support calling methods").arg("id", id); } @Override public Object call(ProcedureParam param, Object... arguments) { throw new InvalidOperationException().msg("properties access does not support calling methods").arg("param", param); } @Override public void reg(EventParam param, EventListener listener) { throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this); } @Override public void regRemove(EventParam param, EventListener listener) { throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this); } @Override public String toString() { StringBuilder b = new StringBuilder(); b.append(framsClass); if (getSelected() != null) { b.append("(").append(getSelected().size()).append(")"); } return b.toString(); } }