Search in sources :

Example 1 with TypeInfo

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

the class AbstractSEIModelImpl method createJAXBContext.

private void createJAXBContext() {
    final List<TypeInfo> types = getAllTypeInfos();
    final List<Class> cls = new ArrayList<>(types.size() + additionalClasses.size());
    cls.addAll(additionalClasses);
    for (TypeInfo type : types) {
        cls.add((Class) type.type);
    }
    try {
        // jaxbContext = JAXBRIContext.newInstance(cls, types, targetNamespace, false);
        // Need to avoid doPriv block once JAXB is fixed. Afterwards, use the above
        bindingContext = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {

            @Override
            public BindingContext run() throws Exception {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.log(Level.FINEST, "Creating JAXBContext with classes={0} and types={1}", new Object[] { cls, types });
                }
                UsesJAXBContextFeature f = features.get(UsesJAXBContextFeature.class);
                com.oracle.webservices.api.databinding.DatabindingModeFeature dmf = features.get(com.oracle.webservices.api.databinding.DatabindingModeFeature.class);
                JAXBContextFactory factory = f != null ? f.getFactory() : null;
                if (factory == null)
                    factory = JAXBContextFactory.DEFAULT;
                // return factory.createJAXBContext(AbstractSEIModelImpl.this,cls,types);
                databindingInfo.properties().put(JAXBContextFactory.class.getName(), factory);
                if (dmf != null) {
                    if (LOGGER.isLoggable(Level.FINE))
                        LOGGER.log(Level.FINE, "DatabindingModeFeature in SEI specifies mode: {0}", dmf.getMode());
                    databindingInfo.setDatabindingMode(dmf.getMode());
                }
                if (f != null)
                    databindingInfo.setDatabindingMode(BindingContextFactory.DefaultDatabindingMode);
                databindingInfo.setClassLoader(classLoader);
                databindingInfo.contentClasses().addAll(cls);
                databindingInfo.typeInfos().addAll(types);
                databindingInfo.properties().put("c14nSupport", Boolean.FALSE);
                databindingInfo.setDefaultNamespace(AbstractSEIModelImpl.this.getDefaultSchemaNamespace());
                BindingContext bc = BindingContextFactory.create(databindingInfo);
                if (LOGGER.isLoggable(Level.FINE))
                    LOGGER.log(Level.FINE, "Created binding context: {0}", bc.getClass().getName());
                // System.out.println("---------------------- databinding " + bc);
                return bc;
            }
        });
        // createBridgeMap(types);
        createBondMap(types);
    } catch (PrivilegedActionException e) {
        throw new WebServiceException(ModelerMessages.UNABLE_TO_CREATE_JAXB_CONTEXT(), e);
    }
    knownNamespaceURIs = new ArrayList<>();
    for (String namespace : bindingContext.getKnownNamespaceURIs()) {
        if (namespace.length() > 0) {
            if (!namespace.equals(SOAPNamespaceConstants.XSD) && !namespace.equals(SOAPNamespaceConstants.XMLNS))
                knownNamespaceURIs.add(namespace);
        }
    }
    marshallers = new Pool.Marshaller(jaxbContext);
// return getJAXBContext();
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) BindingContext(com.sun.xml.ws.spi.db.BindingContext) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) UsesJAXBContextFeature(com.sun.xml.ws.developer.UsesJAXBContextFeature) JAXBContextFactory(com.sun.xml.ws.developer.JAXBContextFactory) Pool(com.sun.xml.ws.util.Pool)

Example 2 with TypeInfo

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

the class RuntimeModeler method processRpcMethod.

/**
 * models a rpc/literal method
 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
 * @param methodName the name of the <code>method</code> being modeled.
 * @param operationName the WSDL operation name for this <code>method</code>
 * @param method the runtime model <code>JavaMethod</code> instance being created
 */
