Java Code Examples for com.sun.org.apache.xerces.internal.xs.XSTypeDefinition#SIMPLE_TYPE

The following examples show how to use com.sun.org.apache.xerces.internal.xs.XSTypeDefinition#SIMPLE_TYPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XSDAbstractTraverser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Element/Attribute traversers call this method to check whether
 * the type is NOTATION without enumeration facet
 */
void checkNotationType(String refName, XSTypeDefinition typeDecl, Element elem) {
    if (typeDecl.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE &&
            ((XSSimpleType)typeDecl).getVariety() == XSSimpleType.VARIETY_ATOMIC &&
            ((XSSimpleType)typeDecl).getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
        if ((((XSSimpleType)typeDecl).getDefinedFacets() & XSSimpleType.FACET_ENUMERATION) == 0) {
            reportSchemaError("enumeration-required-notation", new Object[]{typeDecl.getName(), refName, DOMUtil.getLocalName(elem)}, elem);
        }
    }
}
 
Example 2
Source File: XSDAbstractTraverser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Element/Attribute traversers call this method to check whether
 * the type is NOTATION without enumeration facet
 */
void checkNotationType(String refName, XSTypeDefinition typeDecl, Element elem) {
    if (typeDecl.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE &&
            ((XSSimpleType)typeDecl).getVariety() == XSSimpleType.VARIETY_ATOMIC &&
            ((XSSimpleType)typeDecl).getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
        if ((((XSSimpleType)typeDecl).getDefinedFacets() & XSSimpleType.FACET_ENUMERATION) == 0) {
            reportSchemaError("enumeration-required-notation", new Object[]{typeDecl.getName(), refName, DOMUtil.getLocalName(elem)}, elem);
        }
    }
}
 
Example 3
Source File: XSConstraints.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * check whether derived is valid derived from base, given a subset
 * of {restriction, extension}.B
 */
public static boolean checkTypeDerivationOk(XSTypeDefinition derived, XSTypeDefinition base, short block) {
    // if derived is anyType, then it's valid only if base is anyType too
    if (derived == SchemaGrammar.fAnyType)
        return derived == base;
    // if derived is anySimpleType, then it's valid only if the base
    // is ur-type
    if (derived == SchemaGrammar.fAnySimpleType) {
        return (base == SchemaGrammar.fAnyType ||
                base == SchemaGrammar.fAnySimpleType);
    }

    // if derived is simple type
    if (derived.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
        // if base is complex type
        if (base.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
            // if base is anyType, change base to anySimpleType,
            // otherwise, not valid
            if (base == SchemaGrammar.fAnyType)
                base = SchemaGrammar.fAnySimpleType;
            else
                return false;
        }
        return checkSimpleDerivation((XSSimpleType)derived,
                (XSSimpleType)base, block);
    }
    else {
        return checkComplexDerivation((XSComplexTypeDecl)derived, base, block);
    }
}
 
Example 4
Source File: XMLSchemaValidator.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
Object elementLocallyValidType(QName element, Object textContent) {
    if (fCurrentType == null)
        return null;

    Object retValue = null;
    // Element Locally Valid (Type)
    // 3 The appropriate case among the following must be true:
    // 3.1 If the type definition is a simple type definition, then all of the following must be true:
    if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
        // 3.1.2 The element information item must have no element information item [children].
        if (fSubElement)
            reportSchemaError("cvc-type.3.1.2", new Object[] { element.rawname });
        // 3.1.3 If clause 3.2 of Element Locally Valid (Element) (3.3.4) did not apply, then the normalized value must be valid with respect to the type definition as defined by String Valid (3.14.4).
        if (!fNil) {
            XSSimpleType dv = (XSSimpleType) fCurrentType;
            try {
                if (!fNormalizeData || fUnionType) {
                    fValidationState.setNormalizationRequired(true);
                }
                retValue = dv.validate(textContent, fValidationState, fValidatedInfo);
            } catch (InvalidDatatypeValueException e) {
                reportSchemaError(e.getKey(), e.getArgs());
                reportSchemaError(
                    "cvc-type.3.1.3",
                    new Object[] { element.rawname, textContent });
            }
        }
    } else {
        // 3.2 If the type definition is a complex type definition, then the element information item must be valid with respect to the type definition as per Element Locally Valid (Complex Type) (3.4.4);
        retValue = elementLocallyValidComplexType(element, textContent);
    }

    return retValue;
}
 
