Search in sources :

Example 1 with XmlSchemaAnyAttribute

use of org.apache.ws.commons.schema.XmlSchemaAnyAttribute 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 2 with XmlSchemaAnyAttribute

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

the class AttributeInfo method forLocalItem.

/**
 * Fill in an AttributeInfo for an attribute or anyAttribute from a sequence.
 *
 * @param sequenceElement
 * @param currentSchema
 * @param schemaCollection
 * @param prefixAccumulator
 * @return
 */
public static AttributeInfo forLocalItem(XmlSchemaObject sequenceObject, XmlSchema currentSchema, SchemaCollection schemaCollection, NamespacePrefixAccumulator prefixAccumulator, QName contextName) {
    XmlSchemaAnnotated annotated = JavascriptUtils.getObjectAnnotated(sequenceObject, contextName);
    AttributeInfo attributeInfo = new AttributeInfo();
    XmlSchemaAnnotated realAnnotated = annotated;
    if (annotated instanceof XmlSchemaAttribute) {
        XmlSchemaAttribute attribute = (XmlSchemaAttribute) annotated;
        attributeInfo.use = attribute.getUse();
        if (attribute.getRef().getTarget() != null) {
            realAnnotated = attribute.getRef().getTarget();
            attributeInfo.global = true;
        }
    } else if (annotated instanceof XmlSchemaAnyAttribute) {
        attributeInfo.any = true;
        // unknown until runtime.
        attributeInfo.xmlName = null;
        attributeInfo.javascriptName = "any";
        // runtime for any.
        attributeInfo.type = null;
        attributeInfo.use = XmlSchemaUse.OPTIONAL;
    } else {
        throw new UnsupportedConstruct(LOG, "UNSUPPORTED_ATTRIBUTE_ITEM", annotated, contextName);
    }
    factoryCommon(realAnnotated, currentSchema, schemaCollection, prefixAccumulator, attributeInfo);
    attributeInfo.annotated = realAnnotated;
    return attributeInfo;
}
Also used : XmlSchemaAnnotated(org.apache.ws.commons.schema.XmlSchemaAnnotated) XmlSchemaAnyAttribute(org.apache.ws.commons.schema.XmlSchemaAnyAttribute) XmlSchemaAttribute(org.apache.ws.commons.schema.XmlSchemaAttribute)

Aggregations

XmlSchemaAnyAttribute (org.apache.ws.commons.schema.XmlSchemaAnyAttribute)2 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)2 QName (javax.xml.namespace.QName)1 AegisType (org.apache.cxf.aegis.type.AegisType)1 XmlSchemaAnnotated (org.apache.ws.commons.schema.XmlSchemaAnnotated)1 XmlSchemaAny (org.apache.ws.commons.schema.XmlSchemaAny)1 XmlSchemaComplexContent (org.apache.ws.commons.schema.XmlSchemaComplexContent)1 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)1 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)1