protected void processRpcMethod(JavaMethodImpl javaMethod, String methodName, String operationName, Method method) {
    boolean isOneway = getAnnotation(method, Oneway.class) != null;
    // use Map to build parameters in the part order when they are known.
    // if part is unbound, we just put them at the end, and for that we
    // use a large index (10000+) to avoid colliding with ordered ones.
    // this assumes that there's no operation with # of parameters > 10000,
    // but I think it's a pretty safe assumption - KK.
    Map<Integer, ParameterImpl> resRpcParams = new TreeMap<>();
    Map<Integer, ParameterImpl> reqRpcParams = new TreeMap<>();
    // Lets take the service namespace and overwrite it with the one we get it from wsdl
    String reqNamespace = targetNamespace;
    String respNamespace = targetNamespace;
    if (binding != null && Style.RPC.equals(binding.getBinding().getStyle())) {
        QName opQName = new QName(binding.getBinding().getPortTypeName().getNamespaceURI(), operationName);
        WSDLBoundOperation op = binding.getBinding().get(opQName);
        if (op != null) {
            // it cant be null, but lets not fail and try to work with service namespce
            if (op.getRequestNamespace() != null) {
                reqNamespace = op.getRequestNamespace();
            }
            // it cant be null, but lets not fail and try to work with service namespce
            if (op.getResponseNamespace() != null) {
                respNamespace = op.getResponseNamespace();
            }
        }
    }
    QName reqElementName = new QName(reqNamespace, operationName);
    javaMethod.setRequestPayloadName(reqElementName);
    QName resElementName = null;
    if (!isOneway) {
        resElementName = new QName(respNamespace, operationName + RESPONSE);
    }
    Class wrapperType = WrapperComposite.class;
    TypeInfo typeRef = new TypeInfo(reqElementName, wrapperType);
    WrapperParameter requestWrapper = new WrapperParameter(javaMethod, typeRef, Mode.IN, 0);
    requestWrapper.setInBinding(ParameterBinding.BODY);
    javaMethod.addParameter(requestWrapper);
    WrapperParameter responseWrapper = null;
    if (!isOneway) {
        typeRef = new TypeInfo(resElementName, wrapperType);
        responseWrapper = new WrapperParameter(javaMethod, typeRef, Mode.OUT, -1);
        responseWrapper.setOutBinding(ParameterBinding.BODY);
        javaMethod.addParameter(responseWrapper);
    }
    Class returnType = method.getReturnType();
    String resultName = RETURN;
    String resultTNS = targetNamespace;
    String resultPartName = resultName;
    boolean isResultHeader = false;
    WebResult webResult = getAnnotation(method, WebResult.class);
    if (webResult != null) {
        isResultHeader = webResult.header();
        if (webResult.name().length() > 0)
            resultName = webResult.name();
        if (webResult.partName().length() > 0) {
            resultPartName = webResult.partName();
            if (!isResultHeader)
                resultName = resultPartName;
        } else
            resultPartName = resultName;
        if (webResult.targetNamespace().length() > 0)
            resultTNS = webResult.targetNamespace();
        isResultHeader = webResult.header();
    }
    QName resultQName;
    if (isResultHeader)
        resultQName = new QName(resultTNS, resultName);
    else
        resultQName = new QName(resultName);
    if (javaMethod.isAsync()) {
        returnType = getAsyncReturnType(method, returnType);
    }
    if (!isOneway && returnType != null && returnType != void.class) {
        Annotation[] rann = getAnnotations(method);
        TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
        metadataReader.getProperties(rTypeReference.properties(), method);
        rTypeReference.setGenericType(method.getGenericReturnType());
        ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
        returnParameter.setPartName(resultPartName);
        if (isResultHeader) {
            returnParameter.setBinding(ParameterBinding.HEADER);
            javaMethod.addParameter(returnParameter);
            rTypeReference.setGlobalElement(true);
        } else {
            ParameterBinding rb = getBinding(operationName, resultPartName, false, Mode.OUT);
            returnParameter.setBinding(rb);
            if (rb.isBody()) {
                rTypeReference.setGlobalElement(false);
                WSDLPart p = getPart(new QName(targetNamespace, operationName), resultPartName, Mode.OUT);
                if (p == null)
                    resRpcParams.put(resRpcParams.size() + 10000, returnParameter);
                else
                    resRpcParams.put(p.getIndex(), returnParameter);
            } else {
                javaMethod.addParameter(returnParameter);
            }
        }
    }
    // get WebParam
    Class<?>[] parameterTypes = method.getParameterTypes();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] pannotations = getParamAnnotations(method);
    int pos = 0;
    for (Class clazzType : parameterTypes) {
        String paramName = "";
        String paramNamespace = "";
        String partName = "";
        boolean isHeader = false;
        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;
                paramName = webParam.name();
                partName = webParam.partName();
                isHeader = webParam.header();
                WebParam.Mode mode = webParam.mode();
                paramNamespace = webParam.targetNamespace();
                if (isHolder && mode == Mode.IN)
                    mode = Mode.INOUT;
                paramMode = mode;
                break;
            }
        }
        if (paramName.length() == 0) {
            paramName = "arg" + pos;
        }
        if (partName.length() == 0) {
            partName = paramName;
        } else if (!isHeader) {
            paramName = partName;
        }
        if (partName.length() == 0) {
            partName = paramName;
        }
        QName paramQName;
        if (!isHeader) {
            // its rpclit body param, set namespace to ""
            paramQName = new QName("", paramName);
        } else {
            if (paramNamespace.length() == 0)
                paramNamespace = targetNamespace;
            paramQName = new QName(paramNamespace, paramName);
        }
        typeRef = new TypeInfo(paramQName, clazzType, pannotations[pos]);
        metadataReader.getProperties(typeRef.properties(), method, pos);
        typeRef.setGenericType(genericParameterTypes[pos]);
        ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
        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) {
                typeRef.setGlobalElement(true);
                param.setBinding(ParameterBinding.HEADER);
            } else {
                ParameterBinding pb = getBinding(operationName, partName, false, paramMode);
                param.setBinding(pb);
            }
        }
        if (param.getInBinding().isBody()) {
            typeRef.setGlobalElement(false);
            if (!param.isOUT()) {
                WSDLPart p = getPart(new QName(targetNamespace, operationName), partName, Mode.IN);
                if (p == null)
                    reqRpcParams.put(reqRpcParams.size() + 10000, param);
                else
                    reqRpcParams.put(param.getIndex(), param);
            }
            if (!param.isIN()) {
                if (isOneway) {
                    throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.out.parameters", portClass.getCanonicalName(), methodName);
                }
                WSDLPart p = getPart(new QName(targetNamespace, operationName), partName, Mode.OUT);
                if (p == null)
                    resRpcParams.put(resRpcParams.size() + 10000, param);
                else
                    resRpcParams.put(p.getIndex(), param);
            }
        } else {
            javaMethod.addParameter(param);
        }
    }
    for (ParameterImpl p : reqRpcParams.values()) requestWrapper.addWrapperChild(p);
    for (ParameterImpl p : resRpcParams.values()) responseWrapper.addWrapperChild(p);
    processExceptions(javaMethod, method);
}
Also used : jakarta.jws(jakarta.jws) ParameterizedType(java.lang.reflect.ParameterizedType) WrapperComposite(com.sun.xml.ws.spi.db.WrapperComposite) Mode(jakarta.jws.WebParam.Mode) QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) TreeMap(java.util.TreeMap) 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) Type(java.lang.reflect.Type) ExceptionType(com.sun.xml.ws.api.model.ExceptionType) WSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation) WSDLPart(com.sun.xml.ws.api.model.wsdl.WSDLPart)

