Search in sources :

Example 1 with XmlSchemaTotalDigitsFacet

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

the class WSDLTypes method processDecimalType.

public static CorbaType processDecimalType(XmlSchemaSimpleTypeRestriction restrictionType, QName name, CorbaType corbaTypeImpl, boolean anonymous) throws Exception {
    String tdigits = null;
    String fdigits = null;
    boolean boundedDecimal = false;
    boolean boundedScale = false;
    for (XmlSchemaFacet val : restrictionType.getFacets()) {
        if (val instanceof XmlSchemaTotalDigitsFacet) {
            tdigits = val.getValue().toString();
            boundedDecimal = true;
        }
        if (val instanceof XmlSchemaFractionDigitsFacet) {
            fdigits = val.getValue().toString();
            boundedScale = true;
        }
    }
    int digits = 0;
    int scale = 0;
    if (boundedDecimal) {
        try {
            digits = Integer.parseInt(tdigits);
            if ((digits > 31) || (digits < 1)) {
                String msg = "totalDigits facet for the type " + name + " cannot be more than 31 for corba fixed types";
                LOG.log(Level.WARNING, msg);
                boundedDecimal = false;
            } else if (digits == 31) {
                boundedDecimal = false;
            }
        } catch (NumberFormatException ex) {
            String msg = "totalDigits facet on the simple type restriction for type" + name.getLocalPart() + "is incorrect.";
            throw new Exception(msg);
        }
    }
    if (boundedScale) {
        try {
            scale = Integer.parseInt(fdigits);
            if ((scale > 6) || (scale < 0)) {
                String msg = "fixedDigits facet for the type " + name + " cannot be more than 6 for corba fixed types";
                LOG.log(Level.WARNING, msg);
                boundedScale = false;
            } else if (scale == 6) {
                boundedScale = false;
            }
        } catch (NumberFormatException ex) {
            String msg = "fractionDigits facet on the simple type restriction for type" + name.getLocalPart() + " is incorrect.";
            throw new Exception(msg);
        }
    }
    if (!boundedDecimal) {
        if (anonymous && corbaTypeImpl instanceof Anonfixed) {
            Anonfixed fixed = (Anonfixed) corbaTypeImpl;
            digits = Integer.parseInt(String.valueOf(fixed.getDigits()));
        } else if (corbaTypeImpl instanceof Fixed) {
            Fixed fixed = (Fixed) corbaTypeImpl;
            digits = Integer.parseInt(String.valueOf(fixed.getDigits()));
        }
    }
    if (!boundedScale) {
        if (anonymous) {
            Anonfixed fixed = (Anonfixed) corbaTypeImpl;
            scale = Integer.parseInt(String.valueOf(fixed.getScale()));
        } else {
            Fixed fixed = (Fixed) corbaTypeImpl;
            scale = Integer.parseInt(String.valueOf(fixed.getScale()));
        }
    }
    if (boundedDecimal || boundedScale) {
        if (anonymous) {
            corbaTypeImpl = getAnonFixedCorbaType(name, W3CConstants.NT_SCHEMA_DECIMAL, digits, scale);
        } else {
            corbaTypeImpl = getFixedCorbaType(name, W3CConstants.NT_SCHEMA_DECIMAL, digits, scale);
        }
    }
    return corbaTypeImpl;
}
Also used : XmlSchemaFacet(org.apache.ws.commons.schema.XmlSchemaFacet) Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) XmlSchemaTotalDigitsFacet(org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet) XmlSchemaFractionDigitsFacet(org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed)

Example 2 with XmlSchemaTotalDigitsFacet

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

the class FixedVisitor method visit.

