xmlattributesimpl.java
来自「JAVA 所有包」· Java 代码 · 共 1,168 行 · 第 1/3 页
JAVA
1,168 行
* * @return the name of a duplicate attribute found in the search, * otherwise null. */ public QName checkDuplicatesNS() { // If the list is small check for duplicates using pairwise comparison. if (fLength <= SIZE_LIMIT) { for (int i = 0; i < fLength - 1; ++i) { Attribute att1 = fAttributes[i]; for (int j = i + 1; j < fLength; ++j) { Attribute att2 = fAttributes[j]; if (att1.name.localpart == att2.name.localpart && att1.name.uri == att2.name.uri) { return att2.name; } } } } // If the list is large check duplicates using a hash table. else { // We don't want this table view to be read if someone calls // addAttribute so we invalidate it up front. fIsTableViewConsistent = false; prepareTableView(); Attribute attr; int bucket; for (int i = fLength - 1; i >= 0; --i) { attr = fAttributes[i]; bucket = getTableViewBucket(attr.name.localpart, attr.name.uri); // The chain is stale. // This must be a unique attribute. if (fAttributeTableViewChainState[bucket] != fLargeCount) { fAttributeTableViewChainState[bucket] = fLargeCount; attr.next = null; fAttributeTableView[bucket] = attr; } // This chain is active. // We need to check if any of the attributes has the same name. else { // Search the table. Attribute found = fAttributeTableView[bucket]; while (found != null) { if (found.name.localpart == attr.name.localpart && found.name.uri == attr.name.uri) { return attr.name; } found = found.next; } // Update table view attr.next = fAttributeTableView[bucket]; fAttributeTableView[bucket] = attr; } } } return null; } /** * Look up the index of an attribute by Namespace name. * <p> * <strong>Note:</strong> * This method uses reference comparison, and thus should * only be used internally. We cannot use this method in any * code exposed to users as they may not pass in unique strings. * * @param uri The Namespace URI, or null if * the name has no Namespace URI. * @param localName The attribute's local name. * @return The index of the attribute, or -1 if it does not * appear in the list. */ public int getIndexFast(String uri, String localPart) { for (int i = 0; i < fLength; ++i) { Attribute attribute = fAttributes[i]; if (attribute.name.localpart == localPart && attribute.name.uri == uri) { return i; } } return -1; } // getIndexFast(String,String):int /** * Returns the value passed in or NMTOKEN if it's an enumerated type. * * @param type attribute type * @return the value passed in or NMTOKEN if it's an enumerated type. */ private String getReportableType(String type) { if (type.charAt(0) == '(') { return "NMTOKEN"; } return type; } /** * Returns the position in the table view * where the given attribute name would be hashed. * * @param qname the attribute name * @return the position in the table view where the given attribute * would be hashed */ protected int getTableViewBucket(String qname) { return (qname.hashCode() & 0x7FFFFFFF) % fTableViewBuckets; } /** * Returns the position in the table view * where the given attribute name would be hashed. * * @param localpart the local part of the attribute * @param uri the namespace name of the attribute * @return the position in the table view where the given attribute * would be hashed */ protected int getTableViewBucket(String localpart, String uri) { if (uri == null) { return (localpart.hashCode() & 0x7FFFFFFF) % fTableViewBuckets; } else { return ((localpart.hashCode() + uri.hashCode()) & 0x7FFFFFFF) % fTableViewBuckets; } } /** * Purges all elements from the table view. */ protected void cleanTableView() { if (++fLargeCount < 0) { // Overflow. We actually need to visit the chain state array. if (fAttributeTableViewChainState != null) { for (int i = fTableViewBuckets - 1; i >= 0; --i) { fAttributeTableViewChainState[i] = 0; } } fLargeCount = 1; } } /** * Prepares the table view of the attributes list for use. */ protected void prepareTableView() { if (fAttributeTableView == null) { fAttributeTableView = new Attribute[fTableViewBuckets]; fAttributeTableViewChainState = new int[fTableViewBuckets]; } else { cleanTableView(); } } /** * Prepares the table view of the attributes list for use, * and populates it with the attributes which have been * previously read. */ protected void prepareAndPopulateTableView() { prepareTableView(); // Need to populate the hash table with the attributes we've scanned so far. Attribute attr; int bucket; for (int i = 0; i < fLength; ++i) { attr = fAttributes[i]; bucket = getTableViewBucket(attr.name.rawname); if (fAttributeTableViewChainState[bucket] != fLargeCount) { fAttributeTableViewChainState[bucket] = fLargeCount; attr.next = null; fAttributeTableView[bucket] = attr; } else { // Update table view attr.next = fAttributeTableView[bucket]; fAttributeTableView[bucket] = attr; } } } /** * Returns the prefix of the attribute at the specified index. * * @param index The index of the attribute. */ public String getPrefix(int index) { if (index < 0 || index >= fLength) { return null; } String prefix = fAttributes[index].name.prefix; // REVISIT: The empty string is not entered in the symbol table! return prefix != null ? prefix : ""; } // getPrefix(int):String /** * Look up an attribute's Namespace URI by index. * * @param index The attribute index (zero-based). * @return The Namespace URI * @see #getLength */ public String getURI(int index) { if (index < 0 || index >= fLength) { return null; } String uri = fAttributes[index].name.uri; return uri; } // getURI(int):String /** * Look up an attribute's value by Namespace name. * * <p>See {@link #getValue(int) getValue(int)} for a description * of the possible values.</p> * * @param uri The Namespace URI, or null if the * @param localName The local name of the attribute. * @return The attribute value as a string, or null if the * attribute is not in the list. */ public String getValue(String uri, String localName) { int index = getIndex(uri, localName); return index != -1 ? getValue(index) : null; } // getValue(String,String):String /** * Look up an augmentations by Namespace name. * * @param uri The Namespace URI, or null if the * @param localName The local name of the attribute. * @return Augmentations */ public Augmentations getAugmentations (String uri, String localName) { int index = getIndex(uri, localName); return index != -1 ? fAttributes[index].augs : null; } /** * Look up an augmentation by XML 1.0 qualified name. * <p> * * @param qName The XML 1.0 qualified name. * * @return Augmentations * */ public Augmentations getAugmentations(String qName){ int index = getIndex(qName); return index != -1 ? fAttributes[index].augs : null; } /** * Look up an augmentations by attributes index. * * @param attributeIndex The attribute index. * @return Augmentations */ public Augmentations getAugmentations (int attributeIndex){ if (attributeIndex < 0 || attributeIndex >= fLength) { return null; } return fAttributes[attributeIndex].augs; } /** * Sets the augmentations of the attribute at the specified index. * * @param attrIndex The attribute index. * @param augs The augmentations. */ public void setAugmentations(int attrIndex, Augmentations augs) { fAttributes[attrIndex].augs = augs; } /** * Sets the uri of the attribute at the specified index. * * @param attrIndex The attribute index. * @param uri Namespace uri */ public void setURI(int attrIndex, String uri) { fAttributes[attrIndex].name.uri = uri; } // getURI(int,QName) // Implementation methods public void setSchemaId(int attrIndex, boolean schemaId) { fAttributes[attrIndex].schemaId = schemaId; } public boolean getSchemaId(int index) { if (index < 0 || index >= fLength) { return false; } return fAttributes[index].schemaId; } public boolean getSchemaId(String qname) { int index = getIndex(qname); return index != -1 ? fAttributes[index].schemaId : false; } // getType(String):String public boolean getSchemaId(String uri, String localName) { if (!fNamespaces) { return false; } int index = getIndex(uri, localName); return index != -1 ? fAttributes[index].schemaId : false; } // getType(String,String):String //XMLBufferListener methods /** * This method will be invoked by XMLEntityReader before ScannedEntities buffer * is reloaded. */ public void refresh() { if(fLength > 0){ for(int i = 0 ; i < fLength ; i++){ getValue(i); } } } public void refresh(int pos) { } // // Classes // /** * Attribute information. * * @author Andy Clark, IBM */ static class Attribute { // // Data // // basic info /** Name. */ public QName name = new QName(); /** Type. */ public String type; /** Value. */ public String value; /** This will point to the ScannedEntities buffer.*/ public XMLString xmlValue; /** Non-normalized value. */ public String nonNormalizedValue; /** Specified. */ public boolean specified; /** Schema ID type. */ public boolean schemaId; /** * Augmentations information for this attribute. * XMLAttributes has no knowledge if any augmentations * were attached to Augmentations. */ public Augmentations augs = new AugmentationsImpl(); // Additional data for attribute table view /** Pointer to the next attribute in the chain. **/ public Attribute next; } // class Attribute} // class XMLAttributesImpl
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?