Search in sources :

Example 61 with XmlSchemaSimpleType

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

the class EnumType method writeSchema.

@Override
public void writeSchema(XmlSchema root) {
    XmlSchemaSimpleType simple = new XmlSchemaSimpleType(root, true);
    simple.setName(getSchemaType().getLocalPart());
    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
    restriction.setBaseTypeName(Constants.XSD_STRING);
    simple.setContent(restriction);
    Object[] constants = getTypeClass().getEnumConstants();
    List<XmlSchemaFacet> facets = restriction.getFacets();
    for (Object constant : constants) {
        XmlSchemaEnumerationFacet f = new XmlSchemaEnumerationFacet();
        f.setValue(getValue(constant));
        facets.add(f);
    }
}
Also used : XmlSchemaFacet(org.apache.ws.commons.schema.XmlSchemaFacet) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) XmlSchemaEnumerationFacet(org.apache.ws.commons.schema.XmlSchemaEnumerationFacet)

Example 62 with XmlSchemaSimpleType

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

the class CustomStringType method writeSchema.

@Override
public void writeSchema(XmlSchema root) {
    // this mapping gets used with xs:string, and we might get called.
    if (root.getTargetNamespace().equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
        return;
    }
    XmlSchemaSimpleType type = new XmlSchemaSimpleType(root, true);
    type.setName(getSchemaType().getLocalPart());
    XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension();
    ext.setBaseTypeName(Constants.XSD_STRING);
    XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction();
    content.setBaseTypeName(Constants.XSD_STRING);
    type.setContent(content);
}
Also used : XmlSchemaSimpleContentExtension(org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction)

Example 63 with XmlSchemaSimpleType

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

the class JAXBSchemaInitializer method begin.

@Override
public void begin(MessagePartInfo part) {
    // Check to see if the WSDL information has been filled in for us.
    if (part.getTypeQName() != null || part.getElementQName() != null) {
        checkForExistence(part);
        return;
    }
    Class<?> clazz = part.getTypeClass();
    if (clazz == null) {
        return;
    }
    boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
    boolean isList = false;
    if (clazz.isArray()) {
        if (isFromWrapper && !Byte.TYPE.equals(clazz.getComponentType())) {
            clazz = clazz.getComponentType();
        } else if (!isFromWrapper) {
            Annotation[] anns = (Annotation[]) part.getProperty("parameter.annotations");
            for (Annotation a : anns) {
                if (a instanceof XmlList) {
                    part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
                    clazz = clazz.getComponentType();
                    isList = true;
                }
            }
        }
    }
    Annotation[] anns = (Annotation[]) part.getProperty("parameter.annotations");
    XmlJavaTypeAdapter jta = findFromTypeAdapter(context, clazz, anns);
    JAXBBeanInfo jtaBeanInfo = null;
    if (jta != null) {
        jtaBeanInfo = findFromTypeAdapter(context, jta.value());
    }
    JAXBBeanInfo beanInfo = getBeanInfo(clazz);
    if (jtaBeanInfo != beanInfo && jta != null) {
        beanInfo = jtaBeanInfo;
        if (anns == null) {
            anns = new Annotation[] { jta };
        } else {
            boolean found = false;
            for (Annotation t : anns) {
                if (t == jta) {
                    found = true;
                }
            }
            if (!found) {
                Annotation[] tmp = new Annotation[anns.length + 1];
                System.arraycopy(anns, 0, tmp, 0, anns.length);
                tmp[anns.length] = jta;
                anns = tmp;
            }
        }
        part.setProperty("parameter.annotations", anns);
        part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
    }
    if (beanInfo == null) {
        if (Exception.class.isAssignableFrom(clazz)) {
            QName name = (QName) part.getMessageInfo().getProperty("elementName");
            part.setElementQName(name);
            buildExceptionType(part, clazz);
        }
        return;
    }
    boolean isElement = beanInfo.isElement() && !Boolean.TRUE.equals(part.getMessageInfo().getOperation().getProperty("operation.force.types"));
    boolean hasType = !beanInfo.getTypeNames().isEmpty();
    if (isElement && isFromWrapper && hasType) {
        // if there is both a Global element and a global type, AND we are in a wrapper,
        // make sure we use the type instead of a ref to the element to
        // match the rules for wrapped/unwrapped
        isElement = false;
    }
    part.setElement(isElement);
    if (isElement) {
        QName name = new QName(beanInfo.getElementNamespaceURI(null), beanInfo.getElementLocalName(null));
        XmlSchemaElement el = schemas.getElementByQName(name);
        if (el != null && el.getRef().getTarget() != null) {
            part.setTypeQName(el.getRef().getTargetQName());
        } else {
            part.setElementQName(name);
        }
        part.setXmlSchema(el);
    } else {
        QName typeName = getTypeName(beanInfo);
        if (typeName != null) {
            XmlSchemaType type = schemas.getTypeByQName(typeName);
            if (isList && type instanceof XmlSchemaSimpleType) {
                XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(type.getParent(), false);
                XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
                XmlSchemaSimpleType stype = (XmlSchemaSimpleType) type;
                list.setItemTypeName(stype.getQName());
                simpleType.setContent(list);
                part.setXmlSchema(simpleType);
                if (part.getConcreteName() == null) {
                    part.setConcreteName(new QName(null, part.getName().getLocalPart()));
                }
            } else {
                part.setTypeQName(typeName);
                part.setXmlSchema(type);
            }
        }
    }
}
Also used : XmlSchemaSimpleTypeList(org.apache.ws.commons.schema.XmlSchemaSimpleTypeList) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) JAXBBeanInfo(org.apache.cxf.common.jaxb.JAXBBeanInfo) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) Annotation(java.lang.annotation.Annotation) XmlList(javax.xml.bind.annotation.XmlList)