public void visit(AST fixedNode) {
    // "typedef" <type_declarator>
    // <type_declarator> ::= <type_spec> <declarators>
    // <type_spec> ::= <simple_type_spec>
    // | <constr_type_spec>
    // <simple_type_spec> ::= <base_type_spec>
    // | <template_type_spec>
    // | <scoped_name>
    // <base_type_spec> ::= ... omitted (integer, char, octect, etc)
    // <template_type_spec> ::= <sequence_type>
    // | <string_type>
    // | <wstring_type>
    // | <fixed_pt_type>
    // <constr_type_spec> ::= <struct_type>
    // | <union_type>
    // | <enum_type>
    // <declarators> ::= <declarator> {"," <declarator>}*
    // <declarator> ::= <simple_declarator>
    // | <complex_declarator>
    // <simple_declarator> ::= <identifier>
    // <complex_declarator> ::= <array_declarator>
    // <array_declarator> ::= <identifier> <fixed_array_size>+
    // <fixed_array_size> ::= "[" <positive_int_const> "]"
    AST digitsNode = fixedNode.getFirstChild();
    AST scaleNode = digitsNode.getNextSibling();
    Scope scopedName = null;
    if (identifierNode == null) {
        scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema);
    } else {
        scopedName = new Scope(getScope(), identifierNode);
    }
    // validate digits and scale
    Long digits = Long.valueOf(digitsNode.toString());
    Long scale = Long.valueOf(scaleNode.toString());
    if (digits < 1 || digits > 31) {
        // throw IllegalIDLException();
        System.out.println("Digits cannot be greater than 31");
        return;
    }
    if (scale.compareTo(digits) > 0) {
        // throw IllegalIDLException();
        System.out.println("Scale cannot be greater than digits");
        return;
    }
    // xmlschema:fixed
    XmlSchemaSimpleType fixedSimpleType = new XmlSchemaSimpleType(schema, true);
    XmlSchemaSimpleTypeRestriction fixedRestriction = new XmlSchemaSimpleTypeRestriction();
    fixedRestriction.setBaseTypeName(Constants.XSD_DECIMAL);
    XmlSchemaTotalDigitsFacet fixedTotalDigits = new XmlSchemaTotalDigitsFacet();
    fixedTotalDigits.setValue(digitsNode.toString());
    XmlSchemaFractionDigitsFacet fixedFractionDigits = new XmlSchemaFractionDigitsFacet();
    fixedFractionDigits.setValue(scaleNode.toString());
    fixedFractionDigits.setFixed(true);
    fixedRestriction.getFacets().add(fixedTotalDigits);
    fixedRestriction.getFacets().add(fixedFractionDigits);
    fixedSimpleType.setName(mapper.mapToQName(scopedName));
    fixedSimpleType.setContent(fixedRestriction);
    // add xmlschema:fixed
    setSchemaType(fixedSimpleType);
    CorbaType type = null;
    if (identifierNode != null) {
        // corba:fixed
        Fixed corbaFixed = new Fixed();
        corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
        corbaFixed.setDigits(digits);
        corbaFixed.setScale(scale);
        corbaFixed.setRepositoryID(scopedName.toIDLRepositoryID());
        // corbaFixed.setType(Constants.XSD_DECIMAL);
        corbaFixed.setType(fixedSimpleType.getQName());
        type = corbaFixed;
    } else {
        // corba:anonfixed
        Anonfixed corbaFixed = new Anonfixed();
        corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
        corbaFixed.setDigits(digits);
        corbaFixed.setScale(scale);
        // corbaFixed.setType(Constants.XSD_DECIMAL);
        corbaFixed.setType(fixedSimpleType.getQName());
        typeMap.getStructOrExceptionOrUnion().add(corbaFixed);
        type = corbaFixed;
    }
    // add corba:fixed
    setCorbaType(type);
}
Also used : Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) AST(antlr.collections.AST) XmlSchemaTotalDigitsFacet(org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet) XmlSchemaFractionDigitsFacet(org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed)

Aggregations

Anonfixed (org.apache.cxf.binding.corba.wsdl.Anonfixed)2 Fixed (org.apache.cxf.binding.corba.wsdl.Fixed)2 XmlSchemaFractionDigitsFacet (org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet)2 XmlSchemaTotalDigitsFacet (org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet)2 AST (antlr.collections.AST)1 QName (javax.xml.namespace.QName)1 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)1 XmlSchemaFacet (org.apache.ws.commons.schema.XmlSchemaFacet)1 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)1 XmlSchemaSimpleTypeRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction)1