Search in sources :

Example 1 with XmlSchemaMaxLengthFacet

use of org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet in project hale by halestudio.

the class XmlTypeUtil method configureSimpleTypeRestriction.

/**
 * Configure a type definition for a simple type based on a simple type
 * restriction.
 *
 * @param type the type definition
 * @param restriction the simple type restriction
 * @param index the XML index for resolving type definitions
 * @param reporter the report
 */
private static void configureSimpleTypeRestriction(XmlTypeDefinition type, XmlSchemaSimpleTypeRestriction restriction, XmlIndex index, IOReporter reporter) {
    QName baseTypeName = restriction.getBaseTypeName();
    XmlTypeDefinition baseTypeDef;
    if (baseTypeName != null) {
        // resolve super type
        baseTypeDef = index.getOrCreateType(baseTypeName);
    } else if (restriction.getBaseType() != null) {
        // simple schema type
        XmlSchemaSimpleType simpleType = restriction.getBaseType();
        // create an anonymous type
        QName anonymousName = new QName(type.getName().getNamespaceURI() + "/" + type.getName().getLocalPart(), // $NON-NLS-1$
        "AnonymousSuperType");
        baseTypeDef = new AnonymousXmlType(anonymousName);
        XmlTypeUtil.configureSimpleType(type, simpleType, index, reporter);
        // no schema location available at this point
        final String schemaLoc = null;
        // set metadata
        XmlSchemaReader.setMetadata(type, simpleType, schemaLoc, index);
    } else {
        reporter.error(new IOMessageImpl("Simple type restriction without base type, skipping type configuration.", null, restriction.getLineNumber(), restriction.getLinePosition()));
        return;
    }
    // set super type
    type.setSuperType(baseTypeDef);
    // mark as restriction
    type.setConstraint(RestrictionFlag.ENABLED);
    // assign no binding, inherit from super type
    // The following code expects schema to be valid.
    List<Validator> validators = new LinkedList<Validator>();
    // patterns and enumerations in one step are ORed together!
    List<String> values = new LinkedList<String>();
    List<Validator> patternValidators = new LinkedList<Validator>();
    // TODO different handling for date/time/g.../duration in
    // (min|max)(In|Ex)clusive
    // XXX only for date, time, duration, dateTime, gMonthDay, gYearMonth?
    // no also for some cases of gYear, gMonth, gDay (they can have a
    // timezone!)
    // but only need to handle cases where isDecimal() is false...
    XmlSchemaObjectCollection facets = restriction.getFacets();
    for (int i = 0; i < facets.getCount(); i++) {
        XmlSchemaFacet facet = (XmlSchemaFacet) facets.getItem(i);
        if (facet instanceof XmlSchemaEnumerationFacet) {
            values.add(facet.getValue().toString());
        } else if (facet instanceof XmlSchemaFractionDigitsFacet) {
            validators.add(new DigitCountValidator(DigitCountValidator.Type.FRACTIONDIGITS, Integer.parseInt(facet.getValue().toString())));
        } else if (facet instanceof XmlSchemaLengthFacet) {
            validators.add(new LengthValidator(LengthValidator.Type.EXACT, Integer.parseInt(facet.getValue().toString())));
        } else if (facet instanceof XmlSchemaMaxExclusiveFacet) {
            if (// number or date?
            isDecimal(facet.getValue().toString()))
                validators.add(new NumberValidator(NumberValidator.Type.MAXEXCLUSIVE, new BigDecimal(facet.getValue().toString())));
            else
                reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
        } else if (facet instanceof XmlSchemaMaxInclusiveFacet) {
            if (// number or date?
            isDecimal(facet.getValue().toString()))
                validators.add(new NumberValidator(NumberValidator.Type.MAXINCLUSIVE, new BigDecimal(facet.getValue().toString())));
            else
                reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
        } else if (facet instanceof XmlSchemaMaxLengthFacet) {
            validators.add(new LengthValidator(LengthValidator.Type.MAXIMUM, Integer.parseInt(facet.getValue().toString())));
        } else if (facet instanceof XmlSchemaMinLengthFacet) {
            validators.add(new LengthValidator(LengthValidator.Type.MINIMUM, Integer.parseInt(facet.getValue().toString())));
        } else if (facet instanceof XmlSchemaMinExclusiveFacet) {
            if (// number or date?
            isDecimal(facet.getValue().toString()))
                validators.add(new NumberValidator(NumberValidator.Type.MINEXCLUSIVE, new BigDecimal(facet.getValue().toString())));
            else
                reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
        } else if (facet instanceof XmlSchemaMinInclusiveFacet) {
            if (// number or date?
            isDecimal(facet.getValue().toString()))
                validators.add(new NumberValidator(NumberValidator.Type.MININCLUSIVE, new BigDecimal(facet.getValue().toString())));
            else
                reporter.warn(new IOMessageImpl("(min|max)(In|Ex)clusive not supported for non-number types", null, facet.getLineNumber(), facet.getLinePosition()));
        } else if (facet instanceof XmlSchemaPatternFacet) {
            patternValidators.add(new PatternValidator(facet.getValue().toString()));
        } else if (facet instanceof XmlSchemaTotalDigitsFacet) {
            validators.add(new DigitCountValidator(DigitCountValidator.Type.TOTALDIGITS, Integer.parseInt(facet.getValue().toString())));
        } else if (facet instanceof XmlSchemaWhiteSpaceFacet) {
            reporter.info(new IOMessageImpl("White space facet not supported", null, facet.getLineNumber(), facet.getLinePosition()));
        // Nothing to validate according to w3.
        // Values should be processed according to rule?
        } else {
            reporter.error(new IOMessageImpl("Unrecognized facet: " + facet.getClass().getSimpleName(), null, facet.getLineNumber(), facet.getLinePosition()));
        }
    }
    if (!patternValidators.isEmpty())
        validators.add(new OrValidator(patternValidators));
    if (!values.isEmpty()) {
        // set enumeration constraint
        // no check of which values are okay, they must be validated
        // somewhere else.
        // XXX conversion to be done?
        type.setConstraint(new Enumeration<String>(values, false));
        validators.add(new EnumerationValidator(values));
    }
    if (!validators.isEmpty())
        type.setConstraint(new ValidationConstraint(new AndValidator(validators), type));
}
Also used : LengthValidator(eu.esdihumboldt.util.validator.LengthValidator) AndValidator(eu.esdihumboldt.util.validator.AndValidator) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) XmlSchemaPatternFacet(org.apache.ws.commons.schema.XmlSchemaPatternFacet) XmlSchemaFractionDigitsFacet(org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet) NumberValidator(eu.esdihumboldt.util.validator.NumberValidator) UnionValidationConstraint(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint) ValidationConstraint(eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint) XmlSchemaMinExclusiveFacet(org.apache.ws.commons.schema.XmlSchemaMinExclusiveFacet) OrValidator(eu.esdihumboldt.util.validator.OrValidator) XmlSchemaEnumerationFacet(org.apache.ws.commons.schema.XmlSchemaEnumerationFacet) PatternValidator(eu.esdihumboldt.util.validator.PatternValidator) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) XmlSchemaFacet(org.apache.ws.commons.schema.XmlSchemaFacet) DigitCountValidator(eu.esdihumboldt.util.validator.DigitCountValidator) XmlSchemaMinInclusiveFacet(org.apache.ws.commons.schema.XmlSchemaMinInclusiveFacet) QName(javax.xml.namespace.QName) LinkedList(java.util.LinkedList) UnionValidationConstraint(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) ValidationConstraint(eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint) XmlSchemaMaxExclusiveFacet(org.apache.ws.commons.schema.XmlSchemaMaxExclusiveFacet) BigDecimal(java.math.BigDecimal) XmlSchemaTotalDigitsFacet(org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet) XmlSchemaMaxInclusiveFacet(org.apache.ws.commons.schema.XmlSchemaMaxInclusiveFacet) EnumerationValidator(eu.esdihumboldt.util.validator.EnumerationValidator) XmlSchemaMinLengthFacet(org.apache.ws.commons.schema.XmlSchemaMinLengthFacet) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaLengthFacet(org.apache.ws.commons.schema.XmlSchemaLengthFacet) EnumerationValidator(eu.esdihumboldt.util.validator.EnumerationValidator) NumberValidator(eu.esdihumboldt.util.validator.NumberValidator) PatternValidator(eu.esdihumboldt.util.validator.PatternValidator) LengthValidator(eu.esdihumboldt.util.validator.LengthValidator) OrValidator(eu.esdihumboldt.util.validator.OrValidator) AndValidator(eu.esdihumboldt.util.validator.AndValidator) Validator(eu.esdihumboldt.util.validator.Validator) DigitCountValidator(eu.esdihumboldt.util.validator.DigitCountValidator) XmlSchemaMaxLengthFacet(org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet) XmlSchemaWhiteSpaceFacet(org.apache.ws.commons.schema.XmlSchemaWhiteSpaceFacet)

