Java Code Examples for org.apache.ws.commons.schema.XmlSchemaComplexType#getContentModel()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaComplexType#getContentModel() . 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: 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 3
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 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
 * 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 5
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 6
Source File: XmlSchemaExtractor.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void handleComplexType(XmlSchemaComplexType target, XmlSchemaComplexType source) throws ParserException {

        // copy attributes
        handleAttributesOrGroupRefs(target.getAttributes(), source.getAttributes());

        // handle contentModel
        final XmlSchemaContentModel sourceContentModel = source.getContentModel();
        if (sourceContentModel != null) {
            target.setContentModel(createXmlSchemaObjectBase(sourceContentModel));
        }

        handleParticle(source.getParticle(), target::setParticle);
    }
 
Example 7
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static List<WrapperElement> getWrappedElement(ToolContext context, QName partElement) {
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    SchemaCollection schema = serviceInfo.getXmlSchemaCollection();

    XmlSchemaElement elementByName = schema.getElementByQName(partElement);

    XmlSchemaComplexType type = (XmlSchemaComplexType)elementByName.getSchemaType();

    XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();

    List<WrapperElement> qnames = createWrappedElements(seq);

    //If it's extension
    if (seq == null && type.getContentModel() != null) {
        Object configuredMaxStackDepth = context.get(ToolConstants.CFG_MAX_EXTENSION_STACK_DEPTH);
        Integer maxStackDepth = Integer.valueOf(5);
        if (configuredMaxStackDepth instanceof Integer) {
            maxStackDepth = (Integer)configuredMaxStackDepth;
        } else if (configuredMaxStackDepth instanceof String) {
            maxStackDepth = Integer.valueOf((String)configuredMaxStackDepth);
        }
        qnames.addAll(createWrappedElementsFromExtension(schema, type, maxStackDepth));

    }

    return qnames;
}
 
Example 8
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 9
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 10
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 11
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 12
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 4 votes vote down vote up
private CorbaType processStruct(XmlSchemaComplexType complex, QName defaultName)
    throws Exception {
    QName name;
    Struct corbaStruct = null;
    QName schematypeName = checkPrefix(complex.getQName());
    if (schematypeName == null) {
        schematypeName = createQNameTargetNamespace(defaultName.getLocalPart());
        if (defaultName.getNamespaceURI().isEmpty()) {
            schematypeName = checkPrefix(schematypeName);
        } else {
            schematypeName = checkPrefix(defaultName);
        }
        name = checkPrefix(createQNameCorbaNamespace(defaultName.getLocalPart()));
    } else {
        name = checkPrefix(createQNameCorbaNamespace(schematypeName.getLocalPart()));
    }

    corbaStruct = (Struct)recursionMap.get(name);
    if (corbaStruct != null) {
        return corbaStruct;
    }

    corbaStruct = new Struct();
    corbaStruct.setName(name.getLocalPart());
    corbaStruct.setQName(name);
    String repoId = REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION;
    corbaStruct.setRepositoryID(repoId);
    corbaStruct.setType(schematypeName);


    recursionMap.put(name, corbaStruct);

    if (complex.getContentModel() instanceof XmlSchemaSimpleContent) {
        corbaStruct = processSimpleContentStruct((XmlSchemaSimpleContent)complex.getContentModel(),
                                                 defaultName, corbaStruct, schematypeName);
    } else if (complex.getContentModel() instanceof XmlSchemaComplexContent) {
        corbaStruct = processComplexContentStruct((XmlSchemaComplexContent)complex.getContentModel(),
                                                  defaultName, corbaStruct, schematypeName);
    }

    // Process attributes at ComplexType level
    if (!complex.getAttributes().isEmpty()) {
        String uri;
        if (schematypeName != null) {
            uri = schematypeName.getNamespaceURI();
        } else {
            uri = defaultName.getNamespaceURI();
        }
        List<MemberType> attlist2 = processAttributesAsMembers(complex.getAttributes(), uri);
        for (int i = 0; i < attlist2.size(); i++) {
            MemberType member = attlist2.get(i);
            corbaStruct.getMember().add(member);
        }
    }

    if (complex.getParticle() != null) {
        List<MemberType> members = processContainerAsMembers(complex.getParticle(),
                                                             defaultName, schematypeName);

        for (MemberType memberType : members) {
            corbaStruct.getMember().add(memberType);
        }
    }

    recursionMap.remove(name);

    return corbaStruct;
}
 
Example 13
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;
}