当前位置: 首页>>代码示例>>Java>>正文


Java XSSimpleType.validate方法代码示例

本文整理汇总了Java中org.apache.xerces.impl.dv.XSSimpleType.validate方法的典型用法代码示例。如果您正苦于以下问题:Java XSSimpleType.validate方法的具体用法?Java XSSimpleType.validate怎么用?Java XSSimpleType.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.xerces.impl.dv.XSSimpleType的用法示例。


在下文中一共展示了XSSimpleType.validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: elementLocallyValidType

import org.apache.xerces.impl.dv.XSSimpleType; //导入方法依赖的package包/类
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;
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:35,代码来源:XMLSchemaValidator.java

示例2: validateString

import org.apache.xerces.impl.dv.XSSimpleType; //导入方法依赖的package包/类
/**
 * this method shows how to validate the content against the given simple type.
 *
 * @param String content to validate
 * @param XSSimpleType SimpleType Definition schema component against which to validate the content.
 *
 * @return ValidatedInfo validatedInfo object.
 */
public ValidatedInfo validateString(String content, XSSimpleType simpleType){

    //create an instance of 'ValidatedInfo' to get back information (like actual value,
    //normalizedValue etc..)after content is validated.
    ValidatedInfo validatedInfo = new ValidatedInfo();

        //get proper validation context , this is very important we need to get appropriate validation context while validating content
        //validation context passed is generally different while validating content and  creating simple type (applyFacets)
        ValidationContext validationState = getValidationContext();

    try{
        simpleType.validate(content, validationState, validatedInfo);
    }catch(InvalidDatatypeValueException ex){
        System.err.println(ex.getMessage());
    }

    //now 'validatedInfo' object contains information

    // for number types (decimal, double, float, and types derived from them),
    // Object return is BigDecimal, Double, Float respectively.
    // for some types (string and derived), they just return the string itself
    Object value = validatedInfo.actualValue;
    //so returned Object can be casted to actual java object like..
    //Boolean booleanDT = (Boolean)value;

    //The normalized value of a string value
    String normalizedValue = validatedInfo.normalizedValue ;

    //If the type is a union type, then the member type which
    //actually validated the string value.
    XSSimpleType memberType = validatedInfo.memberType ;

    return validatedInfo;

}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:44,代码来源:SimpleTypeUsage.java

示例3: checkNonSchemaAttributes

import org.apache.xerces.impl.dv.XSSimpleType; //导入方法依赖的package包/类
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);
            }
        }
    }
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:47,代码来源:XSAttributeChecker.java

示例4: elementLocallyValidComplexType

import org.apache.xerces.impl.dv.XSSimpleType; //导入方法依赖的package包/类
Object elementLocallyValidComplexType(QName element, Object textContent) {
    Object actualValue = null;
    XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;

    // Element Locally Valid (Complex Type)
    // For an element information item to be locally valid with respect to a complex type definition all of the following must be true:
    // 1 {abstract} is false.
    // 2 If clause 3.2 of Element Locally Valid (Element) (3.3.4) did not apply, then the appropriate case among the following must be true:
    if (!fNil) {
        // 2.1 If the {content type} is empty, then the element information item has no character or element information item [children].
        if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_EMPTY
            && (fSubElement || fSawText)) {
            reportSchemaError("cvc-complex-type.2.1", new Object[] { element.rawname });
        }
        // 2.2 If the {content type} is a simple type definition, then the element information item has no element information item [children], and the normalized value of the element information item is valid with respect to that simple type definition as defined by String Valid (3.14.4).
        else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) {
            if (fSubElement)
                reportSchemaError("cvc-complex-type.2.2", new Object[] { element.rawname });
            XSSimpleType dv = ctype.fXSSimpleType;
            try {
                if (!fNormalizeData || fUnionType) {
                    fValidationState.setNormalizationRequired(true);
                }
                actualValue = dv.validate(textContent, fValidationState, fValidatedInfo);
            } catch (InvalidDatatypeValueException e) {
                reportSchemaError(e.getKey(), e.getArgs());
                reportSchemaError("cvc-complex-type.2.2", new Object[] { element.rawname });
            }
            // REVISIT: eventually, this method should return the same actualValue as elementLocallyValidType...
            // obviously it'll return null when the content is complex.
        }
        // 2.3 If the {content type} is element-only, then the element information item has no character information item [children] other than those whose [character code] is defined as a white space in [XML 1.0 (Second Edition)].
        else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
            if (fSawCharacters) {
                reportSchemaError("cvc-complex-type.2.3", new Object[] { element.rawname });
            }
        }
        // 2.4 If the {content type} is element-only or mixed, then the sequence of the element information item's element information item [children], if any, taken in order, is valid with respect to the {content type}'s particle, as defined in Element Sequence Locally Valid (Particle) (3.9.4).
        if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT
            || ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED) {
            // if the current state is a valid state, check whether
            // it's one of the final states.
            if (DEBUG) {
                System.out.println(fCurrCMState);
            }
            if (fCurrCMState[0] >= 0 && !fCurrentCM.endContentModel(fCurrCMState)) {
                String expected = expectedStr(fCurrentCM.whatCanGoHere(fCurrCMState));
                final int[] occurenceInfo = fCurrentCM.occurenceInfo(fCurrCMState);
                if (occurenceInfo != null) {
                    final int minOccurs = occurenceInfo[0];
                    final int count = occurenceInfo[2];
                    // Check if this is a violation of minOccurs
                    if (count < minOccurs) {
                        final int required = minOccurs - count;
                        if (required > 1) {
                            reportSchemaError("cvc-complex-type.2.4.j", new Object[] { element.rawname, 
                                    fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs), Integer.toString(required) });
                        }
                        else {
                            reportSchemaError("cvc-complex-type.2.4.i", new Object[] { element.rawname, 
                                    fCurrentCM.getTermName(occurenceInfo[3]), Integer.toString(minOccurs) });
                        }
                    }
                    else {
                        reportSchemaError("cvc-complex-type.2.4.b", new Object[] { element.rawname, expected });
                    }
                }
                else {
                    reportSchemaError("cvc-complex-type.2.4.b", new Object[] { element.rawname, expected });
                }
            }
        }
    }
    return actualValue;
}
 
开发者ID:AaronZhangL,项目名称:SplitCharater,代码行数:76,代码来源:XMLSchemaValidator.java


注:本文中的org.apache.xerces.impl.dv.XSSimpleType.validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。