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

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaComplexContentExtension. 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: XmlSchemaUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static QName getBaseType(XmlSchemaComplexType type) {
    XmlSchemaContentModel model = type.getContentModel();
    if (model == null) {
        return null;
    }
    XmlSchemaContent content = model.getContent();
    if (content == null) {
        return null;
    }

    if (!(content instanceof XmlSchemaComplexContentExtension)) {
        return null;
    }

    XmlSchemaComplexContentExtension ext = (XmlSchemaComplexContentExtension)content;
    return ext.getBaseTypeName();
}
 
Example #2
Source File: XmlSchemaUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static List<XmlSchemaAttributeOrGroupRef> getContentAttributes(XmlSchemaComplexType type) {
    XmlSchemaContentModel model = type.getContentModel();
    if (model == null) {
        return null;
    }
    XmlSchemaContent content = model.getContent();
    if (content == null) {
        return null;
    }
    if (!(content instanceof XmlSchemaComplexContentExtension)) {
        return null;
    }

    XmlSchemaComplexContentExtension ext = (XmlSchemaComplexContentExtension)content;
    return ext.getAttributes();
}
 
Example #3
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Extract a particle from a complex type
 * returns null if it can't be extracted.
 */
private XmlSchemaParticle extractParticle(XmlSchemaComplexType complexType) {
    XmlSchemaParticle particle = complexType.getParticle();

    // handle case where the complexType is an extension
    if (particle == null && complexType.getContentModel() != null
            && complexType.getContentModel().getContent() != null) {
        XmlSchemaContent content = complexType.getContentModel().getContent();
        if (content instanceof XmlSchemaComplexContentExtension) {
            XmlSchemaComplexContentExtension complexContent = (XmlSchemaComplexContentExtension) content;
            particle = complexContent.getParticle();
        }
    }

    return particle;
}
 
Example #4
Source File: XmlSchemaExtractor.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void handleComplexContentExtension(XmlSchemaComplexContentExtension target,
                                           XmlSchemaComplexContentExtension source) throws ParserException {

    handleAttributesOrGroupRefs(target.getAttributes(), source.getAttributes());
    if (source.getParticle() != null) {
        handleParticle(source.getParticle(), target::setParticle);
    }
    setTargetTypeQName(source.getBaseTypeName(), target::setBaseTypeName);
}
 
Example #5
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static List<WrapperElement> createWrappedElementsFromExtension(SchemaCollection schema,
                                                                       XmlSchemaComplexType type,
                                                                       int maxStackDepth) {
    List<WrapperElement> qnames = new ArrayList<>();

    XmlSchemaContent schemaContent = type.getContentModel().getContent();
    if (!(schemaContent instanceof XmlSchemaComplexContentExtension) || maxStackDepth == 0) {
        return qnames;
    }

    XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)schemaContent;
    QName baseTypeName = extension.getBaseTypeName();
    XmlSchemaType baseType = schema.getTypeByQName(baseTypeName);

    if (baseType instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexBaseType = (XmlSchemaComplexType)baseType;

        if (complexBaseType.getParticle() == null && complexBaseType.getContentModel() != null) {
            // continue up the extension ladder
            qnames.addAll(createWrappedElementsFromExtension(schema, complexBaseType, maxStackDepth - 1));
        } else if (complexBaseType.getParticle() instanceof XmlSchemaSequence) {
            XmlSchemaSequence seq = (XmlSchemaSequence)complexBaseType.getParticle();
            qnames.addAll(createWrappedElements(seq));
        }
    }

    if (extension.getParticle() instanceof XmlSchemaSequence) {
        XmlSchemaSequence xmlSchemaSeq = (XmlSchemaSequence)extension.getParticle();
        qnames.addAll(createWrappedElements(xmlSchemaSeq));
    }

    return qnames;
}
 
Example #6
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XmlSchemaComplexContentExtension createDerivedType1(XmlSchema importingSchema) {
    XmlSchemaComplexType derivedType1 = new XmlSchemaComplexType(importingSchema, true);
    derivedType1.setName("derivedExtension");
    XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
    extension.setBaseTypeName(new QName(BASE_TYPE_SCHEMA1, "baseType1"));
    XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
    complexContent.setContent(extension);
    derivedType1.setContentModel(complexContent);
    return extension;
}
 
Example #7
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 #8
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private static final List<Attribute> parseFields(
        final XmlSchemaComplexContentExtension schemaComplexContentExtension, final XmlSchema schema,
        final Xsd2UmlConfig context) {
    // parseAttributes(schemaComplexContentExtension.getAttributes(),
    // schema);
    return parseParticle(schemaComplexContentExtension.getParticle(), schema, context);
}
 
Example #9
Source File: ImportRepairTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testImportRepairs() throws Exception {
    if (System.getProperty("java.vendor").contains("IBM")) {
        //the version of xerces built into IBM jdk won't work
        //and we cannot get a good version unless we endorse it
        return;
    }

    collection = new SchemaCollection();
    XmlSchema importingSchema = newSchema(IMPORTING_SCHEMA);
    XmlSchema baseTypeSchema1 = newSchema(BASE_TYPE_SCHEMA1);
    XmlSchema baseTypeSchema2 = newSchema(BASE_TYPE_SCHEMA2);
    XmlSchema elementTypeSchema = newSchema(ELEMENT_TYPE_SCHEMA);
    XmlSchema elementSchema = newSchema(ELEMENT_SCHEMA);
    XmlSchema attributeSchema = newSchema(ATTRIBUTE_SCHEMA);
    XmlSchema attributeTypeSchema = newSchema(ATTRIBUTE_TYPE_SCHEMA);

    createBaseType1(baseTypeSchema1);

    createBaseType2(baseTypeSchema2);
    XmlSchemaComplexContentExtension derivedType1Extension = createDerivedType1(importingSchema);
    createDerivedType2(importingSchema);

    createImportedElement(elementSchema);

    createTypeImportingElement(importingSchema);

    createTypeImportedByElement(elementTypeSchema);

    createElementWithImportedType(importingSchema);

    createImportedAttribute(attributeSchema);

    XmlSchemaAttribute importingAttribute = new XmlSchemaAttribute(importingSchema, false);
    importingAttribute.getRef().setTargetQName(new QName(ATTRIBUTE_SCHEMA, "imported"));
    // borrow derivedType1 to make the reference.
    derivedType1Extension.getAttributes().add(importingAttribute);

    createImportedAttributeType(attributeTypeSchema);

    createAttributeImportingType(importingSchema);


    /*
     * Notice that no imports have been added. In an ideal world, XmlSchema would do this for us.
     */
    try {
        tryToParseSchemas();
        fail("Expected an exception");
    } catch (DOMErrorException e) {
        //ignore, expected
    }
    LOG.info("adding imports");
    collection.addCrossImports();
    tryToParseSchemas();
}
 
Example #10
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;
}
 
Example #11
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private void parseFields(XmlSchemaComplexContentExtension schemaComplexContentExtension,
        NeutralSchema complexSchema, XmlSchema schema) {
    parseAttributes(schemaComplexContentExtension.getAttributes(), complexSchema, schema);
    parseParticle(schemaComplexContentExtension.getParticle(), complexSchema, schema);
}