/** * Gets the items from this map that have indicated they are {@link Serializable} through * {@link AttributeHolder#isSerializable()}. * @return a new map of keys to the {@link Serializable} values. */ public <V> Map<String, V> getAllSerializable() { final Map<String, V> allSerializable = new HashMap<String, V>(); for (Entry<String, AttributeHolder> entry : attributes.entrySet()) { final AttributeHolder attributeHolder = entry.getValue(); if (attributeHolder.isSerializable()) { @SuppressWarnings("unchecked") final V value = (V)attributeHolder.getValue(); allSerializable.put(entry.getKey(), value); } } return allSerializable; }
/** * Takes the supplied attributes and returns an equivalent set that are ready to be serialized. * Will only return those attributes that are marked as serializable. * * @param attributeHolders the attributes to prepare for serialization * @return an equivalent set of attributes that can be serialized */ public Map<String, Serializable> makeAttributeHoldersSerializable( final Map<String, ? extends AttributeHolder> attributeHolders) { if (!isEnabled()) { return new HashMap<String, Serializable>(); } final Map<String, Serializable> renderedAttributes = new HashMap<String, Serializable>( attributeHolders.size()); for (final Entry<String, ? extends AttributeHolder> entry : attributeHolders.entrySet()) { final AttributeHolder holder = entry.getValue(); if (holder.isSerializable()) { renderedAttributes.put(entry.getKey(), decomposer.decompose(holder)); } } return renderedAttributes; }
public Map getInheritableAttributes() { Map inheritableAttributes = new HashMap(); Map map = (Map) threadBasedMap.get(Thread.currentThread()); if(map != null) { for(Iterator it = map.values().iterator(); it.hasNext(); ) { Map attributes = (Map) it.next(); for(Iterator ij = attributes.entrySet().iterator(); ij.hasNext(); ) { Map.Entry entry = (Map.Entry) ij.next(); AttributeHolder original = (AttributeHolder) entry.getValue(); AttributeHolder copy = new AttributeHolder(original.getValue()); if(original.isSerializable()) { copy.serializable(); } inheritableAttributes.put(entry.getKey(), copy); } } } return inheritableAttributes; }
/** * Creates a new {@link CompositeAttributeHolder} for a value * @param old the existing {@link AttributeHolder}. Note that the value of the holder is ignored * and it does not have to be "{@link CompositeAttributeHolder composite}". * @param value the value to be held * @return a new {@link CompositeAttributeHolder composite holder} holding the value with its * {@link CompositeAttributeHolder#isSerializable() serializable} attribute set to the * same value as the specified holder. */ protected CompositeAttributeHolder createHolderForValue(final AttributeHolder old, final Object value) { final CompositeAttributeHolder attributeHolder = new CompositeAttributeHolder(value); if (old.isSerializable()) { attributeHolder.serializable(); } return attributeHolder; }
@Override protected CompositeAttributeHolder createHolderForValue(final AttributeHolder old, final Object value) { final CompositeAttributeHolder attributeHolder = new CompositeAttributeHolder(value); if (old.isSerializable()) { attributeHolder.serializable(); } if (CompositeAttributeHolder.class.isAssignableFrom(old.getClass())) { if (((CompositeAttributeHolder)old).isInheritable()) { attributeHolder.setInheritable(true); } } return attributeHolder; }
private void inheritGlobals(final Monitor monitor) { for (final Iterator it = globalAttributes.getAllAttributeHolders().entrySet().iterator(); it .hasNext();) { final Map.Entry entry = (Map.Entry)it.next(); final String key = (String)entry.getKey(); final AttributeHolder holder = (AttributeHolder)entry.getValue(); final Object value = holder.getValue(); final AttributeHolder attribute = monitor.set(key, value); if (holder.isSerializable()) { attribute.serializable(); } if (holder.isLocked()) { attribute.lock(); } } }
private void inheritAttributesFromAncestors(final Monitor monitor) { // Inherit from parent if not set. final Map attrs = getInheritableAttributes(); for (final Iterator it = attrs.entrySet().iterator(); it.hasNext();) { final Map.Entry entry = (Map.Entry)it.next(); final String key = (String)entry.getKey(); final AttributeHolder parentAttribute = (AttributeHolder)entry.getValue(); if (!monitor.hasAttribute(key)) { final Object value = parentAttribute.getValue(); final AttributeHolder childAttribute = monitor.set(key, value); if (parentAttribute.isSerializable()) { childAttribute.serializable(); } if (parentAttribute.isLocked()) { childAttribute.lock(); } } } }
final AttributeHolder original = (AttributeHolder)value; final CompositeAttributeHolder copy = new CompositeAttributeHolder(original.getValue()); if (original.isSerializable()) { copy.serializable();