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

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaSimpleType. 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: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 7 votes vote down vote up
private static final QName getSimpleTypeName(final XmlSchemaSimpleType simpleType) {
    final QName typeName = simpleType.getQName();
    if (null == typeName) {
        // The type is anonymous.
        final XmlSchemaSimpleTypeContent content = simpleType.getContent();
        if (content instanceof XmlSchemaSimpleTypeRestriction) {
            final XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
            return restriction.getBaseTypeName();
        } else if (content instanceof XmlSchemaSimpleTypeList) {
            final XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content;
            return list.getItemTypeName();
        } else {
            throw new AssertionError(content);
        }
    } else {
        return typeName;
    }
}
 
Example #2
Source File: EnumType.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void writeSchema(XmlSchema root) {

    XmlSchemaSimpleType simple = new XmlSchemaSimpleType(root, true);
    simple.setName(getSchemaType().getLocalPart());
    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
    restriction.setBaseTypeName(Constants.XSD_STRING);
    simple.setContent(restriction);

    Object[] constants = getTypeClass().getEnumConstants();

    List<XmlSchemaFacet> facets = restriction.getFacets();
    for (Object constant : constants) {
        XmlSchemaEnumerationFacet f = new XmlSchemaEnumerationFacet();
        f.setValue(getValue(constant));
        facets.add(f);
    }
}
 
Example #3
Source File: SmooksGenerator.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
public SmooksGenerator() {
    complexTypes = new HashMap<String, XmlSchemaComplexType>();
    simpleTypes = new HashMap<String, XmlSchemaSimpleType>();
    complexTypesData = new HashMap<String, ComplexTypeData>();

    resourceLoader = new DefaultResourceLoader();
    Resource xsdResource = resourceLoader.getResource(xsdLocation);
    Resource extensionXsdResource = resourceLoader.getResource(extensionXsdLocation);

    // extract complex types from base schema
    cacheTypesFromResource(xsdResource, xsdParentLocation);
    // extract complex types from extension schema
    cacheTypesFromResource(extensionXsdResource, extensionXsdParentLocation);

    // extract data from complex data including hierarchy
    cacheComplexTypeData();
}
 
Example #4
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private NeutralSchema parseSimpleType(XmlSchemaSimpleType schemaSimpleType, XmlSchema schema, String name) {

        NeutralSchema ns = recursiveParseSimpleType(schemaSimpleType, schema);
        if (schemaSimpleType.getName() == null) {
            // Type defined in-line. Need to capture it in the element schema set.
            int i = 1;
            NeutralSchema existing = elementSchemas.get(name + i);
            while (existing != null && !schemasEqual(ns, existing)) {
                i++;
                existing = schemas.get(name + i);
            }
            ns.setType(name + i);
            elementSchemas.put(name + i, ns);
        }
        return ns;
    }
 
Example #5
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private NeutralSchema parse(XmlSchemaType type, String name, XmlSchema schema) {
    NeutralSchema prior = partialSchemas.get(type);
    if (prior != null) {
        // we already have a schema of this type
        NeutralSchema nSchema = getSchemaFactory().copySchema(prior);
        return nSchema;
    }
    if (type instanceof XmlSchemaComplexType) {
        NeutralSchema complexSchema = getSchemaFactory().createSchema(name);
        partialSchemas.put(type, complexSchema); // avoid infinite recursion in self-referential
                                                 // schemas
        return parseComplexType((XmlSchemaComplexType) type, complexSchema, schema);

    } else if (type instanceof XmlSchemaSimpleType) {
        return parseSimpleType((XmlSchemaSimpleType) type, schema, name);

    } else {
        throw new RuntimeException("Unsupported schema type: " + type.getClass().getCanonicalName());
    }
}
 
