/** * Method used to 'intern()' qualified names; main benefit is reduced * memory usage as the name objects are shared. May also slightly * speed up Map access, as more often identity comparisons catch * matches. *<p> * Note: it is assumed at this point that access is only from a single * thread, and non-recursive -- generally valid assumption as readers are * not shared. Restriction is needed since the method is not re-entrant: * it uses mAccessKey during the method call. */ private PrefixedName findSharedName(String prefix, String localName) { HashMap m = mSharedNames; if (mSharedNames == null) { mSharedNames = m = new HashMap(); } else { // Maybe we already have a shared instance... ? PrefixedName key = mAccessKey; key.reset(prefix, localName); key = (PrefixedName) m.get(key); if (key != null) { // gotcha return key; } } // Not found; let's create, cache and return it: PrefixedName result = new PrefixedName(prefix, localName); m.put(result, result); return result; }
/** * @return True if the set contains specified name; false if not. */ public boolean contains(PrefixedName name) { PrefixedName[] hashArea = mNames; int index = name.hashCode() & (hashArea.length - 1); PrefixedName res = hashArea[index]; if (res != null && res.equals(name)) { return true; } Bucket[] buckets = mBuckets; if (buckets != null) { for (Bucket bucket = buckets[index >> 2]; bucket != null; bucket = bucket.getNext()) { res = bucket.getName(); if (res.equals(name)) { return true; } } } return false; }
public SmallPrefixedNameSet(boolean nsAware, PrefixedName[] names) { mNsAware = nsAware; int len = names.length; if (len == 0) { // sanity check throw new IllegalStateException("Trying to construct empty PrefixedNameSet"); } mStrings = new String[nsAware ? (len+len) : len]; for (int out = 0, in = 0; in < len; ++in) { PrefixedName nk = names[in]; if (nsAware) { mStrings[out++] = nk.getPrefix(); } mStrings[out++] = nk.getLocalName(); } }
if (attrName.isXmlReservedAttr(mCfgNsEnabled, "id")) { if (attrName.isXmlReservedAttr(mCfgNsEnabled, "space")) { checkXmlSpaceAttr(type, enumValues); if (mCfgNsEnabled && attrName.isaNsDeclaration()) { // only check in ns mode
public String tryToValidate(PrefixedName elemName) { if (!elemName.equals(mElemName)) { return "Expected element <"+mElemName+">"; } if (++mCount > 1 && (mArity == '?' || mArity == ' ')) { return "More than one instance of element <"+mElemName+">"; } return null; }
/** * Calling this method before {@link #checkNsDefaults} is necessary * to pass information regarding the current element; although * it will become available later on (via normal XMLValidator interface), * that's too late (after namespace binding and resolving). */ public boolean mayHaveNsDefaults(String elemPrefix, String elemLN) { mTmpKey.reset(elemPrefix, elemLN); DTDElement elem = (DTDElement) mElemSpecs.get(mTmpKey); mCurrElem = elem; return (elem != null) && elem.hasNsDefaults(); }
PrefixedName getAttrPName() { return new PrefixedName(mCurrAttrPrefix, mCurrAttrLocalName); }
PrefixedName getElementPName() { return PrefixedName.valueOf(mContext.getCurrentElementName()); }
int ix = (nk.hashCode() & mask); if (mNames[ix] == null) { // no collision mNames[ix] = nk;
if (attrName.isXmlReservedAttr(mCfgNsEnabled, "id")) { if (attrName.isXmlReservedAttr(mCfgNsEnabled, "space")) { checkXmlSpaceAttr(type, enumValues); if (mCfgNsEnabled && attrName.isaNsDeclaration()) { // only check in ns mode
public String getDisplayName() { return mName.toString(); }
public boolean contains(PrefixedName n) { return mName.equals(n); } }
public String validateAttribute(String localName, String uri, String prefix, char[] valueChars, int valueStart, int valueEnd) throws XMLStreamException { // note: cut'n pasted from above... DTDAttribute attr = (DTDAttribute) mCurrAttrDefs.get(mTmpKey.reset(prefix, localName)); int index = mAttrCount++; if (index >= mAttrSpecs.length) { mAttrSpecs = (DTDAttribute[]) DataUtil.growArrayBy50Pct(mAttrSpecs); } mAttrSpecs[index] = attr; if (attr != null) { if (mHasAttrDefaults) { int specIndex = attr.getSpecialIndex(); if (specIndex >= 0) { mCurrDefaultAttrs.set(specIndex); } } if (mHasNormalizableAttrs) { // may get normalized, after all return attr.normalize(this, valueChars, valueStart, valueEnd); } } return null; // fine as is }
public static PrefixedName valueOf(QName n) { return new PrefixedName(n.getPrefix(), n.getLocalPart()); }
PrefixedName getElementPName() { return PrefixedName.valueOf(mContext.getCurrentElementName()); }
int ix = (nk.hashCode() & mask); if (mNames[ix] == null) { // no collision mNames[ix] = nk;
/** * @return True if the set contains specified name; false if not. */ public boolean contains(PrefixedName name) { int len = mStrings.length; String ln = name.getLocalName(); String[] strs = mStrings; if (mNsAware) { String prefix = name.getPrefix(); if (strs[1] == ln && strs[0] == prefix) { return true; } for (int i = 2; i < len; i += 2) { if (strs[i+1] == ln && strs[i] == prefix) { return true; } } } else { if (strs[0] == ln) { return true; } for (int i = 1; i < len; ++i) { if (strs[i] == ln) { return true; } } } return false; }