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

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaContent. 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: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Extract a particle from a complex type, respecting both extensions and restrictions
 * returns null if there isn't one.
 */
private String extractBaseTypeName(XmlSchemaComplexType complexType) {
    String baseTypeName = null;

    if (complexType.getBaseSchemaTypeName() != null) {
        baseTypeName = complexType.getBaseSchemaTypeName().getLocalPart();
    } else if (complexType.getContentModel() != null && complexType.getContentModel().getContent() != null) {
        XmlSchemaContent content = complexType.getContentModel().getContent();
        if (content instanceof XmlSchemaComplexContentRestriction) {
            XmlSchemaComplexContentRestriction contentRestriction = (XmlSchemaComplexContentRestriction) content;
            if (contentRestriction.getBaseTypeName() != null) {
                baseTypeName = contentRestriction.getBaseTypeName().getLocalPart();
            }
        }
    }

    return baseTypeName;
}
 
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: CommonsSchemaInfoBuilder.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static boolean isSoapArray(XmlSchemaComplexType complexType) {
    // Soap arrays are based on complex content restriction
    XmlSchemaContentModel contentModel = complexType.getContentModel();
    if (contentModel == null) {
        return false;
    }
    XmlSchemaContent content = contentModel.getContent();
    if (!(content instanceof XmlSchemaComplexContentRestriction)) {
        return false;
    }

    XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
    return SOAP_ARRAY.equals(restriction.getBaseTypeName());
}
 
Example #7
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * Extract a particle from a complex type
 * returns null if it can't be extracted.
 */
private XmlSchemaParticle extractParticleWithRestriction(XmlSchemaComplexType complexType) {
    XmlSchemaParticle particle = complexType.getParticle();

    if (particle == null && complexType.getContentModel() != null
            && complexType.getContentModel().getContent() != null) {
        XmlSchemaContent content = complexType.getContentModel().getContent();
        if (content instanceof XmlSchemaComplexContentRestriction) {
            XmlSchemaComplexContentRestriction complexContent = (XmlSchemaComplexContentRestriction) content;
            particle = complexContent.getParticle();
        }
    }
    return particle;
}
 
Example #8
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 #9
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;
}