Search in sources :

Example 6 with TypeInfo

use of com.sun.xml.ws.spi.db.TypeInfo in project metro-jax-ws by eclipse-ee4j.

the class RuntimeModeler method processDocBareMethod.

/**
 * models a document/literal bare method
 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
 * @param operationName the runtime model <code>JavaMethod</code> instance being created
 * @param method the runtime model <code>JavaMethod</code> instance being created
 */
protected void processDocBareMethod(JavaMethodImpl javaMethod, String operationName, Method method) {
    String resultName = operationName + RESPONSE;
    String resultTNS = targetNamespace;
    String resultPartName = null;
    boolean isResultHeader = false;
    WebResult webResult = getAnnotation(method, WebResult.class);
    if (webResult != null) {
        if (webResult.name().length() > 0)
            resultName = webResult.name();
        if (webResult.targetNamespace().length() > 0)
            resultTNS = webResult.targetNamespace();
        resultPartName = webResult.partName();
        isResultHeader = webResult.header();
    }
    Class returnType = method.getReturnType();
    Type gReturnType = method.getGenericReturnType();
    if (javaMethod.isAsync()) {
        returnType = getAsyncReturnType(method, returnType);
    }
    if ((returnType != null) && (!returnType.getName().equals("void"))) {
        Annotation[] rann = getAnnotations(method);
        if (resultName != null) {
            QName responseQName = new QName(resultTNS, resultName);
            TypeInfo rTypeReference = new TypeInfo(responseQName, returnType, rann);
            rTypeReference.setGenericType(gReturnType);
            metadataReader.getProperties(rTypeReference.properties(), method);
            ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
            if (resultPartName == null || (resultPartName.length() == 0)) {
                resultPartName = resultName;
            }
            returnParameter.setPartName(resultPartName);
            if (isResultHeader) {
                returnParameter.setBinding(ParameterBinding.HEADER);
            } else {
                ParameterBinding rb = getBinding(operationName, resultPartName, false, Mode.OUT);
                returnParameter.setBinding(rb);
            }
            javaMethod.addParameter(returnParameter);
        }
    }
    // get WebParam
    Class<?>[] parameterTypes = method.getParameterTypes();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] pannotations = getParamAnnotations(method);
    int pos = 0;
    for (Class clazzType : parameterTypes) {
        // method.getName();
        String paramName = operationName;
        String partName = null;
        String requestNamespace = targetNamespace;
        boolean isHeader = false;
        // async
        if (javaMethod.isAsync() && AsyncHandler.class.isAssignableFrom(clazzType)) {
            continue;
        }
        boolean isHolder = HOLDER_CLASS.isAssignableFrom(clazzType);
        // set the actual type argument of Holder in the TypeReference
        if (isHolder) {
            if (clazzType == Holder.class)
                clazzType = erasure(((ParameterizedType) genericParameterTypes[pos]).getActualTypeArguments()[0]);
        }
        Mode paramMode = isHolder ? Mode.INOUT : Mode.IN;
        for (Annotation annotation : pannotations[pos]) {
            if (annotation.annotationType() == jakarta.jws.WebParam.class) {
                jakarta.jws.WebParam webParam = (jakarta.jws.WebParam) annotation;
                paramMode = webParam.mode();
                if (isHolder && paramMode == Mode.IN)
                    paramMode = Mode.INOUT;
                isHeader = webParam.header();
                if (isHeader)
                    paramName = "arg" + pos;
                if (paramMode == Mode.OUT && !isHeader)
                    paramName = operationName + RESPONSE;
                if (webParam.name().length() > 0)
                    paramName = webParam.name();
                partName = webParam.partName();
                if (!webParam.targetNamespace().equals("")) {
                    requestNamespace = webParam.targetNamespace();
                }
                break;
            }
        }
        QName requestQName = new QName(requestNamespace, paramName);
        if (!isHeader && paramMode != Mode.OUT)
            javaMethod.setRequestPayloadName(requestQName);
        // doclit/wrapped
        // operationName with upper 1 char
        TypeInfo typeRef = new TypeInfo(requestQName, clazzType, pannotations[pos]);
        metadataReader.getProperties(typeRef.properties(), method, pos);
        typeRef.setGenericType(genericParameterTypes[pos]);
        ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
        if (partName == null || (partName.length() == 0)) {
            partName = paramName;
        }
        param.setPartName(partName);
        if (paramMode == Mode.INOUT) {
            ParameterBinding pb = getBinding(operationName, partName, isHeader, Mode.IN);
            param.setInBinding(pb);
            pb = getBinding(operationName, partName, isHeader, Mode.OUT);
            param.setOutBinding(pb);
        } else {
            if (isHeader) {
                param.setBinding(ParameterBinding.HEADER);
            } else {
                ParameterBinding pb = getBinding(operationName, partName, false, paramMode);
                param.setBinding(pb);
            }
        }
        javaMethod.addParameter(param);
    }
    validateDocBare(javaMethod);
    processExceptions(javaMethod, method);
}
Also used : QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) jakarta.jws(jakarta.jws) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation) ParameterBinding(com.sun.xml.ws.api.model.ParameterBinding) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ExceptionType(com.sun.xml.ws.api.model.ExceptionType)

