FileDocCategorySizeDatePackage
ShortHandPointer.javaAPI DocApache Xerces 3.0.110612Fri Sep 14 20:33:56 BST 2007org.apache.xerces.xpointer

ShortHandPointer

public class ShortHandPointer extends Object implements XPointerPart

Implements the XPointerPart interface and handles processing of ShortHand Pointers. It identifies at most one element in the resource's information set; specifically, the first one (if any) in document order that has a matching NCName as an identifier.

version
$Id: ShortHandPointer.java 447248 2006-09-18 05:25:21Z mrglavas $

Fields Summary
private String
fShortHandPointer
private boolean
fIsFragmentResolved
private org.apache.xerces.util.SymbolTable
fSymbolTable
int
fMatchingChildCount
Resolves the XPointer ShortHand pointer based on the rules defined in Section 3.2 of the XPointer Framework Recommendation. Note that in the current implementation only supports DTD determined ID's.
Constructors Summary
public ShortHandPointer()

    
    //
    // Constructors
    //
      
    
public ShortHandPointer(org.apache.xerces.util.SymbolTable symbolTable)

        fSymbolTable = symbolTable;
    
Methods Summary
public java.lang.StringgetChildrenSchemaDeterminedID(org.apache.xerces.xni.XMLAttributes attributes, int index)
Not quite sure how this can be correctly implemented.

param
attributes
param
index
return
String - We return null since we currenly do not supprt this.
throws
XNIException

        return null;
    
public java.lang.StringgetDTDDeterminedID(org.apache.xerces.xni.XMLAttributes attributes, int index)
Rerturns the DTD determine-ID

param
attributes
param
index
return
String
throws
XNIException

        
        if (attributes.getType(index).equals("ID")) {
            return attributes.getValue(index);
        }
        return null;
    
public java.lang.StringgetSchemaDeterminedID(org.apache.xerces.xni.XMLAttributes attributes, int index)
Returns the schema-determined-ID.

param
attributes
param
index
return
A String containing the schema-determined ID.
throws
XNIException

        Augmentations augs = attributes.getAugmentations(index);
        AttributePSVI attrPSVI = (AttributePSVI) augs
        .getItem(Constants.ATTRIBUTE_PSVI);
        
        if (attrPSVI != null) {
            // An element or attribute information item is a schema-determined 
            // ID if and only if one of the following is true:]
            
            // 1. It has a [member type definition] or [type definition] property 
            // whose value in turn has [name] equal to ID and [target namespace] 
            // equal to http://www.w3.org/2001/XMLSchema;
            
            // 2. It has a [base type definition] whose value has that [name] and [target namespace];
            
            // 3. It has a [base type definition] whose value has a [base type definition] 
            // whose value has that [name] and [target namespace], and so on following 
            // the [base type definition] property recursively;
            
            XSTypeDefinition typeDef = attrPSVI.getMemberTypeDefinition();
            if (typeDef != null) {
                typeDef = attrPSVI.getTypeDefinition();
            }
            
            // 
            if (typeDef != null && ((XSSimpleType) typeDef).isIDType()) {
                return attrPSVI.getSchemaNormalizedValue();
            }
            
            // 4 & 5 NA
        }
        
        return null;
    
public java.lang.StringgetSchemeData()

see
org.apache.xerces.xpointer.XPointerPart#getSchemeData()

        return null;
    
public java.lang.StringgetSchemeName()
Returns the name of the ShortHand pointer

see
org.apache.xerces.xpointer.XPointerPart#getSchemeName()

        return fShortHandPointer;
    
private booleanhasMatchingIdentifier(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs, int event)

param
element
param
attributes
param
augs
param
event
return
throws
XNIException

        String normalizedValue = null;
        
        // The identifiers of an element are determined by the 
        // ShortHand Pointer as follows:
        
        if (attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                
                // 1. If an element information item has an attribute information item 
                // among its [attributes] that is a schema-determined ID, then it is 
                // identified by the value of that attribute information item's 
                // [schema normalized value] property;
                normalizedValue = getSchemaDeterminedID(attributes, i);
                if (normalizedValue != null) {
                    break;
                }
                
                // 2. If an element information item has an element information item among 
                // its [children] that is a schema-determined ID, then it is identified by 
                // the value of that element information item's [schema normalized value] property;
                // ???
                normalizedValue = getChildrenSchemaDeterminedID(attributes, i);
                if (normalizedValue != null) {
                    break;
                }
                
                // 3. If an element information item has an attribute information item among 
                // its [attributes] that is a DTD-determined ID, then it is identified by the 
                // value of that attribute information item's [normalized value] property.
                // An attribute information item is a DTD-determined ID if and only if it has 
                // a [type definition] property whose value is equal to ID.
                normalizedValue = getDTDDeterminedID(attributes, i);
                if (normalizedValue != null) {
                    break;
                }
                // 4. No externally determined ID's
            }
        }
        
        if (normalizedValue != null
                && normalizedValue.equals(fShortHandPointer)) {
            return true;
        }
        
        return false;
    
public booleanisChildFragmentResolved()

see
org.apache.xerces.xpointer.XPointerPart#isChildFragmentResolved()

        return fIsFragmentResolved && (fMatchingChildCount > 0);
    
public booleanisFragmentResolved()

see
org.apache.xerces.xpointer.XPointerPart#isFragmentResolved()

        return fIsFragmentResolved;
    
public voidparseXPointer(java.lang.String part)
The XPointerProcessor takes care of this. Simply set the ShortHand Pointer here.

see
org.apache.xerces.xpointer.XPointerPart#parseXPointer(java.lang.String)

        fShortHandPointer = part;
        // reset fIsFragmentResolved
        fIsFragmentResolved = false;
    
public booleanresolveXPointer(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs, int event)

         
                  

        // reset fIsFragmentResolved
        if (fMatchingChildCount == 0) {
            fIsFragmentResolved = false;
        }

        // On startElement or emptyElement, if no matching elements or parent 
        // elements were found, check for a matching idenfitier.
        if (event == XPointerPart.EVENT_ELEMENT_START) {
            if (fMatchingChildCount == 0) {
                fIsFragmentResolved = hasMatchingIdentifier(element, attributes, augs,
                    event);
            }
            if (fIsFragmentResolved) {
               fMatchingChildCount++;
            }
        } else if (event == XPointerPart.EVENT_ELEMENT_EMPTY) {
            if (fMatchingChildCount == 0) {
                fIsFragmentResolved = hasMatchingIdentifier(element, attributes, augs,
                    event);
            }
        }
        else {
            // On endElement, decrease the matching child count if the child or
            // its parent was resolved.
            if (fIsFragmentResolved) {
                fMatchingChildCount--;
            }
        }
        
        return fIsFragmentResolved ;
    
public voidsetSchemeData(java.lang.String schemeData)

see
org.apache.xerces.xpointer.XPointerPart#setSchemeData(java.lang.String)

        // NA
    
public voidsetSchemeName(java.lang.String schemeName)

see
org.apache.xerces.xpointer.XPointerPart#setSchemeName(java.lang.String)

        fShortHandPointer = schemeName;