com.sun.org.apache.xerces.internal.impl.xs.XSAttributeDecl

Here are the examples of the java api class com.sun.org.apache.xerces.internal.impl.xs.XSAttributeDecl taken from open source projects.

1. XSAttributeChecker#checkNonSchemaAttributes()

Project: openjdk
Source File: XSAttributeChecker.java
View license
// validate attriubtes from non-schema namespaces
// REVISIT: why we store the attributes in this way? why not just a list
//          of structure {element node, attr name/qname, attr value)?
// REVISIT: pass the proper element node to reportSchemaError
public void checkNonSchemaAttributes(XSGrammarBucket grammarBucket) {
    // for all attributes
    Iterator entries = fNonSchemaAttrs.entrySet().iterator();
    XSAttributeDecl attrDecl;
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        // get name, uri, localpart
        String attrRName = (String) entry.getKey();
        String attrURI = attrRName.substring(0, attrRName.indexOf(','));
        String attrLocal = attrRName.substring(attrRName.indexOf(',') + 1);
        // find associated grammar
        SchemaGrammar sGrammar = grammarBucket.getGrammar(attrURI);
        if (sGrammar == null) {
            continue;
        }
        // and get the datatype validator, if there is one
        attrDecl = sGrammar.getGlobalAttributeDecl(attrLocal);
        if (attrDecl == null) {
            continue;
        }
        XSSimpleType dv = (XSSimpleType) attrDecl.getTypeDefinition();
        if (dv == null) {
            continue;
        }
        // get all values appeared with this attribute name
        Vector values = (Vector) entry.getValue();
        String elName;
        String attrName = (String) values.elementAt(0);
        // for each of the values
        int count = values.size();
        for (int i = 1; i < count; i += 2) {
            elName = (String) values.elementAt(i);
            try {
                // and validate it using the XSSimpleType
                // REVISIT: what would be the proper validation context?
                //          guess we need to save that in the vectors too.
                dv.validate((String) values.elementAt(i + 1), null, null);
            } catch (InvalidDatatypeValueException ide) {
                reportSchemaError("s4s-att-invalid-value", new Object[] { elName, attrName, ide.getMessage() }, null);
            }
        }
    }
}

2. XSDAttributeTraverser#traverseLocal()

Project: openjdk
Source File: XSDAttributeTraverser.java
View license
protected XSAttributeUseImpl traverseLocal(Element attrDecl, XSDocumentInfo schemaDoc, SchemaGrammar grammar, XSComplexTypeDecl enclosingCT) {
    // General Attribute Checking
    Object[] attrValues = fAttrChecker.checkAttributes(attrDecl, false, schemaDoc);
    String defaultAtt = (String) attrValues[XSAttributeChecker.ATTIDX_DEFAULT];
    String fixedAtt = (String) attrValues[XSAttributeChecker.ATTIDX_FIXED];
    String nameAtt = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
    QName refAtt = (QName) attrValues[XSAttributeChecker.ATTIDX_REF];
    XInt useAtt = (XInt) attrValues[XSAttributeChecker.ATTIDX_USE];
    // get 'attribute declaration'
    XSAttributeDecl attribute = null;
    XSAnnotationImpl annotation = null;
    if (attrDecl.getAttributeNode(SchemaSymbols.ATT_REF) != null) {
        if (refAtt != null) {
            attribute = (XSAttributeDecl) fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTE_TYPE, refAtt, attrDecl);
            Element child = DOMUtil.getFirstChildElement(attrDecl);
            if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
                annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc);
                child = DOMUtil.getNextSiblingElement(child);
            } else {
                String text = DOMUtil.getSyntheticAnnotation(attrDecl);
                if (text != null) {
                    annotation = traverseSyntheticAnnotation(attrDecl, text, attrValues, false, schemaDoc);
                }
            }
            if (child != null) {
                reportSchemaError("src-attribute.3.2", new Object[] { refAtt.rawname }, child);
            }
            // for error reporting
            nameAtt = refAtt.localpart;
        } else {
            attribute = null;
        }
    } else {
        attribute = traverseNamedAttr(attrDecl, attrValues, schemaDoc, grammar, false, enclosingCT);
    }
    // get 'value constraint'
    short consType = XSConstants.VC_NONE;
    if (defaultAtt != null) {
        consType = XSConstants.VC_DEFAULT;
    } else if (fixedAtt != null) {
        consType = XSConstants.VC_FIXED;
        defaultAtt = fixedAtt;
        fixedAtt = null;
    }
    XSAttributeUseImpl attrUse = null;
    if (attribute != null) {
        if (fSchemaHandler.fDeclPool != null) {
            attrUse = fSchemaHandler.fDeclPool.getAttributeUse();
        } else {
            attrUse = new XSAttributeUseImpl();
        }
        attrUse.fAttrDecl = attribute;
        attrUse.fUse = useAtt.shortValue();
        attrUse.fConstraintType = consType;
        if (defaultAtt != null) {
            attrUse.fDefault = new ValidatedInfo();
            attrUse.fDefault.normalizedValue = defaultAtt;
        }
        // Get the annotation associated witht the local attr decl
        if (attrDecl.getAttributeNode(SchemaSymbols.ATT_REF) == null) {
            attrUse.fAnnotations = attribute.getAnnotations();
        } else {
            XSObjectList annotations;
            if (annotation != null) {
                annotations = new XSObjectListImpl();
                ((XSObjectListImpl) annotations).addXSObject(annotation);
            } else {
                annotations = XSObjectListImpl.EMPTY_LIST;
            }
            attrUse.fAnnotations = annotations;
        }
    }
    // 1 default and fixed must not both be present.
    if (defaultAtt != null && fixedAtt != null) {
        reportSchemaError("src-attribute.1", new Object[] { nameAtt }, attrDecl);
    }
    // 2 If default and use are both present, use must have the actual value optional.
    if (consType == XSConstants.VC_DEFAULT && useAtt != null && useAtt.intValue() != SchemaSymbols.USE_OPTIONAL) {
        reportSchemaError("src-attribute.2", new Object[] { nameAtt }, attrDecl);
        // Recover by honouring the default value
        attrUse.fUse = SchemaSymbols.USE_OPTIONAL;
    }
    if (defaultAtt != null && attrUse != null) {
        // 2 if there is a {value constraint}, the canonical lexical representation of its value must be valid with respect to the {type definition} as defined in String Valid (3.14.4).
        fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);
        try {
            checkDefaultValid(attrUse);
        } catch (InvalidDatatypeValueException ide) {
            reportSchemaError(ide.getKey(), ide.getArgs(), attrDecl);
            reportSchemaError("a-props-correct.2", new Object[] { nameAtt, defaultAtt }, attrDecl);
            attrUse.fDefault = null;
            attrUse.fConstraintType = XSConstants.VC_NONE;
        }
        // 3 If the {type definition} is or is derived from ID then there must not be a {value constraint}.
        if (((XSSimpleType) attribute.getTypeDefinition()).isIDType()) {
            reportSchemaError("a-props-correct.3", new Object[] { nameAtt }, attrDecl);
            // Recover by removing the default value
            attrUse.fDefault = null;
            attrUse.fConstraintType = XSConstants.VC_NONE;
        }
        // 2 If the {attribute declaration} has a fixed {value constraint}, then if the attribute use itself has a {value constraint}, it must also be fixed and its value must match that of the {attribute declaration}'s {value constraint}.
        if (attrUse.fAttrDecl.getConstraintType() == XSConstants.VC_FIXED && attrUse.fConstraintType != XSConstants.VC_NONE) {
            if (attrUse.fConstraintType != XSConstants.VC_FIXED || !attrUse.fAttrDecl.getValInfo().actualValue.equals(attrUse.fDefault.actualValue)) {
                reportSchemaError("au-props-correct.2", new Object[] { nameAtt, attrUse.fAttrDecl.getValInfo().stringValue() }, attrDecl);
                // Recover by using the decl's {value constraint}
                attrUse.fDefault = attrUse.fAttrDecl.getValInfo();
                attrUse.fConstraintType = XSConstants.VC_FIXED;
            }
        }
    }
    fAttrChecker.returnAttrArray(attrValues, schemaDoc);
    return attrUse;
}