Example 64 with XmlSchemaSimpleType

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

the class FixedVisitor method visit.

public void visit(AST fixedNode) {
    // "typedef" <type_declarator>
    // <type_declarator> ::= <type_spec> <declarators>
    // <type_spec> ::= <simple_type_spec>
    // | <constr_type_spec>
    // <simple_type_spec> ::= <base_type_spec>
    // | <template_type_spec>
    // | <scoped_name>
    // <base_type_spec> ::= ... omitted (integer, char, octect, etc)
    // <template_type_spec> ::= <sequence_type>
    // | <string_type>
    // | <wstring_type>
    // | <fixed_pt_type>
    // <constr_type_spec> ::= <struct_type>
    // | <union_type>
    // | <enum_type>
    // <declarators> ::= <declarator> {"," <declarator>}*
    // <declarator> ::= <simple_declarator>
    // | <complex_declarator>
    // <simple_declarator> ::= <identifier>
    // <complex_declarator> ::= <array_declarator>
    // <array_declarator> ::= <identifier> <fixed_array_size>+
    // <fixed_array_size> ::= "[" <positive_int_const> "]"
    AST digitsNode = fixedNode.getFirstChild();
    AST scaleNode = digitsNode.getNextSibling();
    final Scope scopedName;
    if (identifierNode == null) {
        scopedName = TypesUtils.generateAnonymousScopedName(getScope(), schema);
    } else {
        scopedName = new Scope(getScope(), identifierNode);
    }
    // validate digits and scale
    Long digits = Long.valueOf(digitsNode.toString());
    Long scale = Long.valueOf(scaleNode.toString());
    if (digits < 1 || digits > 31) {
        // throw IllegalIDLException();
        System.out.println("Digits cannot be greater than 31");
        return;
    }
    if (scale.compareTo(digits) > 0) {
        // throw IllegalIDLException();
        System.out.println("Scale cannot be greater than digits");
        return;
    }
    // xmlschema:fixed
    XmlSchemaSimpleType fixedSimpleType = new XmlSchemaSimpleType(schema, true);
    XmlSchemaSimpleTypeRestriction fixedRestriction = new XmlSchemaSimpleTypeRestriction();
    fixedRestriction.setBaseTypeName(Constants.XSD_DECIMAL);
    XmlSchemaTotalDigitsFacet fixedTotalDigits = new XmlSchemaTotalDigitsFacet();
    fixedTotalDigits.setValue(digitsNode.toString());
    XmlSchemaFractionDigitsFacet fixedFractionDigits = new XmlSchemaFractionDigitsFacet();
    fixedFractionDigits.setValue(scaleNode.toString());
    fixedFractionDigits.setFixed(true);
    fixedRestriction.getFacets().add(fixedTotalDigits);
    fixedRestriction.getFacets().add(fixedFractionDigits);
    fixedSimpleType.setName(mapper.mapToQName(scopedName));
    fixedSimpleType.setContent(fixedRestriction);
    // add xmlschema:fixed
    setSchemaType(fixedSimpleType);
    final CorbaType type;
    if (identifierNode != null) {
        // corba:fixed
        Fixed corbaFixed = new Fixed();
        corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
        corbaFixed.setDigits(digits);
        corbaFixed.setScale(scale);
        corbaFixed.setRepositoryID(scopedName.toIDLRepositoryID());
        // corbaFixed.setType(Constants.XSD_DECIMAL);
        corbaFixed.setType(fixedSimpleType.getQName());
        type = corbaFixed;
    } else {
        // corba:anonfixed
        Anonfixed corbaFixed = new Anonfixed();
        corbaFixed.setQName(new QName(typeMap.getTargetNamespace(), scopedName.toString()));
        corbaFixed.setDigits(digits);
        corbaFixed.setScale(scale);
        // corbaFixed.setType(Constants.XSD_DECIMAL);
        corbaFixed.setType(fixedSimpleType.getQName());
        typeMap.getStructOrExceptionOrUnion().add(corbaFixed);
        type = corbaFixed;
    }
    // add corba:fixed
    setCorbaType(type);
}
Also used : Anonfixed(org.apache.cxf.binding.corba.wsdl.Anonfixed) AST(antlr.collections.AST) XmlSchemaTotalDigitsFacet(org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet) XmlSchemaFractionDigitsFacet(org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) XmlSchemaSimpleTypeRestriction(org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction) Fixed(org.apache.cxf.binding.corba.wsdl.Fixed)

