FileDocCategorySizeDatePackage
ShortHandPointer.javaAPI DocJava SE 6 API10501Tue Jun 10 00:22:54 BST 2008com.sun.org.apache.xerces.internal.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,v 1.1.4.1 2005/09/08 05:25:44 sunithareddy Exp $

Fields Summary
private String
fShortHandPointer
private boolean
fIsFragmentResolved
private 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(SymbolTable symbolTable)

        fSymbolTable = symbolTable;
    
Methods Summary
public java.lang.StringgetChildrenSchemaDeterminedID(com.sun.org.apache.xerces.internal.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(com.sun.org.apache.xerces.internal.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(com.sun.org.apache.xerces.internal.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
com.sun.org.apache.xerces.internal.xpointer.XPointerPart#getSchemeData()

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

see
com.sun.org.apache.xerces.internal.xpointer.XPointerPart#getSchemeName()

        return fShortHandPointer;
    
private booleanhasMatchingIdentifier(com.sun.org.apache.xerces.internal.xni.QName element, com.sun.org.apache.xerces.internal.xni.XMLAttributes attributes, com.sun.org.apache.xerces.internal.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
com.sun.org.apache.xerces.internal.xpointer.XPointerPart#isChildFragmentResolved()

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

see
com.sun.org.apache.xerces.internal.xpointer.XPointerPart#isFragmentResolved()

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

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

        fShortHandPointer = part;
        // reset fIsFragmentResolved
        fIsFragmentResolved = false;
    
public booleanresolveXPointer(com.sun.org.apache.xerces.internal.xni.QName element, com.sun.org.apache.xerces.internal.xni.XMLAttributes attributes, com.sun.org.apache.xerces.internal.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
com.sun.org.apache.xerces.internal.xpointer.XPointerPart#setSchemeData(java.lang.String)

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

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

        fShortHandPointer = schemeName;