Example 5
Source File: SchemaGrammar.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public synchronized ObjectList getComponentsExt(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return ObjectListImpl.EMPTY_LIST;
    }

    if (fComponentsExt == null)
        fComponentsExt = new ObjectList[MAX_COMP_IDX+1];

    // get the hashtable for this type of components
    if (fComponentsExt[objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGlobalTypeDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGlobalAttrDeclsExt;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGlobalElemDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGlobalAttrGrpDeclsExt;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGlobalGroupDeclsExt;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGlobalNotationDeclsExt;
            break;
        }

        Object[] entries = table.getEntries();
        fComponentsExt[objectType] = new ObjectListImpl(entries, entries.length);
    }

    return fComponentsExt[objectType];
}
 
Example 6
Source File: SubstitutionGroupHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private boolean typeDerivationOK(XSTypeDefinition derived, XSTypeDefinition base, short blockingConstraint) {

        short devMethod = 0, blockConstraint = blockingConstraint;

        // "derived" should be derived from "base"
        // add derivation methods of derived types to devMethod;
        // add block of base types to blockConstraint.
        XSTypeDefinition type = derived;
        while (type != base && type != SchemaGrammar.fAnyType) {
            if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
                devMethod |= ((XSComplexTypeDecl)type).fDerivedBy;
            }
            else {
                devMethod |= XSConstants.DERIVATION_RESTRICTION;
            }
            type = type.getBaseType();
            // type == null means the current type is anySimpleType,
            // whose base type should be anyType
            if (type == null) {
                type = SchemaGrammar.fAnyType;
            }
            if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
                blockConstraint |= ((XSComplexTypeDecl)type).fBlock;
            }
        }
        if (type != base) {
            // If the base is a union, check if "derived" is allowed through any of the member types.
            if (base.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
                XSSimpleTypeDefinition st = (XSSimpleTypeDefinition) base;
                if (st.getVariety() ==  XSSimpleTypeDefinition.VARIETY_UNION) {
                    XSObjectList memberTypes = st.getMemberTypes();
                    final int length = memberTypes.getLength();
                    for (int i = 0; i < length; ++i) {
                        if (typeDerivationOK(derived, (XSTypeDefinition) memberTypes.item(i), blockingConstraint)) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        if ((devMethod & blockConstraint) != 0) {
            return false;
        }
        return true;
    }
 
Example 7
Source File: SchemaGrammar.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * [schema components]: a list of top-level components, i.e. element
 * declarations, attribute declarations, etc.
 * @param objectType The type of the declaration, i.e.
 *   <code>ELEMENT_DECLARATION</code>. Note that
 *   <code>XSTypeDefinition.SIMPLE_TYPE</code> and
 *   <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
 *   <code>objectType</code> to retrieve only complex types or simple
 *   types, instead of all types.
 * @return  A list of top-level definition of the specified type in
 *   <code>objectType</code> or an empty <code>XSNamedMap</code> if no
 *   such definitions exist.
 */
public synchronized XSNamedMap getComponents(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    if (fComponents == null)
        fComponents = new XSNamedMap[MAX_COMP_IDX+1];

    // get the hashtable for this type of components
    if (fComponents[objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGlobalTypeDecls;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGlobalAttrDecls;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGlobalElemDecls;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGlobalAttrGrpDecls;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGlobalGroupDecls;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGlobalNotationDecls;
            break;
        }

        // for complex/simple types, create a special implementation,
        // which take specific types out of the hash table
        if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
            objectType == XSTypeDefinition.SIMPLE_TYPE) {
            fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType);
        }
        else {
            fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table);
        }
    }

    return fComponents[objectType];
}
 