Example #6
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private static final Attribute parseAttribute(final XmlSchemaAttribute attribute, final XmlSchema schema,
        final Xsd2UmlConfig config) {
    
    final String name = config.getPlugin().nameFromSchemaAttributeName(attribute.getQName());
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    taggedValues.addAll(annotations(attribute, config));
    
    final XmlSchemaSimpleType simpleType = attribute.getSchemaType();
    final Identifier type;
    if (simpleType != null) {
        type = config.ensureId(getSimpleTypeName(simpleType));
    } else {
        type = config.ensureId(attribute.getSchemaTypeName());
    }
    final Multiplicity multiplicity = multiplicity(range(Occurs.ONE, Occurs.ONE));
    return new Attribute(Identifier.random(), name, type, multiplicity, taggedValues);
}
 
Example #7
Source File: XmlSchemaUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the string values for an enumeration.
 * @param type
 */
public static List<String> enumeratorValues(XmlSchemaSimpleType type) {
    XmlSchemaSimpleTypeContent content = type.getContent();
    XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
    List<XmlSchemaFacet> facets = restriction.getFacets();
    List<String> values = new ArrayList<>();
    for (XmlSchemaFacet facet : facets) {
        XmlSchemaEnumerationFacet enumFacet = (XmlSchemaEnumerationFacet) facet;
        values.add(enumFacet.getValue().toString());
    }
    return values;
}
 
Example #8
Source File: XmlSchemaUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Return true if a simple type is a straightforward XML Schema representation of an enumeration.
 * If we discover schemas that are 'enum-like' with more complex structures, we might
 * make this deal with them.
 * @param type Simple type, possible an enumeration.
 * @return true for an enumeration.
 */
public static boolean isEumeration(XmlSchemaSimpleType type) {
    XmlSchemaSimpleTypeContent content = type.getContent();
    if (!(content instanceof XmlSchemaSimpleTypeRestriction)) {
        return false;
    }
    XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
    List<XmlSchemaFacet> facets = restriction.getFacets();
    for (XmlSchemaFacet facet : facets) {
        if (!(facet instanceof XmlSchemaEnumerationFacet)) {
            return false;
        }
    }
    return true;
}
 
Example #9
Source File: XmlSchemaExtractor.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private void handleSimpleTypeUnion(XmlSchemaSimpleTypeUnion target, XmlSchemaSimpleTypeUnion source) throws ParserException {

        final List<XmlSchemaSimpleType> targetBaseTypes = target.getBaseTypes();
        final List<QName> targetTypeNames = new ArrayList<>();

        // add base types
        for (XmlSchemaSimpleType baseType : source.getBaseTypes()) {
            targetBaseTypes.add(createXmlSchemaObjectBase(baseType));
        }

        // add member types by QName
        final QName[] typesQNames = source.getMemberTypesQNames();
        if (typesQNames != null) {
            for (QName name : typesQNames) {
                setTargetTypeQName(name, targetTypeNames::add);
            }
        }

        if (!targetTypeNames.isEmpty()) {
            // set target type names
            target.setMemberTypesQNames(targetTypeNames.toArray(new QName[0]));
        }
    }
 
Example #10
Source File: XsdEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Create a simple type for an alphanumeric type.
 * <p/>
 * COBOL alphanumeric fields are fixed length so we create a facet to
 * enforce that constraint. A pattern derived from the picture clause can
 * also be used as a facet. If the item has children conditions, we add
 * enumeration facets
 * 
 * @param xsdDataItem COBOL data item decorated with XSD attributes
 * @param xsdTypeName the XML schema built-in type name to use as a
 *            restriction
 * @return an XML schema simple type
 */
protected XmlSchemaSimpleType createAlphaXmlSchemaSimpleType(
        final XsdDataItem xsdDataItem, final String xsdTypeName) {

    XmlSchemaSimpleTypeRestriction restriction = createRestriction(xsdTypeName);
    if (xsdDataItem.getLength() > -1) {
        restriction.getFacets().add(
                createMaxLengthFacet(xsdDataItem.getLength()));
    }
    if (xsdDataItem.getPattern() != null) {
        restriction.getFacets().add(
                createPatternFacet(xsdDataItem.getPattern()));
    }
    addEnumerationFacets(xsdDataItem, restriction);
    return createXmlSchemaSimpleType(restriction);
}
 
Example #11
Source File: XsdEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an XML Schema element from a COBOL data item.
 * 
 * @param xsdDataItem COBOL data item decorated with XSD attributes
 * @return the XML schema element
 */