Example 7 with TypeInfo

use of com.sun.xml.ws.spi.db.TypeInfo in project metro-jax-ws by eclipse-ee4j.

the class AbstractSEIModelImpl method createBondMap.

private void createBondMap(List<TypeInfo> types) {
    for (TypeInfo type : types) {
        XMLBridge binding = bindingContext.createBridge(type);
        xmlBridgeMap.put(type, binding);
    }
}
Also used : XMLBridge(com.sun.xml.ws.spi.db.XMLBridge) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo)

Example 8 with TypeInfo

use of com.sun.xml.ws.spi.db.TypeInfo in project metro-jax-ws by eclipse-ee4j.

the class JAXBContextFactory method createTypeMappings.

static Map<TypeInfo, TypeMappingInfo> createTypeMappings(Collection<TypeInfo> col) {
    Map<TypeInfo, TypeMappingInfo> refs = new HashMap<>();
    if (col == null || col.isEmpty()) {
        return refs;
    }
    for (TypeInfo e : col) {
        if (e.type.equals(WrapperComposite.class)) {
            continue;
        }
        Element xmlElem = findXmlElement(e.properties());
        if (e.isRepeatedElement()) {
            e = repeatedWrapee(e, xmlElem);
            xmlElem = null;
        }
        // First do the obvious check: is the instance already in the map?
        if (refs.get(e) != null) {
            continue;
        }
        TypeMappingInfo tmi = null;
        boolean forceLocal = false;
        for (TypeInfo ti : refs.keySet()) {
            // Workaround for runtime duplicates.
            if (e.tagName.equals(ti.tagName)) {
                if (e.isGlobalElement() && ti.isGlobalElement()) {
                    if (e.type.equals(ti.type)) {
                        // be resolved adequately.
                        if (e.type instanceof Class<?>) {
                            Class<?> clz = (Class<?>) e.type;
                            if (clz.isEnum()) {
                                forceLocal = true;
                                break;
                            } else {
                                tmi = refs.get(ti);
                                break;
                            }
                        } else {
                            tmi = refs.get(ti);
                            break;
                        }
                    } else {
                        // Conflicting types on globals!  May not be
                        // a bullet-proof solution possible.
                        forceLocal = true;
                        break;
                    }
                }
            }
        }
        if (tmi == null) {
            tmi = new TypeMappingInfo();
            tmi.setXmlTagName(e.tagName);
            tmi.setType((e.getGenericType() != null) ? e.getGenericType() : e.type);
            tmi.setNillable(e.isNillable());
            if (e.getGenericType() != null) {
                String gts = e.getGenericType().toString();
                if (gts.startsWith("jakarta.xml.ws.Holder")) {
                    tmi.setType(e.type);
                } else if (gts.startsWith("jakarta.xml.ws.Response")) {
                    tmi.setType(e.type);
                } else if (gts.startsWith("java.util.concurrent.Future")) {
                    tmi.setType(e.type);
                }
                if (Object.class.equals(e.type)) {
                    tmi.setType(e.type);
                // System.out.println(e.getGenericType().getClass() + " "
                // + e.type);
                }
                if (tmi.getType() instanceof GenericArrayType) {
                    tmi.setType(typeToClass(tmi.getType(), null));
                }
            }
            // Filter out non-JAXB annotations.
            Annotation[] aa = e.annotations;
            if (aa != null && aa.length != 0) {
                List<Annotation> la = new ArrayList<>();
                for (Annotation a : aa) {
                    for (Class<?> clz : a.getClass().getInterfaces()) {
                        if (clz.getName().startsWith("jakarta.xml.bind.annotation.")) {
                            la.add(a);
                            break;
                        }
                    }
                }
                aa = la.toArray(new Annotation[0]);
            // System.out.println("filtered: " + la);
            }
            tmi.setAnnotations(aa);
            if (forceLocal) {
                tmi.setElementScope(ElementScope.Local);
            } else {
                tmi.setElementScope(e.isGlobalElement() ? ElementScope.Global : ElementScope.Local);
            }
            tmi.setXmlElement(xmlElem);
        }
        refs.put(e, tmi);
    }
    return refs;
}
Also used : HashMap(java.util.HashMap) XmlElement(jakarta.xml.bind.annotation.XmlElement) Element(org.w3c.dom.Element) XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) ArrayList(java.util.ArrayList) GenericArrayType(java.lang.reflect.GenericArrayType) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo)