Example 3 with TypeInfo

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

the class RuntimeModeler method processDocWrappedMethod.

/**
 * models a document/literal wrapped method
 * @param javaMethod the runtime model <code>JavaMethod</code> instance being created
 * @param methodName the runtime model <code>JavaMethod</code> instance being created
 * @param operationName the runtime model <code>JavaMethod</code> instance being created
 * @param method the <code>method</code> to model
 */
protected void processDocWrappedMethod(JavaMethodImpl javaMethod, String methodName, String operationName, Method method) {
    boolean methodHasHeaderParams = false;
    boolean isOneway = getAnnotation(method, Oneway.class) != null;
    RequestWrapper reqWrapper = getAnnotation(method, RequestWrapper.class);
    ResponseWrapper resWrapper = getAnnotation(method, ResponseWrapper.class);
    String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
    if (packageName == null || packageName.length() == 0) {
        beanPackage = JAXWS_PACKAGE_PD;
    }
    String requestClassName;
    if (reqWrapper != null && reqWrapper.className().length() > 0) {
        requestClassName = reqWrapper.className();
    } else {
        requestClassName = beanPackage + capitalize(method.getName());
    }
    String responseClassName;
    if (resWrapper != null && resWrapper.className().length() > 0) {
        responseClassName = resWrapper.className();
    } else {
        responseClassName = beanPackage + capitalize(method.getName()) + RESPONSE;
    }
    String reqName = operationName;
    String reqNamespace = targetNamespace;
    String reqPartName = "parameters";
    if (reqWrapper != null) {
        if (reqWrapper.targetNamespace().length() > 0)
            reqNamespace = reqWrapper.targetNamespace();
        if (reqWrapper.localName().length() > 0)
            reqName = reqWrapper.localName();
        try {
            if (reqWrapper.partName().length() > 0)
                reqPartName = reqWrapper.partName();
        } catch (LinkageError e) {
        // 2.1 API dopes n't have this method
        // Do nothing, just default to "parameters"
        }
    }
    QName reqElementName = new QName(reqNamespace, reqName);
    javaMethod.setRequestPayloadName(reqElementName);
    Class requestClass = getRequestWrapperClass(requestClassName, method, reqElementName);
    Class responseClass = null;
    String resName = operationName + "Response";
    String resNamespace = targetNamespace;
    QName resElementName = null;
    String resPartName = "parameters";
    if (!isOneway) {
        if (resWrapper != null) {
            if (resWrapper.targetNamespace().length() > 0)
                resNamespace = resWrapper.targetNamespace();
            if (resWrapper.localName().length() > 0)
                resName = resWrapper.localName();
            try {
                if (resWrapper.partName().length() > 0)
                    resPartName = resWrapper.partName();
            } catch (LinkageError e) {
            // 2.1 API does n't have this method
            // Do nothing, just default to "parameters"
            }
        }
        resElementName = new QName(resNamespace, resName);
        responseClass = getResponseWrapperClass(responseClassName, method, resElementName);
    }
    TypeInfo typeRef = new TypeInfo(reqElementName, requestClass);
    typeRef.setNillable(false);
    WrapperParameter requestWrapper = new WrapperParameter(javaMethod, typeRef, Mode.IN, 0);
    requestWrapper.setPartName(reqPartName);
    requestWrapper.setBinding(ParameterBinding.BODY);
    javaMethod.addParameter(requestWrapper);
    WrapperParameter responseWrapper = null;
    if (!isOneway) {
        typeRef = new TypeInfo(resElementName, responseClass);
        typeRef.setNillable(false);
        responseWrapper = new WrapperParameter(javaMethod, typeRef, Mode.OUT, -1);
        javaMethod.addParameter(responseWrapper);
        responseWrapper.setBinding(ParameterBinding.BODY);
    }
    // return value
    WebResult webResult = getAnnotation(method, WebResult.class);
    XmlElement xmlElem = getAnnotation(method, XmlElement.class);
    QName resultQName = getReturnQName(method, webResult, xmlElem);
    Class returnType = method.getReturnType();
    boolean isResultHeader = false;
    if (webResult != null) {
        isResultHeader = webResult.header();
        methodHasHeaderParams = isResultHeader || methodHasHeaderParams;
        if (isResultHeader && xmlElem != null) {
            throw new RuntimeModelerException("@XmlElement cannot be specified on method " + method + " as the return value is bound to header");
        }
        if (resultQName.getNamespaceURI().length() == 0 && webResult.header()) {
            // headers must have a namespace
            resultQName = new QName(targetNamespace, resultQName.getLocalPart());
        }
    }
    if (javaMethod.isAsync()) {
        returnType = getAsyncReturnType(method, returnType);
        resultQName = new QName(RETURN);
    }
    resultQName = qualifyWrappeeIfNeeded(resultQName, resNamespace);
    if (!isOneway && (returnType != null) && (!returnType.getName().equals("void"))) {
        Annotation[] rann = getAnnotations(method);
        if (resultQName.getLocalPart() != null) {
            TypeInfo rTypeReference = new TypeInfo(resultQName, returnType, rann);
            metadataReader.getProperties(rTypeReference.properties(), method);
            rTypeReference.setGenericType(method.getGenericReturnType());
            ParameterImpl returnParameter = new ParameterImpl(javaMethod, rTypeReference, Mode.OUT, -1);
            if (isResultHeader) {
                returnParameter.setBinding(ParameterBinding.HEADER);
                javaMethod.addParameter(returnParameter);
            } else {
                returnParameter.setBinding(ParameterBinding.BODY);
                responseWrapper.addWrapperChild(returnParameter);
            }
        }
    }
    // get WebParam
    Class<?>[] parameterTypes = method.getParameterTypes();
    Type[] genericParameterTypes = method.getGenericParameterTypes();
    Annotation[][] pannotations = getParamAnnotations(method);
    int pos = 0;
    for (Class clazzType : parameterTypes) {
        String partName = null;
        String paramName = "arg" + pos;
        // String paramNamespace = "";
        boolean isHeader = false;
        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;
        WebParam webParam = null;
        xmlElem = null;
        for (Annotation annotation : pannotations[pos]) {
            if (annotation.annotationType() == WebParam.class)
                webParam = (WebParam) annotation;
            else if (annotation.annotationType() == XmlElement.class)
                xmlElem = (XmlElement) annotation;
        }
        QName paramQName = getParameterQName(method, webParam, xmlElem, paramName);
        if (webParam != null) {
            isHeader = webParam.header();
            methodHasHeaderParams = isHeader || methodHasHeaderParams;
            if (isHeader && xmlElem != null) {
                throw new RuntimeModelerException("@XmlElement cannot be specified on method " + method + " parameter that is bound to header");
            }
            if (webParam.partName().length() > 0)
                partName = webParam.partName();
            else
                partName = paramQName.getLocalPart();
            if (isHeader && paramQName.getNamespaceURI().equals("")) {
                // headers cannot be in empty namespace
                paramQName = new QName(targetNamespace, paramQName.getLocalPart());
            }
            paramMode = webParam.mode();
            if (isHolder && paramMode == Mode.IN)
                paramMode = Mode.INOUT;
        }
        paramQName = qualifyWrappeeIfNeeded(paramQName, reqNamespace);
        typeRef = new TypeInfo(paramQName, clazzType, pannotations[pos]);
        metadataReader.getProperties(typeRef.properties(), method, pos);
        typeRef.setGenericType(genericParameterTypes[pos]);
        ParameterImpl param = new ParameterImpl(javaMethod, typeRef, paramMode, pos++);
        if (isHeader) {
            param.setBinding(ParameterBinding.HEADER);
            javaMethod.addParameter(param);
            param.setPartName(partName);
        } else {
            param.setBinding(ParameterBinding.BODY);
            if (paramMode != Mode.OUT) {
                requestWrapper.addWrapperChild(param);
            }
            if (paramMode != Mode.IN) {
                if (isOneway) {
                    throw new RuntimeModelerException("runtime.modeler.oneway.operation.no.out.parameters", portClass.getCanonicalName(), methodName);
                }
                responseWrapper.addWrapperChild(param);
            }
        }
    }
    // client mapping.
    if (methodHasHeaderParams) {
        resPartName = "result";
    }
    if (responseWrapper != null)
        responseWrapper.setPartName(resPartName);
    processExceptions(javaMethod, method);
}
Also used : QName(javax.xml.namespace.QName) Mode(jakarta.jws.WebParam.Mode) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ExceptionType(com.sun.xml.ws.api.model.ExceptionType) XmlElement(jakarta.xml.bind.annotation.XmlElement)

