/** * A helper function for derived classes. The mutator/setter method for any ID-typed attributes should call this * method in order to handle getting the old value removed from the ID-to-XMLObject mapping, and the new value added * to the mapping. * * @param oldID the old value of the ID-typed attribute * @param newID the new value of the ID-typed attribute */ protected void registerOwnID(String oldID, String newID) { String newString = DatatypeHelper.safeTrimOrNullString(newID); if (!DatatypeHelper.safeEquals(oldID, newString)) { if (oldID != null) { idIndex.deregisterIDMapping(oldID); } if (newString != null) { idIndex.registerIDMapping(newString, this); } } }
/** * Deregister multiple ID-to-XMLObject mappings for this object's owner's children. * * @param idIndex the ID-to-XMLObject mappings to deregister */ public void deregisterIDMappings(IDIndex idIndex) { if (idIndex == null || idIndex.isEmpty()) { return; } for (String id : idIndex.getIDs()) { idMappings.remove(id); } if (owner.hasParent()) { owner.getParent().getIDIndex().deregisterIDMappings(idIndex); } }
/** * Register multiple ID-to-XMLObject mappings for this object's owner's children. * * @param idIndex the ID-to-XMLObject mapping to register */ public void registerIDMappings(IDIndex idIndex) { if (idIndex == null || idIndex.isEmpty()) { return; } idMappings.putAll(idIndex.getIDMappings()); if (owner.hasParent()) { owner.getParent().getIDIndex().registerIDMappings(idIndex); } }
/** * Replaces the XMLObject at the specified index with the given element. * * @param index index of the XMLObject to be replaced * @param element element to be stored at the given index * * @return the replaced XMLObject * * @throws IllegalArgumentException thrown if the given XMLObject already has a parent that is different from the * XMLObject given at list construction time */ public ElementType set(int index, ElementType element) throws IllegalArgumentException { if (element == null) { return null; } setParent(element); ElementType removedElement = elements.set(index, element); if (removedElement != null) { removedElement.setParent(null); parent.getIDIndex().deregisterIDMappings(removedElement.getIDIndex()); } // Note: to avoid ordering problems, this needs to be called after // the deregistration, in case the added element has a same ID string // value as the removed one, else you will lose it. parent.getIDIndex().registerIDMappings(element.getIDIndex()); modCount++; return removedElement; }
/** * Deregister an attribute as having a type of ID. * * @param attributeName the QName of the ID attribute to be de-registered */ public void deregisterID(QName attributeName) { if (idAttribNames.contains(attributeName)) { idAttribNames.remove(attributeName); } // In case attribute already has a value, // deregister the current value mapping with the XMLObject owner. if (containsKey(attributeName)) { attributeOwner.getIDIndex().deregisterIDMapping(get(attributeName)); } }
/** {@inheritDoc} */ public ElementType remove(int index) { ElementType element = elements.remove(index); if (element != null) { element.releaseParentDOM(true); element.setParent(null); parent.getIDIndex().deregisterIDMappings(element.getIDIndex()); } modCount++; return element; }
/** * Register an attribute as having a type of ID. * * @param attributeName the QName of the ID attribute to be registered */ public void registerID(QName attributeName) { if (! idAttribNames.contains(attributeName)) { idAttribNames.add(attributeName); } // In case attribute already has a value, // register the current value mapping with the XMLObject owner. if (containsKey(attributeName)) { attributeOwner.getIDIndex().registerIDMapping(get(attributeName), attributeOwner); } }
/** {@inheritDoc} */ public XMLObject resolveID(String id) { return idIndex.lookup(id); }
/** * Constructor. * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents * @param namespacePrefix the prefix for the given namespace */ protected AbstractXMLObject(String namespaceURI, String elementLocalName, String namespacePrefix) { nsManager = new NamespaceManager(this); idIndex = new IDIndex(this); elementQname = XMLHelper.constructQName(namespaceURI, elementLocalName, namespacePrefix); if(namespaceURI != null){ setElementNamespacePrefix(namespacePrefix); } }
/** * Adds the given XMLObject to this list. * * @param index index at which to add the given XMLObject * @param element element to be stored at the given index * * @throws IllegalArgumentException thrown if the given XMLObject already has a parent that is different from the * XMLObject given at list construction time */ public void add(int index, ElementType element) throws IllegalArgumentException { if (element == null || elements.contains(element)) { return; } setParent(element); parent.getIDIndex().registerIDMappings(element.getIDIndex()); modCount++; elements.add(index, element); }
releaseThisandParentDOM(); newValue.setParent(this); idIndex.registerIDMappings(newValue.getIDIndex()); return newValue; oldValue.setParent(null); releaseThisandParentDOM(); idIndex.deregisterIDMappings(oldValue.getIDIndex()); if (newValue != null) { newValue.setParent(this); idIndex.registerIDMappings(newValue.getIDIndex());
/** * Deregister an attribute as having a type of ID. * * @param attributeName the QName of the ID attribute to be de-registered */ public void deregisterID(QName attributeName) { if (idAttribNames.contains(attributeName)) { idAttribNames.remove(attributeName); } // In case attribute already has a value, // deregister the current value mapping with the XMLObject owner. if (containsKey(attributeName)) { attributeOwner.getIDIndex().deregisterIDMapping(get(attributeName)); } }
/** {@inheritDoc} */ public ElementType remove(int index) { ElementType element = elements.remove(index); if (element != null) { element.releaseParentDOM(true); element.setParent(null); parent.getIDIndex().deregisterIDMappings(element.getIDIndex()); } modCount++; return element; }
/** * Register an attribute as having a type of ID. * * @param attributeName the QName of the ID attribute to be registered */ public void registerID(QName attributeName) { if (! idAttribNames.contains(attributeName)) { idAttribNames.add(attributeName); } // In case attribute already has a value, // register the current value mapping with the XMLObject owner. if (containsKey(attributeName)) { attributeOwner.getIDIndex().registerIDMapping(get(attributeName), attributeOwner); } }
/** {@inheritDoc} */ public XMLObject resolveID(String id) { return idIndex.lookup(id); }
/** * Constructor. * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents * @param namespacePrefix the prefix for the given namespace */ protected AbstractXMLObject(String namespaceURI, String elementLocalName, String namespacePrefix) { nsManager = new NamespaceManager(this); idIndex = new IDIndex(this); elementQname = XMLHelper.constructQName(namespaceURI, elementLocalName, namespacePrefix); if(namespaceURI != null){ setElementNamespacePrefix(namespacePrefix); } }
/** * Adds the given XMLObject to this list. * * @param index index at which to add the given XMLObject * @param element element to be stored at the given index * * @throws IllegalArgumentException thrown if the given XMLObject already has a parent that is different from the * XMLObject given at list construction time */ public void add(int index, ElementType element) throws IllegalArgumentException { if (element == null || elements.contains(element)) { return; } setParent(element); parent.getIDIndex().registerIDMappings(element.getIDIndex()); modCount++; elements.add(index, element); }
/** * Register multiple ID-to-XMLObject mappings for this object's owner's children. * * @param idIndex the ID-to-XMLObject mapping to register */ public void registerIDMappings(IDIndex idIndex) { if (idIndex == null || idIndex.isEmpty()) { return; } idMappings.putAll(idIndex.getIDMappings()); if (owner.hasParent()) { owner.getParent().getIDIndex().registerIDMappings(idIndex); } }
/** * Deregister multiple ID-to-XMLObject mappings for this object's owner's children. * * @param idIndex the ID-to-XMLObject mappings to deregister */ public void deregisterIDMappings(IDIndex idIndex) { if (idIndex == null || idIndex.isEmpty()) { return; } for (String id : idIndex.getIDs()) { idMappings.remove(id); } if (owner.hasParent()) { owner.getParent().getIDIndex().deregisterIDMappings(idIndex); } }
/** * A helper function for derived classes. The mutator/setter method for any ID-typed attributes should call this * method in order to handle getting the old value removed from the ID-to-XMLObject mapping, and the new value added * to the mapping. * * @param oldID the old value of the ID-typed attribute * @param newID the new value of the ID-typed attribute */ protected void registerOwnID(String oldID, String newID) { String newString = DatatypeHelper.safeTrimOrNullString(newID); if (!DatatypeHelper.safeEquals(oldID, newString)) { if (oldID != null) { idIndex.deregisterIDMapping(oldID); } if (newString != null) { idIndex.registerIDMapping(newString, this); } } }