Example 9 with TypeInfo

use of com.sun.xml.ws.spi.db.TypeInfo in project metro-jax-ws by eclipse-ee4j.

the class JAXBRIContextFactory method typeInfoMappings.

private Map<TypeInfo, TypeReference> typeInfoMappings(Collection<TypeInfo> typeInfos) {
    Map<TypeInfo, TypeReference> map = new java.util.HashMap<>();
    for (TypeInfo ti : typeInfos) {
        Type type = WrapperComposite.class.equals(ti.type) ? CompositeStructure.class : ti.type;
        TypeReference tr = new TypeReference(ti.tagName, type, ti.annotations);
        map.put(ti, tr);
    }
    return map;
}
Also used : Type(java.lang.reflect.Type) WrapperComposite(com.sun.xml.ws.spi.db.WrapperComposite) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo)

Example 10 with TypeInfo

use of com.sun.xml.ws.spi.db.TypeInfo in project metro-jax-ws by eclipse-ee4j.

the class JAXBRIContextFactory method newContext.

@Override
public BindingContext newContext(BindingInfo bi) {
    Class[] classes = bi.contentClasses().toArray(new Class[0]);
    for (int i = 0; i < classes.length; i++) {
        if (WrapperComposite.class.equals(classes[i])) {
            classes[i] = CompositeStructure.class;
        }
    }
    Map<TypeInfo, TypeReference> typeInfoMappings = typeInfoMappings(bi.typeInfos());
    Map<Class, Class> subclassReplacements = bi.subclassReplacements();
    String defaultNamespaceRemap = bi.getDefaultNamespace();
    Boolean c14nSupport = (Boolean) bi.properties().get("c14nSupport");
    RuntimeAnnotationReader ar = (RuntimeAnnotationReader) bi.properties().get("org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader");
    JAXBContextFactory jaxbContextFactory = (JAXBContextFactory) bi.properties().get(JAXBContextFactory.class.getName());
    try {
        JAXBRIContext context = (jaxbContextFactory != null) ? jaxbContextFactory.createJAXBContext(bi.getSEIModel(), toList(classes), toList(typeInfoMappings.values())) : ContextFactory.createContext(classes, typeInfoMappings.values(), subclassReplacements, defaultNamespaceRemap, (c14nSupport != null) ? c14nSupport : false, ar, false, false, false);
        return new JAXBRIContextWrapper(context, typeInfoMappings);
    } catch (Exception e) {
        throw new DatabindingException(e);
    }
}
Also used : TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) RuntimeAnnotationReader(org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader) JAXBContextFactory(com.sun.xml.ws.developer.JAXBContextFactory) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference)

Aggregations

TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)10 Annotation (java.lang.annotation.Annotation)5 Type (java.lang.reflect.Type)5 ExceptionType (com.sun.xml.ws.api.model.ExceptionType)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 QName (javax.xml.namespace.QName)4 Mode (jakarta.jws.WebParam.Mode)3 XmlElement (jakarta.xml.bind.annotation.XmlElement)3 ParameterBinding (com.sun.xml.ws.api.model.ParameterBinding)2 JAXBContextFactory (com.sun.xml.ws.developer.JAXBContextFactory)2 DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)2 WrapperComposite (com.sun.xml.ws.spi.db.WrapperComposite)2 jakarta.jws (jakarta.jws)2 XmlRootElement (jakarta.xml.bind.annotation.XmlRootElement)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TypeMappingInfo (org.eclipse.persistence.jaxb.TypeMappingInfo)2 TypeReference (org.glassfish.jaxb.runtime.api.TypeReference)2 Element (org.w3c.dom.Element)2