/** * Sets the value. * * @param value the new value for the entry * @return the old value for the entry */ public override Object setValue(Object value) { Object key = getKey(); Object oldValue = owner.get(key); owner.put(key, value); Object newValue = owner.get(key); base.setValue(newValue); return(oldValue); }
/** * Clone this bean map using the following process: * * <ul> * <li>If there is no underlying bean, return a cloned BeanMap without a * bean. * * <li>Since there is an underlying bean, try to instantiate a new bean of * the same type using Class.newInstance(). * * <li>If the instantiation fails, throw a CloneNotSupportedException * * <li>Clone the bean map and set the newly instantiated bean as the * underlying bean for the bean map. * * <li>Copy each property that is both readable and writable from the * existing object to a cloned bean map. * * <li>If anything fails along the way, throw a * CloneNotSupportedException. * * <ul> */ public Object clone() {//throws CloneNotSupportedException { BeanMap newMap = (BeanMap)base.MemberwiseClone(); if (bean == null) { // no bean, just an empty bean map at the moment. return a newly // cloned and empty bean map. return(newMap); } Object newBean = null; java.lang.Class beanClass = null; try { beanClass = bean.getClass(); newBean = beanClass.newInstance(); } catch (Exception e) { // unable to instantiate throw new java.lang.CloneNotSupportedException ("Unable to instantiate the underlying bean \"" + beanClass.getName() + "\": " + e); } try { newMap.setBean(newBean); } catch (Exception exception) { throw new java.lang.CloneNotSupportedException ("Unable to set bean in the cloned bean map: " + exception); } try { // copy only properties that are readable and writable. If its // not readable, we can't get the value from the old map. If // its not writable, we can't write a value into the new map. java.util.Iterator <Object> readableKeys = readMethods.keySet().iterator(); while (readableKeys.hasNext()) { Object key = readableKeys.next(); if (getWriteMethod(key) != null) { newMap.put(key, get(key)); } } } catch (Exception exception) { throw new java.lang.CloneNotSupportedException ("Unable to copy bean values to cloned bean map: " + exception); } return(newMap); }