3. XSDAttributeTraverser#traverseGlobal()

Project: openjdk
Source File: XSDAttributeTraverser.java
View license
protected XSAttributeDecl traverseGlobal(Element attrDecl, XSDocumentInfo schemaDoc, SchemaGrammar grammar) {
    // General Attribute Checking
    Object[] attrValues = fAttrChecker.checkAttributes(attrDecl, true, schemaDoc);
    XSAttributeDecl attribute = traverseNamedAttr(attrDecl, attrValues, schemaDoc, grammar, true, null);
    fAttrChecker.returnAttrArray(attrValues, schemaDoc);
    return attribute;
}

4. XSDHandler#addGlobalAttributeDecls()

Project: openjdk
Source File: XSDHandler.java
View license
private void addGlobalAttributeDecls(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) {
    XSNamedMap components = srcGrammar.getComponents(XSConstants.ATTRIBUTE_DECLARATION);
    int len = components.getLength();
    XSAttributeDecl srcDecl, dstDecl;
    // add global components
    for (int i = 0; i < len; i++) {
        srcDecl = (XSAttributeDecl) components.item(i);
        dstDecl = dstGrammar.getGlobalAttributeDecl(srcDecl.getName());
        if (dstDecl == null) {
            dstGrammar.addGlobalAttributeDecl(srcDecl);
        } else if (dstDecl != srcDecl && !fTolerateDuplicates) {
            reportSharingError(srcDecl.getNamespace(), srcDecl.getName());
        }
    }
    // add any extended (duplicate) global components
    ObjectList componentsExt = srcGrammar.getComponentsExt(XSConstants.ATTRIBUTE_DECLARATION);
    len = componentsExt.getLength();
    for (int i = 0; i < len; i += 2) {
        final String key = (String) componentsExt.item(i);
        final int index = key.indexOf(',');
        final String location = key.substring(0, index);
        final String name = key.substring(index + 1, key.length());
        srcDecl = (XSAttributeDecl) componentsExt.item(i + 1);
        dstDecl = dstGrammar.getGlobalAttributeDecl(name, location);
        if (dstDecl == null) {
            dstGrammar.addGlobalAttributeDecl(srcDecl, location);
        } else // REVISIT - do we report an error?
        if (dstDecl != srcDecl) {
        }
    }
}