public XmlSchemaElement createXmlSchemaElement(final XsdDataItem xsdDataItem) {

    // Let call add root elements if he needs to so for now pretend this is
    // not a root element
    XmlSchemaElement element = new XmlSchemaElement(getXsd(), false);
    element.setName(xsdDataItem.getXsdElementName());
    if (xsdDataItem.getMaxOccurs() != 1) {
        element.setMaxOccurs(xsdDataItem.getMaxOccurs());
    }
    if (xsdDataItem.getMinOccurs() != 1) {
        element.setMinOccurs(xsdDataItem.getMinOccurs());
    }

    /*
     * Create this element schema type, then if its a simple type set it as
     * an anonymous type. Otherwise, it is a named complex type, so
     * reference it by name.
     */
    XmlSchemaType xmlSchemaType = createXmlSchemaType(xsdDataItem);
    if (xmlSchemaType == null) {
        return null;
    }
    if (xmlSchemaType instanceof XmlSchemaSimpleType) {
        element.setSchemaType(xmlSchemaType);
    } else {
        element.setSchemaTypeName(xmlSchemaType.getQName());
    }
    if (getConfig().addLegStarAnnotations()) {
        element.setAnnotation(_annotationEmitter
                .createLegStarAnnotation(xsdDataItem));
    }
    return element;
}
 