Example 8
Source File: XSModelImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a list of top-level components, i.e. element declarations,
 * attribute declarations, etc.
 * @param objectType The type of the declaration, i.e.
 *   <code>ELEMENT_DECLARATION</code>. Note that
 *   <code>XSTypeDefinition.SIMPLE_TYPE</code> and
 *   <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
 *   <code>objectType</code> to retrieve only complex types or simple
 *   types, instead of all types.
 * @return  A list of top-level definitions of the specified type in
 *   <code>objectType</code> or an empty <code>XSNamedMap</code> if no
 *   such definitions exist.
 */
public synchronized XSNamedMap getComponents(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    SymbolHash[] tables = new SymbolHash[fGrammarCount];
    // get all hashtables from all namespaces for this type of components
    if (fGlobalComponents[objectType] == null) {
        for (int i = 0; i < fGrammarCount; i++) {
            switch (objectType) {
            case XSConstants.TYPE_DEFINITION:
            case XSTypeDefinition.COMPLEX_TYPE:
            case XSTypeDefinition.SIMPLE_TYPE:
                tables[i] = fGrammarList[i].fGlobalTypeDecls;
                break;
            case XSConstants.ATTRIBUTE_DECLARATION:
                tables[i] = fGrammarList[i].fGlobalAttrDecls;
                break;
            case XSConstants.ELEMENT_DECLARATION:
                tables[i] = fGrammarList[i].fGlobalElemDecls;
                break;
            case XSConstants.ATTRIBUTE_GROUP:
                tables[i] = fGrammarList[i].fGlobalAttrGrpDecls;
                break;
            case XSConstants.MODEL_GROUP_DEFINITION:
                tables[i] = fGrammarList[i].fGlobalGroupDecls;
                break;
            case XSConstants.NOTATION_DECLARATION:
                tables[i] = fGrammarList[i].fGlobalNotationDecls;
                break;
            }
        }
        // for complex/simple types, create a special implementation,
        // which take specific types out of the hash table
        if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
            objectType == XSTypeDefinition.SIMPLE_TYPE) {
            fGlobalComponents[objectType] = new XSNamedMap4Types(fNamespaces, tables, fGrammarCount, objectType);
        }
        else {
            fGlobalComponents[objectType] = new XSNamedMapImpl(fNamespaces, tables, fGrammarCount);
        }
    }

    return fGlobalComponents[objectType];
}
 
Example 9
Source File: SchemaGrammar.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * [schema components]: a list of top-level components, i.e. element
 * declarations, attribute declarations, etc.
 * @param objectType The type of the declaration, i.e.
 *   <code>ELEMENT_DECLARATION</code>. Note that
 *   <code>XSTypeDefinition.SIMPLE_TYPE</code> and
 *   <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
 *   <code>objectType</code> to retrieve only complex types or simple
 *   types, instead of all types.
 * @return  A list of top-level definition of the specified type in
 *   <code>objectType</code> or an empty <code>XSNamedMap</code> if no
 *   such definitions exist.
 */
public synchronized XSNamedMap getComponents(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    if (fComponents == null)
        fComponents = new XSNamedMap[MAX_COMP_IDX+1];

    // get the hashtable for this type of components
    if (fComponents[objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGlobalTypeDecls;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGlobalAttrDecls;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGlobalElemDecls;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGlobalAttrGrpDecls;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGlobalGroupDecls;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGlobalNotationDecls;
            break;
        case XSConstants.IDENTITY_CONSTRAINT:
            table = this.fGlobalIDConstraintDecls;
            break;
        }

        // for complex/simple types, create a special implementation,
        // which take specific types out of the hash table
        if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
            objectType == XSTypeDefinition.SIMPLE_TYPE) {
            fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType);
        }
        else {
            fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table);
        }
    }

    return fComponents[objectType];
}
 
