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

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension. 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: JavascriptUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Return true for xsd:base64Binary or simple restrictions of it, as in the xmime stock type.
 * @param type
 * @return
 */
public static boolean mtomCandidateType(XmlSchemaType type) {
    if (type == null) {
        return false;
    }
    if (Constants.XSD_BASE64.equals(type.getQName())) {
        return true;
    }
    // there could be some disagreement whether the following is a good enough test.
    // what if 'base64binary' was extended in some crazy way? At runtime, either it has
    // an xop:Include or it doesn't.
    if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType)type;
        if (complexType.getContentModel() instanceof XmlSchemaSimpleContent) {
            XmlSchemaSimpleContent content = (XmlSchemaSimpleContent)complexType.getContentModel();
            if (content.getContent() instanceof XmlSchemaSimpleContentExtension) {
                XmlSchemaSimpleContentExtension extension =
                    (XmlSchemaSimpleContentExtension)content.getContent();
                if (Constants.XSD_BASE64.equals(extension.getBaseTypeName())) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example #2
Source File: XmlSchemaExtractor.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void handleSimpleContentExtension(XmlSchemaSimpleContentExtension target,
                                          XmlSchemaSimpleContentExtension source) throws ParserException {
    handleAttributesOrGroupRefs(target.getAttributes(), source.getAttributes());

    // copy baseType if present
    setTargetTypeQName(source.getBaseTypeName(), target::setBaseTypeName);
}
 
Example #3
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 #4
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private static final void convertComplexType(final XmlSchemaComplexType complexType, final XmlSchema schema,
        final Xsd2UmlConfig config, final Visitor handler, final QName complexTypeName,
        final List<TaggedValue> taggedValues) {
    
    final Identifier complexTypeId = config.ensureId(complexTypeName);
    
    final List<Attribute> attributes = new LinkedList<Attribute>();
    
    if (complexType.getContentModel() != null && complexType.getContentModel().getContent() != null) {
        final XmlSchemaContent content = complexType.getContentModel().getContent();
        if (content instanceof XmlSchemaComplexContentExtension) {
            final XmlSchemaComplexContentExtension complexContentExtension = (XmlSchemaComplexContentExtension) content;
            attributes.addAll(parseFields(complexContentExtension, schema, config));
            // The base of the restriction is interpreted as a UML
            // generalization.
            final QName base = complexContentExtension.getBaseTypeName();
            final Identifier baseId = config.ensureId(base);
            // Hack here to support anonymous complex types in the context
            // of elements.
            // Need to fix the SLI MongoDB schemes so that all types are
            // named.
            handler.visit(new Generalization(config.getPlugin().nameFromComplexTypeExtension(complexTypeName, base),
                    complexTypeId, baseId));
        } else if (content instanceof XmlSchemaComplexContentRestriction) {
            throw new AssertionError(content);
        } else if (content instanceof XmlSchemaSimpleContentExtension) {
            throw new AssertionError(content);
        } else if (content instanceof XmlSchemaSimpleContentRestriction) {
            throw new AssertionError(content);
        } else {
            throw new AssertionError(content);
        }
    }
    
    attributes.addAll(parseFields(complexType, schema, config));
    
    final String name = config.getPlugin().nameFromSchemaTypeName(complexTypeName);
    handler.visit(new ClassType(complexTypeId, name, false, attributes, taggedValues));
}
 
Example #5
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("PMD.AvoidReassigningParameters")  // makes code simpler 
private NeutralSchema parseComplexType(XmlSchemaComplexType schemaComplexType, NeutralSchema complexSchema,
        XmlSchema schema) {

    //if(complexSchema != null && complexSchema.getType() != null && complexSchema.getType().equals("application")) {
        //boolean isRequiredSchema = true; //for debugging
    //}

    if ((schemaComplexType.getContentModel() != null) && (schemaComplexType.getContentModel().getContent() != null)) {
        XmlSchemaContent content = schemaComplexType.getContentModel().getContent();
        if (content instanceof XmlSchemaComplexContentExtension) {
            XmlSchemaComplexContentExtension schemaComplexContent = (XmlSchemaComplexContentExtension) content;
            XmlSchemaComplexType complexBaseType = getComplexBaseType(schemaComplexContent, schema);
            if (complexBaseType != null) {
                complexSchema = parseComplexType(complexBaseType, complexSchema, schema);
            }
            this.parseFields(schemaComplexContent, complexSchema, schema);

        } else if (content instanceof XmlSchemaSimpleContentExtension) {
            QName baseTypeName = ((XmlSchemaSimpleContentExtension) content).getBaseTypeName();
            NeutralSchema simpleContentSchema = schemaFactory.createSchema(baseTypeName);
            complexSchema.addField(complexSchema.getType(), simpleContentSchema);

            parseAttributes(((XmlSchemaSimpleContentExtension) content).getAttributes(), complexSchema, schema);
        }
    }

    // Annotations are inherited by ComplexType fields so we need to parse these first.
    parseAnnotations(complexSchema, schemaComplexType);

    this.parseFields(schemaComplexType, complexSchema, schema);

    // Check for ChoiceSchemas. We only support complex types that contain choice if choice is
    // the ONLY element. If we find one, swap out the current ComplexSchema object that contains
    // this single choice schema for the actual choice schema itself.
    for (NeutralSchema ns : complexSchema.getFields().values()) {
        if (ns instanceof ChoiceSchema) {
            if (complexSchema.getFields().size() > 1 && !mergedChoiceSchemas.contains(ns)) {
                throw new RuntimeException(
                        "Choice elements are only supported on complex objects with no other fields: "
                                + schemaComplexType.getName());
            } else if (!mergedChoiceSchemas.contains(ns)) {
                ns.setType(complexSchema.getType());
                complexSchema.getAppInfo();
                mergedChoiceSchemas.add(ns);
                if(ns.getType().equals("serviceDescriptorType")) {
                    ns.addAnnotation(complexSchema.getAppInfo());
                }
                return ns;
            }
        }
    }

    return complexSchema;
}