Example #12
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createImportedAttributeType(XmlSchema attributeTypeSchema) {
    XmlSchemaSimpleType attributeImportedType = new XmlSchemaSimpleType(attributeTypeSchema, true);
    attributeImportedType.setName("importedAttributeType");
    XmlSchemaSimpleTypeRestriction simpleContent = new XmlSchemaSimpleTypeRestriction();
    attributeImportedType.setContent(simpleContent);
    simpleContent.setBaseTypeName(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string"));
}
 
Example #13
Source File: Xsd2CobolTypesModelBuilder.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map < String, Object > getProps(int fieldIndex,
        XmlSchemaElement xsdElement, RootCompositeType compositeTypes) {
    Map < String, Object > props;
    CobolAnnotations cobolAnnotations = new CobolAnnotations(xsdElement);

    if (xsdElement.getSchemaType() instanceof XmlSchemaComplexType) {
        props = getProps((XmlSchemaComplexType) xsdElement.getSchemaType(),
                compositeTypes);

    } else if (xsdElement.getSchemaType() instanceof XmlSchemaSimpleType) {
        props = getProps((XmlSchemaSimpleType) xsdElement.getSchemaType(),
                cobolAnnotations);
        if (props.get(ODO_OBJECT_PROP_NAME) != null) {
            odoObjectNames.put(cobolAnnotations.getCobolName(),
                    getFieldName(xsdElement));
        }

    } else {
        throw new Xsd2ConverterException("Unsupported xsd element of type "
                + xsdElement.getSchemaType().getQName() + " at line "
                + xsdElement.getLineNumber());
    }

    if (xsdElement.getMaxOccurs() > 1) {
        addArrayProps(xsdElement, cobolAnnotations, props);
    }
    
    if (xsdElement.getMinOccurs() == 0 &&  xsdElement.getMaxOccurs() == 1) {
        addOptionalProps(xsdElement, cobolAnnotations, props);
    }

    props.put(COBOL_NAME_PROP_NAME, cobolAnnotations.getCobolName());
    props.put(FIELD_INDEX_PROP_NAME, fieldIndex);
    return props;

}
 
Example #14
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private static final void convertType(final XmlSchemaType type, final XmlSchema schema,
        final Xsd2UmlConfig context, final Visitor handler, final QName name, final List<TaggedValue> taggedValues) {
    
    if (type instanceof XmlSchemaComplexType) {
        final XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
        convertComplexType(complexType, schema, context, handler, name, taggedValues);
    } else if (type instanceof XmlSchemaSimpleType) {
        final XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
        convertSimpleType(simpleType, schema, context, handler);
    } else {
        throw new AssertionError(type);
    }
}
 
Example #15
Source File: XsdEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an XML schema simple type from a restriction.
 * 
 * @param restriction the XML schema restriction
 * @return the XML schema simple type
 */
protected XmlSchemaSimpleType createXmlSchemaSimpleType(
        final XmlSchemaSimpleTypeRestriction restriction) {
    XmlSchemaSimpleType xmlSchemaSimpleType = new XmlSchemaSimpleType(
            getXsd(), false);
    xmlSchemaSimpleType.setContent(restriction);
    return xmlSchemaSimpleType;
}
 
Example #16
Source File: JavascriptUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String javascriptParseExpression(XmlSchemaType type, String value) {
    if (!(type instanceof XmlSchemaSimpleType)) {
        return value;
    }
    String name = type.getName();
    if (INT_TYPES.contains(name)) {
        return "parseInt(" + value + ")";
    } else if (FLOAT_TYPES.contains(name)) {
        return "parseFloat(" + value + ")";
    } else if ("boolean".equals(name)) {
        return "(" + value + " == 'true')";
    } else {
        return value;
    }
}
 
Example #17
Source File: ClassTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void writeSchema(XmlSchema root) {
    XmlSchemaSimpleType xst = new XmlSchemaSimpleType(root, true);
    xst.setName("class");

    XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction();
    content.setBaseTypeName(Constants.XSD_STRING);
    xst.setContent(content);
}
 
Example #18
Source File: CustomStringType.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void writeSchema(XmlSchema root) {
    // this mapping gets used with xs:string, and we might get called.
    if (root.getTargetNamespace().equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
        return;
    }
    XmlSchemaSimpleType type = new XmlSchemaSimpleType(root, true);
    type.setName(getSchemaType().getLocalPart());
    XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension();
    ext.setBaseTypeName(Constants.XSD_STRING);
    XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction();
    content.setBaseTypeName(Constants.XSD_STRING);
    type.setContent(content);
}
 
Example #19
Source File: ParameterMapper.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void processXmlSchemaSimpleType(XmlSchemaSimpleType xmlSchema, JavaMethod jm,
                                               JavaParameter parameter, MessagePartInfo part) {
    if (xmlSchema.getContent() instanceof XmlSchemaSimpleTypeList
        && (!part.isElement() || !jm.isWrapperStyle())) {
        parameter.annotate(new XmlListAnotator(jm.getInterface()));
    }
    if (Constants.XSD_HEXBIN.equals(xmlSchema.getQName())
        && (!part.isElement() || !jm.isWrapperStyle())) {
        parameter.annotate(new XmlJavaTypeAdapterAnnotator(jm.getInterface(), HexBinaryAdapter.class));
    }
}
 
Example #20
Source File: ParameterMapper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static JavaParameter map(JavaMethod jm, MessagePartInfo part,
                                JavaType.Style style, ToolContext context) {
    String name = ProcessorUtil.mangleNameToVariableName(part.getName().getLocalPart());
    String namespace = ProcessorUtil.resolvePartNamespace(part);
    String type = ProcessorUtil.resolvePartType(part, context);

    JavaParameter parameter = new JavaParameter(name, type, namespace);
    parameter.setPartName(part.getName().getLocalPart());
    if (part.getXmlSchema() instanceof XmlSchemaSimpleType) {
        processXmlSchemaSimpleType((XmlSchemaSimpleType)part.getXmlSchema(), jm, parameter, part);
    } else if (part.getXmlSchema() instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement)part.getXmlSchema();
        if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            processXmlSchemaSimpleType((XmlSchemaSimpleType)element.getSchemaType(), jm, parameter, part);
        }
    }
    parameter.setQName(ProcessorUtil.getElementName(part));
    parameter.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriter(part, context));
    String fullJavaName = ProcessorUtil.getFullClzName(part, context, false);

    parameter.setClassName(fullJavaName);

    if (style == JavaType.Style.INOUT || style == JavaType.Style.OUT) {
        parameter.setHolder(true);
        parameter.setHolderName(javax.xml.ws.Holder.class.getName());
        String holderClass = fullJavaName;
        if (JAXBUtils.holderClass(fullJavaName) != null) {
            holderClass = JAXBUtils.holderClass(fullJavaName).getName();
        }
        parameter.setClassName(holderClass);
    }
    parameter.setStyle(style);

    return parameter;
}
 