Example 2 with XmlSchemaMaxLengthFacet

use of org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet in project cxf by apache.

the class WSDLToCorbaHelper method processSimpleRestrictionType.

private CorbaType processSimpleRestrictionType(XmlSchemaSimpleType stype, QName name, QName schematypeName, boolean anonymous) throws Exception {
    CorbaType corbaTypeImpl;
    // checks if enumeration
    XmlSchemaSimpleTypeRestriction restrictionType = (XmlSchemaSimpleTypeRestriction) stype.getContent();
    QName baseName = checkPrefix(restrictionType.getBaseTypeName());
    String maxLength = null;
    String length = null;
    for (XmlSchemaFacet val : restrictionType.getFacets()) {
        if (val instanceof XmlSchemaMaxLengthFacet) {
            maxLength = val.getValue().toString();
        }
        if (val instanceof XmlSchemaLengthFacet) {
            length = val.getValue().toString();
        }
    }
    if (isEnumeration(restrictionType)) {
        corbaTypeImpl = createCorbaEnum(restrictionType, name, schematypeName);
    } else {
        if (restrictionType.getBaseType() != null) {
            corbaTypeImpl = convertSchemaToCorbaType(restrictionType.getBaseType(), schematypeName, stype, null, false);
        } else {
            corbaTypeImpl = processPrimitiveType(baseName);
            if (corbaTypeImpl == null) {
                XmlSchemaType schematype = findSchemaType(baseName);
                corbaTypeImpl = convertSchemaToCorbaType(schematype, schematypeName, schematype, null, false);
            }
        }
        if (corbaTypeImpl != null) {
            if (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_STRING) || (baseName.equals(W3CConstants.NT_SCHEMA_STRING))) {
                corbaTypeImpl = WSDLTypes.processStringType(corbaTypeImpl, name, maxLength, length);
            } else if (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_DECIMAL) || (baseName.equals(W3CConstants.NT_SCHEMA_DECIMAL))) {
                corbaTypeImpl = WSDLTypes.processDecimalType(restrictionType, name, corbaTypeImpl, anonymous);
            } else if ((corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_BASE64)) || (baseName.equals(W3CConstants.NT_SCHEMA_BASE64)) || (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_HBIN))) {
                corbaTypeImpl = WSDLTypes.processBase64Type(corbaTypeImpl, name, maxLength, length);
            }
        }
    }
    return corbaTypeImpl;
}
Also used : XmlSchemaFacet(org.apache.ws.commons.schema.XmlSchemaFacet) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) QName(javax.xml.namespace.QName) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) XmlSchemaLengthFacet(org.apache.ws.commons.schema.XmlSchemaLengthFacet) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaMaxLengthFacet(org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet)