Example 10
Source File: XSModelImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convenience method. Returns a list of top-level component declarations
 * that are defined within the specified namespace, i.e. element
 * declarations, attribute declarations, etc.
 * @param objectType The type of the declaration, i.e.
 *   <code>ELEMENT_DECLARATION</code>.
 * @param namespace The namespace to which the declaration belongs or
 *   <code>null</code> (for components with no target namespace).
 * @return  A list of top-level definitions of the specified type in
 *   <code>objectType</code> and defined in the specified
 *   <code>namespace</code> or an empty <code>XSNamedMap</code>.
 */
public synchronized XSNamedMap getComponentsByNamespace(short objectType,
                                                        String namespace) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    // try to find the grammar
    int i = 0;
    if (namespace != null) {
        for (; i < fGrammarCount; ++i) {
            if (namespace.equals(fNamespaces[i])) {
                break;
            }
        }
    }
    else {
        for (; i < fGrammarCount; ++i) {
            if (fNamespaces[i] == null) {
                break;
            }
        }
    }
    if (i == fGrammarCount) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    // get the hashtable for this type of components
    if (fNSComponents[i][objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGrammarList[i].fGlobalTypeDecls;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGrammarList[i].fGlobalAttrDecls;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGrammarList[i].fGlobalElemDecls;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGrammarList[i].fGlobalAttrGrpDecls;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGrammarList[i].fGlobalGroupDecls;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGrammarList[i].fGlobalNotationDecls;
            break;
        }

        // for complex/simple types, create a special implementation,
        // which take specific types out of the hash table
        if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
            objectType == XSTypeDefinition.SIMPLE_TYPE) {
            fNSComponents[i][objectType] = new XSNamedMap4Types(namespace, table, objectType);
        }
        else {
            fNSComponents[i][objectType] = new XSNamedMapImpl(namespace, table);
        }
    }

    return fNSComponents[i][objectType];
}
 
Example 11
Source File: XSConstraints.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Note: this will be a private method, and it assumes that derived is not
 *       anyType. Another method will be introduced for public use,
 *       which will call this method.
 */
private static boolean checkComplexDerivation(XSComplexTypeDecl derived, XSTypeDefinition base, short block) {
    // 2.1 B and D must be the same type definition.
    if (derived == base)
        return true;

    // 1 If B and D are not the same type definition, then the {derivation method} of D must not be in the subset.
    if ((derived.fDerivedBy & block) != 0)
        return false;

    // 2 One of the following must be true:
    XSTypeDefinition directBase = derived.fBaseType;
    // 2.2 B must be D's {base type definition}.
    if (directBase == base)
        return true;

    // 2.3 All of the following must be true:
    // 2.3.1 D's {base type definition} must not be the ur-type definition.
    if (directBase == SchemaGrammar.fAnyType ||
            directBase == SchemaGrammar.fAnySimpleType) {
        return false;
    }

    // 2.3.2 The appropriate case among the following must be true:
    // 2.3.2.1 If D's {base type definition} is complex, then it must be validly derived from B given the subset as defined by this constraint.
    if (directBase.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
        return checkComplexDerivation((XSComplexTypeDecl)directBase, base, block);

    // 2.3.2.2 If D's {base type definition} is simple, then it must be validly derived from B given the subset as defined in Type Derivation OK (Simple) (3.14.6).
    if (directBase.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
        // if base is complex type
        if (base.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
            // if base is anyType, change base to anySimpleType,
            // otherwise, not valid
            if (base == SchemaGrammar.fAnyType)
                base = SchemaGrammar.fAnySimpleType;
            else
                return false;
        }
        return checkSimpleDerivation((XSSimpleType)directBase,
                (XSSimpleType)base, block);
    }

    return false;
}
 
Example 12
Source File: XSModelImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convenience method. Returns a list of top-level component declarations
 * that are defined within the specified namespace, i.e. element
 * declarations, attribute declarations, etc.
 * @param objectType The type of the declaration, i.e.
 *   <code>ELEMENT_DECLARATION</code>.
 * @param namespace The namespace to which the declaration belongs or
 *   <code>null</code> (for components with no target namespace).
 * @return  A list of top-level definitions of the specified type in
 *   <code>objectType</code> and defined in the specified
 *   <code>namespace</code> or an empty <code>XSNamedMap</code>.
 */
public synchronized XSNamedMap getComponentsByNamespace(short objectType,
                                                        String namespace) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    // try to find the grammar
    int i = 0;
    if (namespace != null) {
        for (; i < fGrammarCount; ++i) {
            if (namespace.equals(fNamespaces[i])) {
                break;
            }
        }
    }
    else {
        for (; i < fGrammarCount; ++i) {
            if (fNamespaces[i] == null) {
                break;
            }
        }
    }
    if (i == fGrammarCount) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    // get the hashtable for this type of components
    if (fNSComponents[i][objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGrammarList[i].fGlobalTypeDecls;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGrammarList[i].fGlobalAttrDecls;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGrammarList[i].fGlobalElemDecls;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGrammarList[i].fGlobalAttrGrpDecls;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGrammarList[i].fGlobalGroupDecls;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGrammarList[i].fGlobalNotationDecls;
            break;
        }

        // for complex/simple types, create a special implementation,
        // which take specific types out of the hash table
        if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
            objectType == XSTypeDefinition.SIMPLE_TYPE) {
            fNSComponents[i][objectType] = new XSNamedMap4Types(namespace, table, objectType);
        }
        else {
            fNSComponents[i][objectType] = new XSNamedMapImpl(namespace, table);
        }
    }

    return fNSComponents[i][objectType];
}
 
