/** * Sets an attribute instance to be updated. * * @param attributeInstance the attribute instance to be updated. */ protected void putUpdatedAttributeInstance(Attribute attributeInstance) { synchronized (updatedAttributeInstances) { if (updatedAttributeInstances.put(attributeInstance.getId(), attributeInstance) == null) Logger.getLogger(this.getClass()).debug( "Put Updating: " + attributeInstance + " * " + this.strHashCode()); } }
/** * Updates all the attribute instances linked with the specified element. * * @param elementId the URI of the element. */ protected void updateLinkedAttributeInstances(URI elementId) { synchronized (updatedAttributeInstances) { Set<URI> attributeInstanceIds = elementsLinkedAttributeInstances.get(elementId); Logger.getLogger(this.getClass()).debug( "Updating: " + attributeInstanceIds + " <- " + elementId + " * " + this.strHashCode()); if (attributeInstanceIds != null) for (URI attributeInstanceId : attributeInstanceIds) updateAttributeInstance(attributeInstanceId); } }
protected void removeAttributeInstanceLinkedElement(URI attributeInstanceId, ContextElement linkedElement) { synchronized (updatedAttributeInstances) { URI linkedElementId = linkedElement.getId(); Set<URI> linkedElementsIds = attributeInstancesLinkedElements.get(attributeInstanceId); if (linkedElementsIds != null) if (linkedElementsIds.remove(linkedElementId)) Logger.getLogger(this.getClass()).debug( "Unlinking: " + updatedAttributeInstances.get(attributeInstanceId) + "<-/-" + linkedElement + " * " + this.strHashCode()); Set<URI> attributeInstancesIds = elementsLinkedAttributeInstances.get(linkedElementId); if (attributeInstancesIds != null) { attributeInstancesIds.remove(attributeInstanceId); if (attributeInstancesIds.isEmpty()) { elementsLinkedAttributeInstances.remove(linkedElementId); linkedElements.remove(linkedElementId).removeObserver(linkedElementsObserver); this.contextRelease(linkedElementId); } } } }
/** * Removes an attribute instance from being updated. * * @param elementId the URI of the attribute instance. */ protected void removeUpdatedAttributeInstance(URI elementId) { synchronized (updatedAttributeInstances) { Attribute removed; if ((removed = updatedAttributeInstances.remove(elementId)) != null) Logger.getLogger(this.getClass()).debug( "Quit Updating: " + removed + " * " + this.strHashCode()); Set<URI> attributeInstanceLinkedElementsIds = attributeInstancesLinkedElements.remove(elementId); if (attributeInstanceLinkedElementsIds != null) for (URI attributeInstanceLinkedElementId : attributeInstanceLinkedElementsIds) { Set<URI> elementLinkedAttributeInstances = elementsLinkedAttributeInstances .get(attributeInstanceLinkedElementId); elementLinkedAttributeInstances.remove(elementId); if (elementLinkedAttributeInstances.isEmpty()) { elementsLinkedAttributeInstances.remove(attributeInstanceLinkedElementId); linkedElements.remove(attributeInstanceLinkedElementId).removeObserver(linkedElementsObserver); this.contextRelease(attributeInstanceLinkedElementId); } } } }
/** * Links an element to an updated attribute instance, so that the changes of the linked element produces the update * of the updated attribute instance. * * @param attributeInstanceId the URI of the attibute instance to be updated. * @param linkedElement the linked element. * @return the previous linked element with the same URI. */ protected ContextElement addAttributeInstanceLinkedElement(URI attributeInstanceId, ContextElement linkedElement) { synchronized (updatedAttributeInstances) { URI linkedElementId = linkedElement.getId(); Set<URI> attributeInstancesIds = elementsLinkedAttributeInstances.get(linkedElementId); if (attributeInstancesIds == null) { linkedElement = this.contextRequest(linkedElement); linkedElements.put(linkedElementId, linkedElement); elementsLinkedAttributeInstances.put(linkedElementId, attributeInstancesIds = setUpIdSet()); linkedElement.addObserver(linkedElementsObserver); } else linkedElement = this.contextPeek(linkedElementId); attributeInstancesIds.add(attributeInstanceId); Set<URI> linkedElementsIds = attributeInstancesLinkedElements.get(attributeInstanceId); if (linkedElementsIds == null) attributeInstancesLinkedElements.put(attributeInstanceId, linkedElementsIds = setUpIdSet()); if (linkedElementsIds.add(linkedElementId)) Logger.getLogger(this.getClass()).debug( "Linking: " + updatedAttributeInstances.get(attributeInstanceId) + " <- " + linkedElement + " * " + this.strHashCode()); return linkedElement; } }