Example 3 with XmlSchemaMaxLengthFacet

use of org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet in project cxf by apache.

the class StringVisitor method visitBoundedString.

private void visitBoundedString() {
    // xmlschema:bounded string
    XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(schema, true);
    simpleType.setName(stringScopedName.toString());
    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
    restriction.setBaseTypeName(Constants.XSD_STRING);
    XmlSchemaMaxLengthFacet maxLengthFacet = new XmlSchemaMaxLengthFacet();
    maxLengthFacet.setValue(boundNode.toString());
    restriction.getFacets().add(maxLengthFacet);
    simpleType.setContent(restriction);
    setSchemaType(simpleType);
    Scope anonstringScopedName = new Scope(getScope(), "_Anon1_" + stringScopedName.tail());
    String anonstringName = anonstringScopedName.toString();
    final CorbaType anon;
    if (stringNode.getType() == IDLTokenTypes.LITERAL_string) {
        // corba:anonstring
        Anonstring anonstring = new Anonstring();
        anonstring.setQName(new QName(typeMap.getTargetNamespace(), anonstringName));
        anonstring.setBound(Long.parseLong(boundNode.toString()));
        anonstring.setType(simpleType.getQName());
        anon = anonstring;
    } else if (stringNode.getType() == IDLTokenTypes.LITERAL_wstring) {
        // corba:anonwstring
        Anonwstring anonwstring = new Anonwstring();
        anonwstring.setQName(new QName(typeMap.getTargetNamespace(), anonstringName));
        anonwstring.setBound(Long.valueOf(boundNode.toString()));
        anonwstring.setType(simpleType.getQName());
        anon = anonwstring;
    } else {
        // should never get here
        throw new RuntimeException("StringVisitor attempted to visit an invalid node");
    }
    // add corba:anonstring
    typeMap.getStructOrExceptionOrUnion().add(anon);
    // corba:alias
    Alias alias = new Alias();
    alias.setQName(new QName(typeMap.getTargetNamespace(), stringScopedName.toString()));
    alias.setBasetype(anon.getQName());
    alias.setType(simpleType.getQName());
    alias.setRepositoryID(stringScopedName.toIDLRepositoryID());
    // add corba:alias
    setCorbaType(alias);
}
Also used : CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Anonwstring(org.apache.cxf.binding.corba.wsdl.Anonwstring) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) Alias(org.apache.cxf.binding.corba.wsdl.Alias) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) XmlSchemaMaxLengthFacet(org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet) Anonstring(org.apache.cxf.binding.corba.wsdl.Anonstring)

