Search in sources :

Example 51 with XmlSchemaElement

use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.

the class XmlSchemaUtils method findElementByRefName.

/**
 * This copes with an observed phenomenon in the schema built by the
 * ReflectionServiceFactoryBean. It is creating element such that: (a) the
 * type is not set. (b) the refName is set. (c) the namespaceURI in the
 * refName is set empty. This apparently indicates 'same Schema' to everyone
 * else, so thus function implements that convention here. It is unclear if
 * that is a correct structure, and it if changes, we can simplify or
 * eliminate this function.
 *
 * @param name
 * @param referencingURI
 */
public static XmlSchemaElement findElementByRefName(SchemaCollection xmlSchemaCollection, QName name, String referencingURI) {
    String uri = name.getNamespaceURI();
    if ("".equals(uri)) {
        uri = referencingURI;
    }
    QName copyName = new QName(uri, name.getLocalPart());
    XmlSchemaElement target = xmlSchemaCollection.getElementByQName(copyName);
    assert target != null;
    return target;
}
Also used : QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement)

Example 52 with XmlSchemaElement

use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.

the class SchemaCollectionContextProxy method getBeanInfo.

public Object getBeanInfo(Class<?> cls) {
    Class<?> origCls = cls;
    String postfix = "";
    while (cls.isArray()) {
        cls = cls.getComponentType();
        postfix = "Array";
    }
    XmlRootElement xre = cls.getAnnotation(XmlRootElement.class);
    String name = xre == null ? "##default" : xre.name();
    String namespace = xre == null ? "##default" : xre.namespace();
    if ("##default".equals(name)) {
        name = java.beans.Introspector.decapitalize(cls.getSimpleName());
    }
    if ("##default".equals(namespace) && cls.getPackage() != null) {
        XmlSchema sc = cls.getPackage().getAnnotation(XmlSchema.class);
        if (sc != null) {
            namespace = sc.namespace();
        }
    }
    if ("##default".equals(namespace) || StringUtils.isEmpty(namespace)) {
        namespace = JAXBUtils.getPackageNamespace(cls);
        if (namespace == null) {
            namespace = defaultNamespace;
        }
    }
    final QName qname = new QName(namespace, name + postfix);
    final XmlSchemaElement el = schemas.getElementByQName(qname);
    XmlSchemaType type = null;
    if (el != null) {
        type = el.getSchemaType();
    }
    if (type == null) {
        type = schemas.getTypeByQName(getTypeQName(origCls, namespace));
        if (type == null) {
            type = schemas.getTypeByQName(qname);
        }
    }
    if (type == null) {
        type = mapToSchemaType(origCls, namespace);
    /*
            if (type == null) {
                type = mapToSchemaType(cls, namespace);
            }
            */
    }
    if (el == null && type == null) {
        return null;
    }
    final QName typeName = type == null ? null : type.getQName();
    return new JAXBBeanInfo() {

        public boolean isElement() {
            return el == null ? false : true;
        }

        public Collection<QName> getTypeNames() {
            return Collections.singletonList(typeName);
        }

        public String getElementNamespaceURI(Object object) {
            return qname.getNamespaceURI();
        }

        public String getElementLocalName(Object object) {
            return qname.getLocalPart();
        }
    };
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) XmlSchema(javax.xml.bind.annotation.XmlSchema) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 53 with XmlSchemaElement

use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.

the class ServiceModelUtil method getOperationInputPartNames.

public static List<String> getOperationInputPartNames(OperationInfo operation) {
    List<String> names = new ArrayList<>();
    List<MessagePartInfo> parts = operation.getInput().getMessageParts();
    if (parts == null || parts.isEmpty()) {
        return names;
    }
    for (MessagePartInfo part : parts) {
        XmlSchemaAnnotated schema = part.getXmlSchema();
        if (schema instanceof XmlSchemaElement && ((XmlSchemaElement) schema).getSchemaType() instanceof XmlSchemaComplexType) {
            XmlSchemaElement element = (XmlSchemaElement) schema;
            XmlSchemaComplexType cplxType = (XmlSchemaComplexType) element.getSchemaType();
            XmlSchemaSequence seq = (XmlSchemaSequence) cplxType.getParticle();
            if (seq == null || seq.getItems() == null) {
                return names;
            }
            for (int i = 0; i < seq.getItems().size(); i++) {
                XmlSchemaElement elChild = (XmlSchemaElement) seq.getItems().get(i);
                names.add(elChild.getName());
            }
        } else {
            names.add(part.getConcreteName().getLocalPart());
        }
    }
    return names;
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) ArrayList(java.util.ArrayList) XmlSchemaAnnotated(org.apache.ws.commons.schema.XmlSchemaAnnotated) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 54 with XmlSchemaElement

use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.

the class BeanType method writeSchema.