Example #21
Source File: ParameterProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void processXmlSchemaSimpleType(XmlSchemaSimpleType xmlSchema, JavaMethod method,
                                               MessagePartInfo part) {
    if (xmlSchema.getContent() instanceof XmlSchemaSimpleTypeList
        && (!part.isElement() || !method.isWrapperStyle())) {
        method.annotate(new XmlListAnotator(method.getInterface()));
    }
    if (Constants.XSD_HEXBIN.equals(xmlSchema.getQName())
        && (!part.isElement() || !method.isWrapperStyle())) {
        method.annotate(new XmlJavaTypeAdapterAnnotator(method.getInterface(), HexBinaryAdapter.class));
    }
}
 
Example #22
Source File: ParameterProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void processReturn(JavaMethod method, MessagePartInfo part) {
    String name = part == null ? "return" : part.getName().getLocalPart();
    String type = part == null ? "void" : ProcessorUtil.resolvePartType(part, context);

    String namespace = part == null ? null : ProcessorUtil.resolvePartNamespace(part);

    JavaReturn returnType = new JavaReturn(name, type, namespace);
    if (part != null) {
        returnType.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriter(part, context));
    }

    returnType.setQName(ProcessorUtil.getElementName(part));
    returnType.setStyle(JavaType.Style.OUT);
    if (namespace != null && type != null && !"void".equals(type)) {
        returnType.setClassName(ProcessorUtil.getFullClzName(part, context, false));
    }

    if (part != null && part.getXmlSchema() instanceof XmlSchemaSimpleType) {
        processXmlSchemaSimpleType((XmlSchemaSimpleType)part.getXmlSchema(), method, part);
    } else if (part != null && part.getXmlSchema() instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement)part.getXmlSchema();
        if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            processXmlSchemaSimpleType((XmlSchemaSimpleType)element.getSchemaType(), method, part);
        }
    }

    method.setReturn(returnType);
}
 
Example #23
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private QName getSimpleContentTypeName(XmlSchemaSimpleType schemaSimpleType) {
    QName simpleContentTypeName = null;
    if (schemaSimpleType.getContent() != null
            && schemaSimpleType.getContent() instanceof XmlSchemaSimpleTypeRestriction) {
        XmlSchemaSimpleTypeRestriction simpleContent = (XmlSchemaSimpleTypeRestriction) schemaSimpleType
                .getContent();
        simpleContentTypeName = simpleContent.getBaseTypeName();
    } else {
        throw new RuntimeException("Unsupported simple content model: "
                + schemaSimpleType.getContent().getClass().getCanonicalName());
    }
    return simpleContentTypeName;
}
 
Example #24
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public CorbaType convertSchemaToCorbaType(XmlSchemaType stype,
                                              QName defaultName,
                                              XmlSchemaType parent,
                                              XmlSchemaAnnotation annotation,
                                              boolean anonymous)
    throws Exception {
    CorbaType corbaTypeImpl = null;
    if (!isAddressingNamespace(stype.getQName())) {
        // need to determine if its a primitive type.
        if (stype instanceof XmlSchemaComplexType) {
            corbaTypeImpl = processComplexType((XmlSchemaComplexType)stype,
                                                          defaultName, annotation, anonymous);
        } else if (stype instanceof XmlSchemaSimpleType) {
            corbaTypeImpl = processSimpleType((XmlSchemaSimpleType)stype,
                                              defaultName, anonymous);
        }  else if (xmlSchemaList.getElementByQName(stype.getQName()) != null) {
            XmlSchemaElement el = xmlSchemaList.getElementByQName(stype.getQName());
            //REVISIT, passing ns uri because of a bug in XmlSchema (Bug: WSCOMMONS-69)
            corbaTypeImpl = processElementType(el,
                                               defaultName,
                                               stype.getQName().getNamespaceURI());
        } else {
            throw new Exception("Couldn't convert schema " + stype.getQName() + " to corba type");
        }
    }

    if (corbaTypeImpl != null && !isDuplicate(corbaTypeImpl)) {
        typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
    }

    return corbaTypeImpl;
}
 
