class MultiAttributeCollection extends MultiAttributeProvider implements AttributeCollection {

	@Override
	public Attribute setAttribute(String name, AttributeValue value) throws AttributeException {
		final boolean b = this.runProviderEvents.getAndSet(false);
		try {
			boolean changed = false;
			Attribute attr;
			final ManyValueAttributeValue oldValue = new ManyValueAttributeValue();
			final ManyValueAttributeValue newValue = new ManyValueAttributeValue();
			for (final AttributeProvider c : containers()) {
				assign(oldValue, c.getAttribute(name));
				if (c instanceof AttributeCollection) {
					attr = ((AttributeCollection) c).setAttribute(name, value);
					assign(newValue, attr);
					if (attr != null) {
						changed = true;
					}
				} else {
					assign(newValue, null);
				}
			}
			if (changed) {
				final AttributeValue oValue = canonize(oldValue);
				final AttributeValue nValue = canonize(newValue);
				this.cache.put(name, nValue);
				final AttributeChangeEvent event;
				if (nValue == null) {
					event = new AttributeChangeEvent(this, Type.REMOVAL, name, oValue, null, null);
				} else if (oValue != null && oValue.isAssigned()) {
					event = new AttributeChangeEvent(this, Type.VALUE_UPDATE, name, oValue, name, nValue);
				} else {
					event = new AttributeChangeEvent(this, Type.ADDITION, null, null, name, nValue);
				}
				fireAttributeChange(event);
				return new AttributeImpl(name, value);
			}
			return null;
		} finally {
			this.runProviderEvents.set(b);
		}
	}

}