Example 65 with XmlSchemaSimpleType

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

the class ObjectReferenceVisitor method visitCustomTypeObjectReference.

private void visitCustomTypeObjectReference(AST node) {
    QName bindingName = null;
    QName referenceName = null;
    String repositoryID = null;
    Scope currentScope = getScope();
    Scope customScope = null;
    if ((node.getFirstChild() == null) || (node.getFirstChild() != null && node.getFirstChild().getType() != IDLTokenTypes.SCOPEOP)) {
        while (bindingName == null && currentScope != currentScope.getParent()) {
            if (ScopedNameVisitor.isFullyScopedName(node)) {
                customScope = ScopedNameVisitor.getFullyScopedName(currentScope, node);
            } else {
                customScope = new Scope(currentScope, node);
            }
            if (mapper.isDefaultMapping()) {
                referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
            } else {
                String tns = mapper.map(customScope.getParent());
                referenceName = new QName(tns, customScope.tail() + "Ref");
            }
            repositoryID = customScope.toIDLRepositoryID();
            bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
            currentScope = currentScope.getParent();
        }
    }
    if (bindingName == null) {
        // Global scope is our last chance to resolve the node
        if (ScopedNameVisitor.isFullyScopedName(node)) {
            customScope = ScopedNameVisitor.getFullyScopedName(new Scope(), node);
            if (mapper.isDefaultMapping()) {
                referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
            } else {
                String tns = mapper.map(customScope.getParent());
                referenceName = new QName(tns, customScope.tail() + "Ref");
            }
        } else {
            // customScope = currentScope;
            customScope = new Scope(new Scope(), node);
            if (mapper.isDefaultMapping()) {
                referenceName = new QName(schema.getTargetNamespace(), customScope.toString() + "Ref");
            } else {
                String tns = mapper.map(customScope.getParent());
                referenceName = new QName(tns, customScope.tail() + "Ref");
            }
        }
        repositoryID = customScope.toIDLRepositoryID();
        bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
        if (bindingName == null) {
            // check bindingName with prefix
            customScope.setPrefix(objRefWsdlVisitor.getPragmaPrefix());
            repositoryID = customScope.toIDLRepositoryID();
            bindingName = getBindingQNameByID(definition, repositoryID, objRefWsdlVisitor);
        }
    }
    if (bindingName == null) {
        // We need to have a binding for this kind of object reference to work
        throw new RuntimeException("[ObjectReferenceVisitor: No binding available for endpoint]");
    }
    // Create a schema namespace for WS addressing and use it to create an endpoint
    // reference type.  This will be used as the type for our endpoint reference.
    XmlSchema[] scs = schemas.getXmlSchema(ReferenceConstants.WSADDRESSING_NAMESPACE);
    XmlSchema wsaSchema = null;
    if (scs != null) {
        for (XmlSchema sc : scs) {
            if (ReferenceConstants.WSADDRESSING_NAMESPACE.equals(sc.getTargetNamespace())) {
                wsaSchema = sc;
                break;
            }
        }
    }
    if (wsaSchema == null) {
        wsaSchema = new XmlSchema(ReferenceConstants.WSADDRESSING_NAMESPACE, schemas);
    }
    XmlSchemaType wsaType = new XmlSchemaSimpleType(wsaSchema, true);
    wsaType.setName(ReferenceConstants.WSADDRESSING_LOCAL_NAME);
    // Check to see if we have already defined an element for this reference type.  If
    // we have, then there is no need to add it to the schema again.
    isDuplicateReference(referenceName, bindingName, customScope, wsaType, node);
    setSchemaType(wsaType);
    // Build and assign the corba:object to the visitor
    Object corbaObject = new Object();
    corbaObject.setBinding(bindingName);
    corbaObject.setQName(new QName(typeMap.getTargetNamespace(), customScope.toString()));
    corbaObject.setRepositoryID(repositoryID);
    corbaObject.setType(wsaType.getQName());
    setCorbaType(corbaObject);
    // type once.
    if (!isReferenceCORBATypeDefined(corbaObject.getQName())) {
        typeMap.getStructOrExceptionOrUnion().add(corbaObject);
    }
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) Object(org.apache.cxf.binding.corba.wsdl.Object) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Aggregations

XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)69 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)47 QName (javax.xml.namespace.QName)46 XmlSchema (org.apache.ws.commons.schema.XmlSchema)31 Test (org.junit.Test)27 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)26 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)21 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)14 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)11 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)10 ArrayList (java.util.ArrayList)8 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)8 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)8 XmlSchemaSimpleTypeList (org.apache.ws.commons.schema.XmlSchemaSimpleTypeList)8 XmlSchemaSimpleTypeRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction)8 List (java.util.List)7 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)7 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)6 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4