Example 4 with TypeInfo

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

the class JAXBContextFactory method newContext.

@Override
protected BindingContext newContext(BindingInfo bi) {
    Map<String, Source> extMapping = (Map<String, Source>) bi.properties().get(OXM_XML_OVERRIDE);
    Map<String, Object> properties = new HashMap<>();
    Map<TypeInfo, TypeMappingInfo> map = createTypeMappings(bi.typeInfos());
    // chen workaround for document-literal wrapper - new feature on eclipselink API requested
    for (TypeInfo tinfo : map.keySet()) {
        WrapperParameter wp = (WrapperParameter) tinfo.properties().get(WrapperParameter.class.getName());
        if (wp != null) {
            Class<?> wrpCls = (Class) tinfo.type;
            Element javaAttributes = null;
            for (ParameterImpl p : wp.getWrapperChildren()) {
                Element xmlelem = findXmlElement(p.getTypeInfo().properties());
                if (xmlelem != null) {
                    if (javaAttributes == null) {
                        javaAttributes = javaAttributes(wrpCls, extMapping);
                    }
                    xmlelem = (Element) javaAttributes.getOwnerDocument().importNode(xmlelem, true);
                    String fieldName = getFieldName(p, wrpCls);
                    xmlelem.setAttribute("java-attribute", fieldName);
                    javaAttributes.appendChild(xmlelem);
                }
            }
            if (wrpCls.getPackage() != null)
                wrpCls.getPackage().getName();
        }
    }
    // Source src = extMapping.get("com.sun.xml.ws.test.toplink.jaxws");
    // if (src != null){
    // TransformerFactory tf = TransformerFactory.newInstance();
    // try {
    // Transformer t = tf.newTransformer();
    // java.io.ByteArrayOutputStream bo = new java.io.ByteArrayOutputStream();
    // StreamResult sax = new StreamResult(bo);
    // t.transform(src, sax);
    // System.out.println(new String(bo.toByteArray()));
    // } catch (TransformerConfigurationException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // } catch (TransformerException e) {
    // e.printStackTrace();
    // throw new WebServiceException(e.getMessage(), e);
    // }
    // }
    HashSet<Type> typeSet = new HashSet<>();
    HashSet<TypeMappingInfo> typeList = new HashSet<>();
    for (TypeMappingInfo tmi : map.values()) {
        typeList.add(tmi);
        typeSet.add(tmi.getType());
    }
    for (Class<?> clss : bi.contentClasses()) {
        if (!typeSet.contains(clss) && !WrapperComposite.class.equals(clss)) {
            typeSet.add(clss);
            TypeMappingInfo tmi = new TypeMappingInfo();
            tmi.setType(clss);
            typeList.add(tmi);
        }
    }
    TypeMappingInfo[] types = typeList.toArray(new TypeMappingInfo[0]);
    if (extMapping != null) {
        properties.put(OXM_XML_OVERRIDE, extMapping);
    }
    if (bi.getDefaultNamespace() != null) {
        properties.put(OXM_XML_ELEMENT, bi.getDefaultNamespace());
    }
    try {
        org.eclipse.persistence.jaxb.JAXBContext jaxbContext = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(types, properties, bi.getClassLoader());
        return new JAXBContextWrapper(jaxbContext, map, bi.getSEIModel());
    } catch (JAXBException e) {
        throw new DatabindingException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) XmlElement(jakarta.xml.bind.annotation.XmlElement) Element(org.w3c.dom.Element) XmlRootElement(jakarta.xml.bind.annotation.XmlRootElement) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) JAXBContext(jakarta.xml.bind.JAXBContext) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) HashSet(java.util.HashSet) JAXBException(jakarta.xml.bind.JAXBException) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) GenericArrayType(java.lang.reflect.GenericArrayType) XmlType(jakarta.xml.bind.annotation.XmlType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with TypeInfo

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

the class RuntimeModeler method processExceptions.

/**
 * models the exceptions thrown by <code>method</code> and adds them to the <code>javaMethod</code>
 * runtime model object
 * @param javaMethod the runtime model object to add the exception model objects to
 * @param method the <code>method</code> from which to find the exceptions to model
 */
protected void processExceptions(JavaMethodImpl javaMethod, Method method) {
    Action actionAnn = getAnnotation(method, Action.class);
    FaultAction[] faultActions = {};
    if (actionAnn != null)
        faultActions = actionAnn.fault();
    for (Class<?> exception : method.getExceptionTypes()) {
        // Exclude RuntimeException, RemoteException and Error etc
        if (!EXCEPTION_CLASS.isAssignableFrom(exception))
            continue;
        if (RUNTIME_EXCEPTION_CLASS.isAssignableFrom(exception) || isRemoteException(exception))
            continue;
        if (getAnnotation(exception, jakarta.xml.bind.annotation.XmlTransient.class) != null)
            continue;
        Class exceptionBean;
        Annotation[] anns;
        WebFault webFault = getAnnotation(exception, WebFault.class);
        Method faultInfoMethod = getWSDLExceptionFaultInfo(exception);
        ExceptionType exceptionType = ExceptionType.WSDLException;
        String namespace = targetNamespace;
        String name = exception.getSimpleName();
        String beanPackage = packageName + PD_JAXWS_PACKAGE_PD;
        if (packageName.length() == 0)
            beanPackage = JAXWS_PACKAGE_PD;
        String className = beanPackage + name + BEAN;
        String messageName = exception.getSimpleName();
        if (webFault != null) {
            if (webFault.faultBean().length() > 0)
                className = webFault.faultBean();
            if (webFault.name().length() > 0)
                name = webFault.name();
            if (webFault.targetNamespace().length() > 0)
                namespace = webFault.targetNamespace();
            if (webFault.messageName().length() > 0)
                messageName = webFault.messageName();
        }
        if (faultInfoMethod == null) {
            exceptionBean = getExceptionBeanClass(className, exception, name, namespace);
            exceptionType = ExceptionType.UserDefined;
            anns = getAnnotations(exceptionBean);
        } else {
            exceptionBean = faultInfoMethod.getReturnType();
            anns = getAnnotations(faultInfoMethod);
        }
        QName faultName = new QName(namespace, name);
        TypeInfo typeRef = new TypeInfo(faultName, exceptionBean, anns);
        CheckedExceptionImpl checkedException = new CheckedExceptionImpl(javaMethod, exception, typeRef, exceptionType);
        checkedException.setMessageName(messageName);
        checkedException.setFaultInfoGetter(faultInfoMethod);
        for (FaultAction fa : faultActions) {
            if (fa.className().equals(exception) && !fa.value().equals("")) {
                checkedException.setFaultAction(fa.value());
                break;
            }
        }
        javaMethod.addException(checkedException);
    }
}
Also used : ExceptionType(com.sun.xml.ws.api.model.ExceptionType) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) Annotation(java.lang.annotation.Annotation)

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