Search in sources :

Example 56 with XmlSchemaSimpleType

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

the class ParameterMapper method map.

public static JavaParameter map(JavaMethod jm, MessagePartInfo part, JavaType.Style style, ToolContext context) {
    String name = ProcessorUtil.mangleNameToVariableName(part.getName().getLocalPart());
    String namespace = ProcessorUtil.resolvePartNamespace(part);
    String type = ProcessorUtil.resolvePartType(part, context);
    JavaParameter parameter = new JavaParameter(name, type, namespace);
    parameter.setPartName(part.getName().getLocalPart());
    if (part.getXmlSchema() instanceof XmlSchemaSimpleType) {
        processXmlSchemaSimpleType((XmlSchemaSimpleType) part.getXmlSchema(), jm, parameter, part);
    } else if (part.getXmlSchema() instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement) part.getXmlSchema();
        if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            processXmlSchemaSimpleType((XmlSchemaSimpleType) element.getSchemaType(), jm, parameter, part);
        }
    }
    parameter.setQName(ProcessorUtil.getElementName(part));
    parameter.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriter(part, context));
    String fullJavaName = ProcessorUtil.getFullClzName(part, context, false);
    parameter.setClassName(fullJavaName);
    if (style == JavaType.Style.INOUT || style == JavaType.Style.OUT) {
        parameter.setHolder(true);
        parameter.setHolderName(javax.xml.ws.Holder.class.getName());
        String holderClass = fullJavaName;
        if (JAXBUtils.holderClass(fullJavaName) != null) {
            holderClass = JAXBUtils.holderClass(fullJavaName).getName();
        }
        parameter.setClassName(holderClass);
    }
    parameter.setStyle(style);
    return parameter;
}
Also used : XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter)

Example 57 with XmlSchemaSimpleType

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

the class JAXBEncoderDecoder method marshall.

public static void marshall(Marshaller marshaller, Object elValue, MessagePartInfo part, Object source) {
    try {
        // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
        // generate the xml declaration.
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
    } catch (javax.xml.bind.PropertyException e) {
    // intentionally empty.
    }
    Class<?> cls = null;
    if (part != null) {
        cls = part.getTypeClass();
    }
    if (cls == null) {
        cls = null != elValue ? elValue.getClass() : null;
    }
    if (cls != null && cls.isArray() && elValue instanceof Collection) {
        Collection<?> col = (Collection<?>) elValue;
        elValue = col.toArray((Object[]) Array.newInstance(cls.getComponentType(), col.size()));
    }
    try {
        Object mObj = elValue;
        QName elName = null;
        if (part != null) {
            elName = part.getConcreteName();
        }
        if (null != elName) {
            if (part != null && part.getXmlSchema() instanceof XmlSchemaElement) {
                XmlSchemaElement el = (XmlSchemaElement) part.getXmlSchema();
                if (mObj.getClass().isArray() && el.getSchemaType() instanceof XmlSchemaSimpleType && ((XmlSchemaSimpleType) el.getSchemaType()).getContent() instanceof XmlSchemaSimpleTypeList) {
                    mObj = Arrays.asList((Object[]) mObj);
                    writeObject(marshaller, source, newJAXBElement(elName, cls, mObj));
                } else if (part.getMessageInfo().getOperation().isUnwrapped() && (mObj.getClass().isArray() || mObj instanceof List) && el.getMaxOccurs() != 1) {
                    writeArrayObject(marshaller, source, elName, mObj);
                } else {
                    writeObject(marshaller, source, newJAXBElement(elName, cls, mObj));
                }
            } else if (byte[].class == cls && part.getTypeQName() != null && part.getTypeQName().getLocalPart().equals("hexBinary")) {
                mObj = new HexBinaryAdapter().marshal((byte[]) mObj);
                writeObject(marshaller, source, newJAXBElement(elName, String.class, mObj));
            } else if (mObj instanceof JAXBElement) {
                writeObject(marshaller, source, mObj);
            } else if (marshaller.getSchema() != null) {
                // force xsi:type so types can be validated instead of trying to
                // use the RPC/lit element names that aren't in the schema
                writeObject(marshaller, source, newJAXBElement(elName, Object.class, mObj));
            } else {
                writeObject(marshaller, source, newJAXBElement(elName, cls, mObj));
            }
        } else {
            writeObject(marshaller, source, mObj);
        }
    } catch (Fault ex) {
        throw ex;
    } catch (Exception ex) {
        if (ex instanceof javax.xml.bind.MarshalException) {
            javax.xml.bind.MarshalException marshalEx = (javax.xml.bind.MarshalException) ex;
            Message faultMessage = new Message("MARSHAL_ERROR", LOG, marshalEx.getLinkedException().getMessage());
            throw new Fault(faultMessage, ex);
        }
        throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
    }
}
Also used : XmlSchemaSimpleTypeList(org.apache.ws.commons.schema.XmlSchemaSimpleTypeList) HexBinaryAdapter(javax.xml.bind.annotation.adapters.HexBinaryAdapter) Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Fault(org.apache.cxf.interceptor.Fault) JAXBElement(javax.xml.bind.JAXBElement) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) PrivilegedActionException(java.security.PrivilegedActionException) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) Collection(java.util.Collection) XmlSchemaSimpleTypeList(org.apache.ws.commons.schema.XmlSchemaSimpleTypeList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 58 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 59 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 60 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)

Aggregations

XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)60 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)44 QName (javax.xml.namespace.QName)38 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)20 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)13 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)9 XmlSchemaObjectCollection (org.apache.ws.commons.schema.XmlSchemaObjectCollection)9 XmlSchemaGroupBase (org.apache.ws.commons.schema.XmlSchemaGroupBase)8 XmlSchemaParticle (org.apache.ws.commons.schema.XmlSchemaParticle)8 XmlSchemaSimpleTypeRestriction (org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction)8 ArrayList (java.util.ArrayList)6 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)6 ParameterInfo (org.talend.designer.webservice.ws.wsdlinfo.ParameterInfo)6 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)4 Iterator (java.util.Iterator)4 List (java.util.List)4 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)4