Example 13
Source File: SubstitutionGroupHandler.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private boolean typeDerivationOK(XSTypeDefinition derived, XSTypeDefinition base, short blockingConstraint) {

        short devMethod = 0, blockConstraint = blockingConstraint;

        // "derived" should be derived from "base"
        // add derivation methods of derived types to devMethod;
        // add block of base types to blockConstraint.
        XSTypeDefinition type = derived;
        while (type != base && type != SchemaGrammar.fAnyType) {
            if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
                devMethod |= ((XSComplexTypeDecl)type).fDerivedBy;
            }
            else {
                devMethod |= XSConstants.DERIVATION_RESTRICTION;
            }
            type = type.getBaseType();
            // type == null means the current type is anySimpleType,
            // whose base type should be anyType
            if (type == null) {
                type = SchemaGrammar.fAnyType;
            }
            if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
                blockConstraint |= ((XSComplexTypeDecl)type).fBlock;
            }
        }
        if (type != base) {
            // If the base is a union, check if "derived" is allowed through any of the member types.
            if (base.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
                XSSimpleTypeDefinition st = (XSSimpleTypeDefinition) base;
                if (st.getVariety() ==  XSSimpleTypeDefinition.VARIETY_UNION) {
                    XSObjectList memberTypes = st.getMemberTypes();
                    final int length = memberTypes.getLength();
                    for (int i = 0; i < length; ++i) {
                        if (typeDerivationOK(derived, (XSTypeDefinition) memberTypes.item(i), blockingConstraint)) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        if ((devMethod & blockConstraint) != 0) {
            return false;
        }
        return true;
    }
 
Example 14
Source File: XSModelImpl.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a list of top-level components, i.e. element declarations,
 * attribute declarations, etc.
 * @param objectType The type of the declaration, i.e.
 *   <code>ELEMENT_DECLARATION</code>. Note that
 *   <code>XSTypeDefinition.SIMPLE_TYPE</code> and
 *   <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
 *   <code>objectType</code> to retrieve only complex types or simple
 *   types, instead of all types.
 * @return  A list of top-level definitions of the specified type in
 *   <code>objectType</code> or an empty <code>XSNamedMap</code> if no
 *   such definitions exist.
 */
public synchronized XSNamedMap getComponents(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    SymbolHash[] tables = new SymbolHash[fGrammarCount];
    // get all hashtables from all namespaces for this type of components
    if (fGlobalComponents[objectType] == null) {
        for (int i = 0; i < fGrammarCount; i++) {
            switch (objectType) {
            case XSConstants.TYPE_DEFINITION:
            case XSTypeDefinition.COMPLEX_TYPE:
            case XSTypeDefinition.SIMPLE_TYPE:
                tables[i] = fGrammarList[i].fGlobalTypeDecls;
                break;
            case XSConstants.ATTRIBUTE_DECLARATION:
                tables[i] = fGrammarList[i].fGlobalAttrDecls;
                break;
            case XSConstants.ELEMENT_DECLARATION:
                tables[i] = fGrammarList[i].fGlobalElemDecls;
                break;
            case XSConstants.ATTRIBUTE_GROUP:
                tables[i] = fGrammarList[i].fGlobalAttrGrpDecls;
                break;
            case XSConstants.MODEL_GROUP_DEFINITION:
                tables[i] = fGrammarList[i].fGlobalGroupDecls;
                break;
            case XSConstants.NOTATION_DECLARATION:
                tables[i] = fGrammarList[i].fGlobalNotationDecls;
                break;
            }
        }
        // for complex/simple types, create a special implementation,
        // which take specific types out of the hash table
        if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
            objectType == XSTypeDefinition.SIMPLE_TYPE) {
            fGlobalComponents[objectType] = new XSNamedMap4Types(fNamespaces, tables, fGrammarCount, objectType);
        }
        else {
            fGlobalComponents[objectType] = new XSNamedMapImpl(fNamespaces, tables, fGrammarCount);
        }
    }

    return fGlobalComponents[objectType];
}
 
Example 15
Source File: XSModelImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convenience method. Returns a list of top-level component declarations
 * that are defined within the specified namespace, i.e. element
 * declarations, attribute declarations, etc.
 * @param objectType The type of the declaration, i.e.
 *   <code>ELEMENT_DECLARATION</code>.
 * @param namespace The namespace to which the declaration belongs or
 *   <code>null</code> (for components with no target namespace).
 * @return  A list of top-level definitions of the specified type in
 *   <code>objectType</code> and defined in the specified
 *   <code>namespace</code> or an empty <code>XSNamedMap</code>.
 */
public synchronized XSNamedMap getComponentsByNamespace(short objectType,
                                                        String namespace) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    // try to find the grammar
    int i = 0;
    if (namespace != null) {
        for (; i < fGrammarCount; ++i) {
            if (namespace.equals(fNamespaces[i])) {
                break;
            }
        }
    }
    else {
        for (; i < fGrammarCount; ++i) {
            if (fNamespaces[i] == null) {
                break;
            }
        }
    }
    if (i == fGrammarCount) {
        return XSNamedMapImpl.EMPTY_MAP;
    }

    // get the hashtable for this type of components
    if (fNSComponents[i][objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGrammarList[i].fGlobalTypeDecls;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGrammarList[i].fGlobalAttrDecls;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGrammarList[i].fGlobalElemDecls;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGrammarList[i].fGlobalAttrGrpDecls;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGrammarList[i].fGlobalGroupDecls;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGrammarList[i].fGlobalNotationDecls;
            break;
        }

        // for complex/simple types, create a special implementation,
        // which take specific types out of the hash table
        if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
            objectType == XSTypeDefinition.SIMPLE_TYPE) {
            fNSComponents[i][objectType] = new XSNamedMap4Types(namespace, table, objectType);
        }
        else {
            fNSComponents[i][objectType] = new XSNamedMapImpl(namespace, table);
        }
    }

    return fNSComponents[i][objectType];
}
 