Example #25
Source File: XmlSchemaExtractor.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void handleSimpleType(XmlSchemaSimpleType target, XmlSchemaSimpleType source) throws ParserException {
    // handle content
    final XmlSchemaSimpleTypeContent sourceContent = source.getContent();
    if (sourceContent != null) {
        target.setContent(createXmlSchemaObjectBase(sourceContent));
    }
}
 
Example #26
Source File: DeclaratorVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaSimpleType duplicateXmlSchemaSimpleType(Scope newScope) {
    XmlSchemaSimpleType oldSimpleType = (XmlSchemaSimpleType) getSchemaType();
    XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(schema, oldSimpleType.isTopLevel());
    simpleType.setContent(oldSimpleType.getContent());
    simpleType.setName(newScope.toString());
    return simpleType;
}
 
Example #27
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 #28
Source File: XsdEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Create a simple type for an numeric type.
 * <p/>
 * Numeric elements might have totaDigits, fractionDigits, minInclusive or
 * maxInclusive facets.
 * 
 * @param xsdDataItem COBOL data item decorated with XSD attributes
 * @param xsdTypeName the XML schema built-in type name to use as a
 *            restriction
 * @return an XML schema simple type
 */
protected XmlSchemaSimpleType createNumericXmlSchemaSimpleType(
        final XsdDataItem xsdDataItem, final String xsdTypeName) {

    XmlSchemaSimpleTypeRestriction restriction = createRestriction(xsdTypeName);

    /*
     * COBOL native binary are special because even though they have a
     * totalDigits attribute, it is not used enforce a restriction.
     */
    if (xsdDataItem.getCobolType() != CobolTypes.NATIVE_BINARY_ITEM
            && xsdDataItem.getTotalDigits() > -1) {

        /*
         * Due to a bug in JAXB (see JAXB issue 715), unsignedLong may end
         * up being mapped to BigInteger instead of Long when totalDigits is
         * used instead of maxInclusive. So for now, we keep maxInclusive.
         */
        if (xsdDataItem.getXsdType() == XsdType.ULONG) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < xsdDataItem.getTotalDigits(); i++) {
                sb.append("9");
            }
            restriction.getFacets().add(
                    createMaxInclusiveFacet(sb.toString()));
        } else {
            restriction.getFacets().add(
                    createTotalDigitsFacet(xsdDataItem.getTotalDigits()));
        }
    }

    /* fractionDigits is a fixed facet for most numerics so be careful */
    if (xsdDataItem.getFractionDigits() > 0) {
        restriction.getFacets().add(
                createFractionDigitsFacet(xsdDataItem.getFractionDigits()));
    }

    /*
     * For xsd:decimal and xsd:integer, we further constrain if the numeric
     * needs to be positive (unsigned).
     */
    if ((xsdDataItem.getXsdType() == XsdType.INTEGER || xsdDataItem
            .getXsdType() == XsdType.DECIMAL) && !xsdDataItem.isSigned()) {
        restriction.getFacets().add(createMinInclusiveFacet("0"));
    }
    addEnumerationFacets(xsdDataItem, restriction);
    return createXmlSchemaSimpleType(restriction);
}
 
