Search in sources :

Example 6 with JavaException

use of org.apache.cxf.tools.common.model.JavaException in project cxf by apache.

the class FaultProcessor method processFault.

private void processFault(JavaMethod method, FaultInfo faultMessage) throws ToolException {
    JavaModel model = method.getInterface().getJavaModel();
    String name = NameUtil.mangleNameToClassName(faultMessage.getName().getLocalPart());
    String namespace = faultMessage.getName().getNamespaceURI();
    String packageName = ProcessorUtil.parsePackageName(namespace, context.mapPackageName(namespace));
    if (namespace.equals(method.getInterface().getNamespace())) {
        packageName = method.getInterface().getPackageName();
    }
    JAXWSBinding jaxwsBinding = faultMessage.getExtensor(JAXWSBinding.class);
    if (jaxwsBinding != null) {
        if (jaxwsBinding.getPackage() != null) {
            packageName = jaxwsBinding.getPackage();
        }
        if (jaxwsBinding.getJaxwsClass() != null && jaxwsBinding.getJaxwsClass().getClassName() != null) {
            name = jaxwsBinding.getJaxwsClass().getClassName();
            if (name.contains(".")) {
                packageName = name.substring(0, name.lastIndexOf('.'));
                name = name.substring(name.lastIndexOf('.') + 1);
            }
        }
    }
    while (isNameCollision(packageName, name)) {
        name = name + "_Exception";
    }
    String fullClassName = packageName + "." + name;
    collector.addExceptionClassName(packageName, name, fullClassName);
    boolean samePackage = method.getInterface().getPackageName().equals(packageName);
    method.addException(new JavaException(faultMessage.getName().getLocalPart(), samePackage ? name : fullClassName, namespace));
    List<MessagePartInfo> faultParts = faultMessage.getMessageParts();
    JavaExceptionClass expClass = new JavaExceptionClass(model);
    expClass.setName(name);
    expClass.setNamespace(namespace);
    expClass.setPackageName(packageName);
    for (MessagePartInfo part : faultParts) {
        final String fName;
        String fNamespace;
        if (part.getElementQName() != null) {
            fNamespace = part.getElementQName().getNamespaceURI();
            // fNamespace = part.getConcreteName().getNamespaceURI();
            fName = part.getConcreteName().getLocalPart();
        } else {
            fNamespace = part.getTypeQName().getNamespaceURI();
            fName = part.getConcreteName().getLocalPart();
        }
        if (StringUtils.isEmpty(fNamespace)) {
            fNamespace = namespace;
        }
        String fType = ProcessorUtil.getType(part, context, false);
        // REVISIT - custom JAXB package names
        String fPackageName = method.getInterface().getPackageName();
        JavaField fField = new JavaField(fName, fType, fNamespace);
        fField.setQName(ProcessorUtil.getElementName(part));
        if (!method.getInterface().getPackageName().equals(fPackageName)) {
            fField.setClassName(ProcessorUtil.getFullClzName(part, context, false));
        }
        if (!fType.equals(ProcessorUtil.resolvePartType(part))) {
            fField.setClassName(ProcessorUtil.getType(part, context, true));
        }
        expClass.addField(fField);
    }
    model.addExceptionClass(packageName + "." + name, expClass);
    expClass.setClassJavaDoc(faultMessage.getDocumentation());
}
Also used : JavaException(org.apache.cxf.tools.common.model.JavaException) JavaField(org.apache.cxf.tools.common.model.JavaField) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaExceptionClass(org.apache.cxf.tools.common.model.JavaExceptionClass) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

JavaException (org.apache.cxf.tools.common.model.JavaException)6 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)4 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)4 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)2 OperationInfo (org.apache.cxf.service.model.OperationInfo)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)2 JavaReturn (org.apache.cxf.tools.common.model.JavaReturn)2 URISyntaxException (java.net.URISyntaxException)1 FaultInfo (org.apache.cxf.service.model.FaultInfo)1 MessageInfo (org.apache.cxf.service.model.MessageInfo)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 ToolContext (org.apache.cxf.tools.common.ToolContext)1 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)1