Example 16
Source File: XSConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void checkNameAndTypeOK(XSElementDecl dElement, int dMin, int dMax,
        XSElementDecl bElement, int bMin, int bMax)
    throws XMLSchemaException {


    //
    // Check that the names are the same
    //
    if (dElement.fName != bElement.fName ||
            dElement.fTargetNamespace != bElement.fTargetNamespace) {
        throw new XMLSchemaException(
                "rcase-NameAndTypeOK.1",new Object[]{dElement.fName,
                        dElement.fTargetNamespace, bElement.fName, bElement.fTargetNamespace});
    }

    //
    // Check nillable
    //
    if (!bElement.getNillable() && dElement.getNillable()) {
        throw new XMLSchemaException("rcase-NameAndTypeOK.2",
                new Object[]{dElement.fName});
    }

    //
    // Check occurrence range
    //
    if (!checkOccurrenceRange(dMin, dMax, bMin, bMax)) {
        throw new XMLSchemaException("rcase-NameAndTypeOK.3",
                new Object[]{
                dElement.fName,
                Integer.toString(dMin),
                dMax==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(dMax),
                        Integer.toString(bMin),
                        bMax==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(bMax)});
    }

    //
    // Check for consistent fixed values
    //
    if (bElement.getConstraintType() == XSConstants.VC_FIXED) {
        // derived one has to have a fixed value
        if (dElement.getConstraintType() != XSConstants.VC_FIXED) {
            throw new XMLSchemaException("rcase-NameAndTypeOK.4.a",
                    new Object[]{dElement.fName, bElement.fDefault.stringValue()});
        }

        // get simple type
        boolean isSimple = false;
        if (dElement.fType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE ||
                ((XSComplexTypeDecl)dElement.fType).fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) {
            isSimple = true;
        }

        // if there is no simple type, then compare based on string
        if (!isSimple && !bElement.fDefault.normalizedValue.equals(dElement.fDefault.normalizedValue) ||
                isSimple && !bElement.fDefault.actualValue.equals(dElement.fDefault.actualValue)) {
            throw new XMLSchemaException("rcase-NameAndTypeOK.4.b",
                    new Object[]{dElement.fName,
                    dElement.fDefault.stringValue(),
                    bElement.fDefault.stringValue()});
        }
    }

    //
    // Check identity constraints
    //
    checkIDConstraintRestriction(dElement, bElement);

    //
    // Check for disallowed substitutions
    //
    int blockSet1 = dElement.fBlock;
    int blockSet2 = bElement.fBlock;
    if (((blockSet1 & blockSet2)!=blockSet2) ||
            (blockSet1==XSConstants.DERIVATION_NONE && blockSet2!=XSConstants.DERIVATION_NONE))
        throw new XMLSchemaException("rcase-NameAndTypeOK.6",
                new Object[]{dElement.fName});


    //
    // Check that the derived element's type is derived from the base's.
    //
    if (!checkTypeDerivationOk(dElement.fType, bElement.fType,
            (short)(XSConstants.DERIVATION_EXTENSION|XSConstants.DERIVATION_LIST|XSConstants.DERIVATION_UNION))) {
        throw new XMLSchemaException("rcase-NameAndTypeOK.7",
                new Object[]{dElement.fName, dElement.fType.getName(), bElement.fType.getName()});
    }

}
 
