org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet. 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: Xsd2CobolTypesModelBuilder.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Retrieve the maxLength facet if it exists.
 * 
 * @param facets the list of facets
 * @return the maxlength value or -1 if there are no maxLength facets
 */
private int getMaxLength(List < XmlSchemaFacet > facets) {
    for (XmlSchemaFacet facet : facets) {
        if (facet instanceof XmlSchemaMaxLengthFacet) {
            return Integer
                    .parseInt((String) ((XmlSchemaMaxLengthFacet) facet)
                            .getValue());
        }
    }
    return -1;
}
 
Example #2
Source File: StringVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
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);

    CorbaType anon = null;
    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);
}
 
Example #3
Source File: StringVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
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();
    CorbaType anon = null;
    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);
}
 
Example #4
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 4 votes vote down vote up
private CorbaType processSimpleRestrictionType(XmlSchemaSimpleType stype,
                                                   QName name, QName schematypeName,
                                                   boolean anonymous)
    throws Exception {
    CorbaType corbaTypeImpl = null;

    // 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;
}
 
Example #5
Source File: XsdEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Create an XML schema maxLength facet.
 * 
 * @param length the value to set
 * @return an XML schema length facet
 */
protected XmlSchemaMaxLengthFacet createMaxLengthFacet(final int length) {
    XmlSchemaMaxLengthFacet xmlSchemaMaxLengthFacet = new XmlSchemaMaxLengthFacet();
    xmlSchemaMaxLengthFacet.setValue(length);
    return xmlSchemaMaxLengthFacet;
}