Example 4 with XmlSchemaMaxLengthFacet

use of org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet in project cxf by apache.

the class StringVisitor method visitAnonBoundedString.

private void visitAnonBoundedString() {
    // xmlschema:bounded anon string
    XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(schema, true);
    simpleType.setName(stringScopedName.toString());
    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
    restriction.setBaseTypeName(Constants.XSD_STRING);
    XmlSchemaMaxLengthFacet maxLengthFacet = new XmlSchemaMaxLengthFacet();
    maxLengthFacet.setValue(boundNode.toString());
    restriction.getFacets().add(maxLengthFacet);
    simpleType.setContent(restriction);
    setSchemaType(simpleType);
    final CorbaType anon;
    if (stringNode.getType() == IDLTokenTypes.LITERAL_string) {
        // corba:anonstring
        Anonstring anonstring = new Anonstring();
        anonstring.setQName(new QName(typeMap.getTargetNamespace(), stringScopedName.toString()));
        anonstring.setBound(Long.parseLong(boundNode.toString()));
        anonstring.setType(simpleType.getQName());
        anon = anonstring;
    } else if (stringNode.getType() == IDLTokenTypes.LITERAL_wstring) {
        // corba:anonwstring
        Anonwstring anonwstring = new Anonwstring();
        anonwstring.setQName(new QName(typeMap.getTargetNamespace(), stringScopedName.toString()));
        anonwstring.setBound(Long.parseLong(boundNode.toString()));
        anonwstring.setType(simpleType.getQName());
        anon = anonwstring;
    } else {
        // should never get here
        throw new RuntimeException("StringVisitor attempted to visit an invalid node");
    }
    // add corba:anonstring
    typeMap.getStructOrExceptionOrUnion().add(anon);
    setCorbaType(anon);
}
Also used : CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) Anonwstring(org.apache.cxf.binding.corba.wsdl.Anonwstring) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) XmlSchemaMaxLengthFacet(org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet) Anonstring(org.apache.cxf.binding.corba.wsdl.Anonstring)

Aggregations

QName (javax.xml.namespace.QName)4 XmlSchemaMaxLengthFacet (org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet)4 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)3 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)3 XmlSchemaSimpleTypeRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction)3 Anonstring (org.apache.cxf.binding.corba.wsdl.Anonstring)2 Anonwstring (org.apache.cxf.binding.corba.wsdl.Anonwstring)2 XmlSchemaFacet (org.apache.ws.commons.schema.XmlSchemaFacet)2 XmlSchemaLengthFacet (org.apache.ws.commons.schema.XmlSchemaLengthFacet)2 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 TypeConstraint (eu.esdihumboldt.hale.common.schema.model.TypeConstraint)1 ValidationConstraint (eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint)1 UnionValidationConstraint (eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint)1 AndValidator (eu.esdihumboldt.util.validator.AndValidator)1 DigitCountValidator (eu.esdihumboldt.util.validator.DigitCountValidator)1 EnumerationValidator (eu.esdihumboldt.util.validator.EnumerationValidator)1 LengthValidator (eu.esdihumboldt.util.validator.LengthValidator)1 NumberValidator (eu.esdihumboldt.util.validator.NumberValidator)1 OrValidator (eu.esdihumboldt.util.validator.OrValidator)1 PatternValidator (eu.esdihumboldt.util.validator.PatternValidator)1