Example 17
Source File: SchemaGrammar.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public synchronized ObjectList getComponentsExt(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return ObjectListImpl.EMPTY_LIST;
    }

    if (fComponentsExt == null)
        fComponentsExt = new ObjectList[MAX_COMP_IDX+1];

    // get the hashtable for this type of components
    if (fComponentsExt[objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGlobalTypeDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGlobalAttrDeclsExt;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGlobalElemDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGlobalAttrGrpDeclsExt;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGlobalGroupDeclsExt;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGlobalNotationDeclsExt;
            break;
        }

        Object[] entries = table.getEntries();
        fComponentsExt[objectType] = new ObjectListImpl(entries, entries.length);
    }

    return fComponentsExt[objectType];
}
 
Example 18
Source File: SchemaGrammar.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public synchronized ObjectList getComponentsExt(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return ObjectListImpl.EMPTY_LIST;
    }

    if (fComponentsExt == null)
        fComponentsExt = new ObjectList[MAX_COMP_IDX+1];

    // get the hashtable for this type of components
    if (fComponentsExt[objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGlobalTypeDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGlobalAttrDeclsExt;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGlobalElemDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGlobalAttrGrpDeclsExt;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGlobalGroupDeclsExt;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGlobalNotationDeclsExt;
            break;
        }

        Object[] entries = table.getEntries();
        fComponentsExt[objectType] = new ObjectListImpl(entries, entries.length);
    }

    return fComponentsExt[objectType];
}
 