Example #29
Source File: CommonsSchemaInfoBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
public static XmlTypeInfo createXmlTypeInfo(QName qname, XmlSchemaType type) {
    if (qname == null) throw new NullPointerException("qname is null");
    if (type == null) throw new NullPointerException("type is null");

    XmlTypeInfo typeInfo = new XmlTypeInfo();
    typeInfo.qname = qname;
    typeInfo.anonymous = qname.getLocalPart().indexOf('>') >= 0;

    if (type instanceof XmlSchemaSimpleType) {
        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
        XmlSchemaSimpleTypeContent content = simpleType.getContent();
        if (content instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content;
            typeInfo.simpleBaseType = list.getItemType().getQName();

            // this is a list
            typeInfo.listType = true;
        } else if (content instanceof XmlSchemaSimpleTypeRestriction) {
            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
            typeInfo.simpleBaseType = restriction.getBaseTypeName();

            // is this an enumeration?
            for (Iterator iterator = restriction.getFacets().getIterator(); iterator.hasNext(); ) {
                if (iterator.next() instanceof XmlSchemaEnumerationFacet) {
                    typeInfo.enumType = true;
                    break;
                }

            }
        }
    } else if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;

        // SOAP array component type
        typeInfo.arrayComponentType = extractSoapArrayComponentType(complexType);

        // process attributes (skip soap arrays which have non-mappable attributes)
        if (!isSoapArray(complexType)) {
            XmlSchemaObjectCollection attributes = complexType.getAttributes();
            for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
                Object item = iterator.next();
                if (item instanceof XmlSchemaAttribute) {
                    XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
                    Object old = typeInfo.attributes.put(attribute.getQName().getLocalPart(), attribute.getSchemaTypeName());
                    if (old != null) {
                        throw new IllegalArgumentException("Complain to your expert group member, spec does not support attributes with the same local name and differing namespaces: original: " + old + ", duplicate local name: " + attribute);
                    }
                }
            }
        }
    } else {
        LOG.warn("Unknown schema type class " + typeInfo.getClass().getName());
    }

    return typeInfo;
}
 
Example #30
Source File: Xsd2CobolTypesModelBuilder.java    From legstar-core2 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Retrieve the properties of a primitive type.
 * 
 * @param xsdSimpleType the XML schema primitive type
 * @param cobolAnnotations the associated COBOL annotations
 * @return a set of properties
 */
private Map < String, Object > getProps(XmlSchemaSimpleType xsdSimpleType,
        final CobolAnnotations cobolAnnotations) {
    XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) xsdSimpleType
            .getContent();
    if (restriction != null && restriction.getBaseTypeName() != null) {
        QName xsdTypeName = restriction.getBaseTypeName();
        List < XmlSchemaFacet > facets = restriction.getFacets();
        if (xsdTypeName.equals(Constants.XSD_STRING)) {
            return getCobolAlphanumType(facets);
        } else if (xsdTypeName.equals(Constants.XSD_HEXBIN)) {
            return getCobolOctetStreamType(facets);
        } else if (xsdTypeName.equals(Constants.XSD_INT)) {
            return getCobolDecimalType(cobolAnnotations, Integer.class);
        } else if (xsdTypeName.equals(Constants.XSD_LONG)) {
            return getCobolDecimalType(cobolAnnotations, Long.class);
        } else if (xsdTypeName.equals(Constants.XSD_SHORT)) {
            return getCobolDecimalType(cobolAnnotations, Short.class);
        } else if (xsdTypeName.equals(Constants.XSD_DECIMAL)) {
            return getCobolDecimalType(cobolAnnotations, BigDecimal.class);
        } else if (xsdTypeName.equals(Constants.XSD_FLOAT)) {
            return getCobolDecimalType(cobolAnnotations, Float.class);
        } else if (xsdTypeName.equals(Constants.XSD_DOUBLE)) {
            return getCobolDecimalType(cobolAnnotations, Double.class);
        } else if (xsdTypeName.equals(Constants.XSD_UNSIGNEDINT)) {
            return getCobolDecimalType(cobolAnnotations, Long.class);
        } else if (xsdTypeName.equals(Constants.XSD_UNSIGNEDSHORT)) {
            return getCobolDecimalType(cobolAnnotations, Integer.class);
        } else if (xsdTypeName.equals(Constants.XSD_UNSIGNEDLONG)) {
            return getCobolDecimalType(cobolAnnotations, BigInteger.class);
        } else if (xsdTypeName.equals(Constants.XSD_INTEGER)) {
            return getCobolDecimalType(cobolAnnotations, BigInteger.class);
        } else {
            throw new Xsd2ConverterException("Unsupported xsd type "
                    + xsdTypeName);
        }

    } else {
        throw new Xsd2ConverterException("Simple type without restriction "
                + xsdSimpleType.getQName());
    }

}