@Override
public void writeSchema(XmlSchema root) {
    BeanTypeInfo inf = getTypeInfo();
    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());
    AegisType sooperType = getSuperType();
    /*
         * See Java Virtual Machine specification:
         * http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#75734
         */
    if (((inf.getTypeClass().getModifiers() & Modifier.ABSTRACT) != 0) && !inf.getTypeClass().isInterface()) {
        complex.setAbstract(true);
    }
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    /*
         * Decide if we're going to extend another type. If we are going to defer, then make sure that we
         * extend the type for our superclass.
         */
    boolean isExtension = inf.isExtension();
    if (isExtension && sooperType != null) {
        // if sooperType is null, things are confused.
        XmlSchemaComplexContent content = new XmlSchemaComplexContent();
        complex.setContentModel(content);
        XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
        content.setContent(extension);
        extension.setBaseTypeName(sooperType.getSchemaType());
        extension.setParticle(sequence);
    } else {
        complex.setParticle(sequence);
    }
    boolean needXmime = false;
    boolean needUtilityTypes = false;
    // Write out schema for elements
    for (QName name : inf.getElements()) {
        if (isInheritedProperty(inf, name)) {
            continue;
        }
        XmlSchemaElement element = new XmlSchemaElement(root, false);
        element.setName(name.getLocalPart());
        sequence.getItems().add(element);
        AegisType type = getType(inf, name);
        if (type.isFlatArray()) {
            // ok, we need some tricks here
            element.setMinOccurs(type.getMinOccurs());
            element.setMaxOccurs(type.getMaxOccurs());
            // for now, assume ArrayType. Look at lists or more general solutions later.
            ArrayType aType = (ArrayType) type;
            type = aType.getComponentType();
            element.setNillable(type.isNillable());
        } else {
            if (AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS.equals(type.getSchemaType().getNamespaceURI())) {
                XmlSchemaUtils.addImportIfNeeded(root, AbstractTypeCreator.HTTP_CXF_APACHE_ORG_ARRAYS);
            }
        }
        writeTypeReference(name, element, type, root);
        needXmime |= type.usesXmime();
        needUtilityTypes |= type.usesUtilityTypes();
    }
    if (needXmime) {
        addXmimeToSchema(root);
    }
    if (needUtilityTypes) {
        AegisContext.addUtilityTypesToSchema(root);
    }
    /**
     * if future proof then add <xsd:any/> element
     */
    if (inf.isExtensibleElements()) {
        XmlSchemaAny any = new XmlSchemaAny();
        any.setMinOccurs(0);
        any.setMaxOccurs(Long.MAX_VALUE);
        sequence.getItems().add(any);
    }
    // Write out schema for attributes
    for (QName name : inf.getAttributes()) {
        if (isInheritedProperty(inf, name)) {
            continue;
        }
        XmlSchemaAttribute attribute = new XmlSchemaAttribute(root, false);
        complex.getAttributes().add(attribute);
        attribute.setName(name.getLocalPart());
        AegisType type = getType(inf, name);
        attribute.setSchemaTypeName(type.getSchemaType());
        String ns = name.getNamespaceURI();
        if (!ns.equals(root.getTargetNamespace())) {
            XmlSchemaUtils.addImportIfNeeded(root, ns);
        }
    }
    /**
     * If extensible attributes then add <xsd:anyAttribute/>
     */
    if (inf.isExtensibleAttributes()) {
        complex.setAnyAttribute(new XmlSchemaAnyAttribute());
    }
}
Also used : XmlSchemaComplexContentExtension(org.apache.ws.commons.schema.XmlSchemaComplexContentExtension) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaAny(org.apache.ws.commons.schema.XmlSchemaAny) XmlSchemaComplexContent(org.apache.ws.commons.schema.XmlSchemaComplexContent) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute) XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) XmlSchemaAnyAttribute(org.apache.ws.commons.schema.XmlSchemaAnyAttribute)

Example 55 with XmlSchemaElement

use of org.apache.ws.commons.schema.XmlSchemaElement in project cxf by apache.

the class MapType method writeSchema.

@Override
public void writeSchema(XmlSchema root) {
    XmlSchemaComplexType complex = new XmlSchemaComplexType(root, true);
    complex.setName(getSchemaType().getLocalPart());
    XmlSchemaSequence sequence = new XmlSchemaSequence();
    complex.setParticle(sequence);
    AegisType kType = getKeyType();
    AegisType vType = getValueType();
    XmlSchemaElement element = new XmlSchemaElement(root, false);
    sequence.getItems().add(element);
    element.setName(getEntryName().getLocalPart());
    element.setMinOccurs(0);
    element.setMaxOccurs(Long.MAX_VALUE);
    XmlSchemaComplexType evType = new XmlSchemaComplexType(root, false);
    element.setType(evType);
    XmlSchemaSequence evSequence = new XmlSchemaSequence();
    evType.setParticle(evSequence);
    createElement(root, evSequence, getKeyName(), kType, false);
    createElement(root, evSequence, getValueName(), vType, true);
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) AegisType(org.apache.cxf.aegis.type.AegisType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType)

Aggregations

XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)164 QName (javax.xml.namespace.QName)100 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)59 XmlSchema (org.apache.ws.commons.schema.XmlSchema)54 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)51 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)42 Test (org.junit.Test)42 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)39 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)32 Message (org.apache.cxf.common.i18n.Message)15 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)15 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)14 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)13 ArrayList (java.util.ArrayList)12 JAXBBeanInfo (org.apache.cxf.common.jaxb.JAXBBeanInfo)12 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)12 Method (java.lang.reflect.Method)11 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)11 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)10 Iterator (java.util.Iterator)9