Example 19
Source File: XSDSimpleTypeTraverser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private XSSimpleType findDTValidator(Element elm, String refName,
        QName baseTypeStr, short baseRefContext,
        XSDocumentInfo schemaDoc) {
    if (baseTypeStr == null)
        return null;

    XSTypeDefinition baseType = (XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.TYPEDECL_TYPE, baseTypeStr, elm);
    if (baseType == null) {
        return null;
    }
    if (baseType.getTypeCategory() != XSTypeDefinition.SIMPLE_TYPE) {
        reportSchemaError("cos-st-restricts.1.1", new Object[]{baseTypeStr.rawname, refName}, elm);
        return null;
    }

    // if it's a complex type, or if its restriction of anySimpleType
    if (baseType == SchemaGrammar.fAnySimpleType &&
        baseRefContext == XSConstants.DERIVATION_RESTRICTION) {
        // if the base type is anySimpleType and the current type is
        // a S4S built-in type, return null. (not an error).
        if (checkBuiltIn(refName, schemaDoc.fTargetNamespace)) {
            return null;
        }
        reportSchemaError("cos-st-restricts.1.1", new Object[]{baseTypeStr.rawname, refName}, elm);
        return null;
    }

    if ((baseType.getFinal() & baseRefContext) != 0) {
        if (baseRefContext == XSConstants.DERIVATION_RESTRICTION) {
            reportSchemaError("st-props-correct.3", new Object[]{refName, baseTypeStr.rawname}, elm);
        }
        else if (baseRefContext == XSConstants.DERIVATION_LIST) {
            reportSchemaError("cos-st-restricts.2.3.1.1", new Object[]{baseTypeStr.rawname, refName}, elm);
        }
        else if (baseRefContext == XSConstants.DERIVATION_UNION) {
            reportSchemaError("cos-st-restricts.3.3.1.1", new Object[]{baseTypeStr.rawname, refName}, elm);
        }
        return null;
    }

    return (XSSimpleType)baseType;
}
 
Example 20
Source File: SchemaGrammar.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public synchronized ObjectList getComponentsExt(short objectType) {
    if (objectType <= 0 || objectType > MAX_COMP_IDX ||
        !GLOBAL_COMP[objectType]) {
        return ObjectListImpl.EMPTY_LIST;
    }

    if (fComponentsExt == null)
        fComponentsExt = new ObjectList[MAX_COMP_IDX+1];

    // get the hashtable for this type of components
    if (fComponentsExt[objectType] == null) {
        SymbolHash table = null;
        switch (objectType) {
        case XSConstants.TYPE_DEFINITION:
        case XSTypeDefinition.COMPLEX_TYPE:
        case XSTypeDefinition.SIMPLE_TYPE:
            table = fGlobalTypeDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_DECLARATION:
            table = fGlobalAttrDeclsExt;
            break;
        case XSConstants.ELEMENT_DECLARATION:
            table = fGlobalElemDeclsExt;
            break;
        case XSConstants.ATTRIBUTE_GROUP:
            table = fGlobalAttrGrpDeclsExt;
            break;
        case XSConstants.MODEL_GROUP_DEFINITION:
            table = fGlobalGroupDeclsExt;
            break;
        case XSConstants.NOTATION_DECLARATION:
            table = fGlobalNotationDeclsExt;
            break;
        }

        Object[] entries = table.getEntries();
        fComponentsExt[objectType] = new ObjectListImpl(entries, entries.length);
    }

    return fComponentsExt[objectType];
}