Search in sources :

Example 11 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class ClientGenerator method mapClassName.

private String mapClassName(String packageName, String name, ToolContext context) {
    ClassCollector collector = context.get(ClassCollector.class);
    int count = 0;
    String checkName = name;
    while (collector.containClientClass(packageName, checkName)) {
        checkName = name + (++count);
    }
    collector.addClientClassName(packageName, checkName, packageName + "." + checkName);
    return checkName;
}
Also used : ClassCollector(org.apache.cxf.tools.util.ClassCollector)

Example 12 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class FaultGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        Map<String, JavaExceptionClass> exceptionClasses = javaModel.getExceptionClasses();
        for (Entry<String, JavaExceptionClass> entry : exceptionClasses.entrySet()) {
            JavaExceptionClass expClz = entry.getValue();
            clearAttributes();
            if (penv.containsKey(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID)) {
                String faultSerialVersionUID = penv.get(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID).toString();
                setAttributes("faultSerialVersionUID", faultSerialVersionUID);
                if ("FQCN".equalsIgnoreCase(faultSerialVersionUID)) {
                    setAttributes("suid", generateHashSUID(expClz.getFullClassName()));
                } else if ("TIMESTAMP".equalsIgnoreCase(faultSerialVersionUID)) {
                    setAttributes("suid", generateTimestampSUID());
                } else if ("NONE".equalsIgnoreCase(faultSerialVersionUID)) {
                    // nothing
                    setAttributes("suid", "");
                } else {
                    // do a quick Parse to make sure it looks like a Long
                    try {
                        Long.parseLong(faultSerialVersionUID);
                    } catch (NumberFormatException nfe) {
                        throw new ToolException(nfe);
                    }
                    setAttributes("suid", faultSerialVersionUID);
                }
            } else {
                setAttributes("suid", "");
            }
            setAttributes("expClass", expClz);
            String exceptionSuperclass;
            if (penv.containsKey(ToolConstants.CFG_EXCEPTION_SUPER)) {
                exceptionSuperclass = penv.get(ToolConstants.CFG_EXCEPTION_SUPER).toString();
            } else {
                exceptionSuperclass = "java.lang.Exception";
            }
            String simpleName = exceptionSuperclass.indexOf('.') == -1 ? exceptionSuperclass : exceptionSuperclass.substring(exceptionSuperclass.lastIndexOf('.') + 1);
            String exceptionSuperclassString = simpleName;
            for (JavaField jf : expClz.getFields()) {
                String jfClassName = jf.getClassName();
                if (jfClassName.substring(jfClassName.lastIndexOf(".") + 1).equals(simpleName)) {
                    exceptionSuperclassString = exceptionSuperclass;
                }
                setAttributes("paraName", ProcessorUtil.mangleNameToVariableName(jf.getName()));
            }
            ClassCollector collector = penv.get(ClassCollector.class);
            for (String pkg : collector.getTypesPackages()) {
                if (collector.containTypesClass(pkg, simpleName)) {
                    exceptionSuperclassString = exceptionSuperclass;
                }
            }
            if (expClz.getName().equals(exceptionSuperclassString)) {
                exceptionSuperclassString = exceptionSuperclass;
            }
            setAttributes("exceptionSuperclass", exceptionSuperclassString);
            if (!exceptionSuperclass.startsWith("java.lang.") && !exceptionSuperclassString.equals(exceptionSuperclass)) {
                expClz.addImport(exceptionSuperclass);
            }
            setCommonAttributes();
            doWrite(FAULT_TEMPLATE, parseOutputName(expClz.getPackageName(), expClz.getName()));
        }
    }
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) ClassCollector(org.apache.cxf.tools.util.ClassCollector) JavaExceptionClass(org.apache.cxf.tools.common.model.JavaExceptionClass) ToolException(org.apache.cxf.tools.common.ToolException)

Example 13 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class ServerGenerator method mapClassName.

private String mapClassName(String packageName, String name, ToolContext context) {
    ClassCollector collector = context.get(ClassCollector.class);
    int count = 0;
    String checkName = name;
    while (collector.containServerClass(packageName, checkName)) {
        checkName = name + (++count);
    }
    collector.addServerClassName(packageName, checkName, packageName + "." + checkName);
    return checkName;
}
Also used : ClassCollector(org.apache.cxf.tools.util.ClassCollector)

Example 14 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class ProcessorUtil method getFullClzName.

// 
// the non-wrapper style will get the type info from the part directly
// 
public static String getFullClzName(MessagePartInfo part, ToolContext context, boolean primitiveType) {
    DataBindingProfile dataBinding = context.get(DataBindingProfile.class);
    String jtype = null;
    QName xmlTypeName = getElementName(part);
    if (!primitiveType && dataBinding != null) {
        jtype = dataBinding.getType(xmlTypeName, true);
    }
    if (!primitiveType && dataBinding == null) {
        Class<?> holderClass = JAXBUtils.holderClass(xmlTypeName.getLocalPart());
        jtype = holderClass == null ? null : holderClass.getName();
        if (jtype == null) {
            jtype = JAXBUtils.builtInTypeToJavaType(xmlTypeName.getLocalPart());
        }
    }
    if (primitiveType) {
        jtype = JAXBUtils.builtInTypeToJavaType(xmlTypeName.getLocalPart());
    }
    String namespace = xmlTypeName.getNamespaceURI();
    String type = resolvePartType(part, context, true);
    String userPackage = context.mapPackageName(namespace);
    ClassCollector collector = context.get(ClassCollector.class);
    if (jtype == null) {
        jtype = collector.getTypesFullClassName(parsePackageName(namespace, userPackage), type);
    }
    if (jtype == null) {
        if (!resolvePartType(part).equals(type)) {
            jtype = resolvePartType(part, context, true);
        } else {
            jtype = parsePackageName(namespace, userPackage) + "." + type;
        }
    }
    return jtype;
}
Also used : QName(javax.xml.namespace.QName) ClassCollector(org.apache.cxf.tools.util.ClassCollector) DataBindingProfile(org.apache.cxf.tools.wsdlto.core.DataBindingProfile)

Example 15 with ClassCollector

use of org.apache.cxf.tools.util.ClassCollector in project cxf by apache.

the class ServiceProcessor method processService.

private void processService(JavaModel model) throws ToolException {
    JavaServiceClass sclz = (JavaServiceClass) service.getProperty("JavaServiceClass");
    if (sclz != null) {
        return;
    }
    for (JavaServiceClass sc : model.getServiceClasses().values()) {
        if (sc.getServiceName().equals(service.getName().getLocalPart())) {
            sclz = sc;
        }
    }
    if (sclz == null) {
        sclz = new JavaServiceClass(model);
        service.setProperty("JavaServiceClass", sclz);
        String name = NameUtil.mangleNameToClassName(service.getName().getLocalPart());
        String namespace = service.getName().getNamespaceURI();
        String packageName = ProcessorUtil.parsePackageName(namespace, context.mapPackageName(namespace));
        // customizing
        JAXWSBinding serviceBinding = null;
        if (service.getDescription() != null) {
            serviceBinding = service.getDescription().getExtensor(JAXWSBinding.class);
        }
        JAXWSBinding serviceBinding2 = service.getExtensor(JAXWSBinding.class);
        // Handle service customized class
        if (serviceBinding != null) {
            if (serviceBinding.getPackage() != null) {
                jaxwsBinding.setPackage(serviceBinding.getPackage());
            }
            if (serviceBinding.isEnableAsyncMapping()) {
                jaxwsBinding.setEnableAsyncMapping(true);
            }
            if (serviceBinding.isEnableMime()) {
                jaxwsBinding.setEnableMime(true);
            }
            jaxwsBinding.setEnableWrapperStyle(serviceBinding.isEnableWrapperStyle());
            if (serviceBinding.getJaxwsClass() != null && serviceBinding.getJaxwsClass().getClassName() != null) {
                name = serviceBinding.getJaxwsClass().getClassName();
                if (name.contains(".")) {
                    jaxwsBinding.setPackage(name.substring(0, name.lastIndexOf('.')));
                    name = name.substring(name.lastIndexOf('.') + 1);
                }
                sclz.setClassJavaDoc(serviceBinding.getJaxwsClass().getComments());
            }
            sclz.setPackageJavaDoc(serviceBinding.getPackageJavaDoc());
        }
        if (serviceBinding2 != null) {
            if (serviceBinding2.getPackage() != null) {
                jaxwsBinding.setPackage(serviceBinding2.getPackage());
            }
            if (serviceBinding2.isEnableAsyncMapping()) {
                jaxwsBinding.setEnableAsyncMapping(true);
            }
            if (serviceBinding2.isEnableMime()) {
                jaxwsBinding.setEnableMime(true);
            }
            if (serviceBinding2.isEnableWrapperStyle()) {
                jaxwsBinding.setEnableWrapperStyle(true);
            }
            if (serviceBinding2.getJaxwsClass() != null && serviceBinding2.getJaxwsClass().getClassName() != null) {
                name = serviceBinding2.getJaxwsClass().getClassName();
                if (name.contains(".")) {
                    jaxwsBinding.setPackage(name.substring(0, name.lastIndexOf('.')));
                    name = name.substring(name.lastIndexOf('.') + 1);
                }
            }
            if (serviceBinding2.getJaxwsClass() != null && serviceBinding2.getJaxwsClass().getComments() != null) {
                jaxwsBinding.setClassJavaDoc(serviceBinding2.getJaxwsClass().getComments());
            }
            if (!serviceBinding2.getPackageJavaDoc().equals("")) {
                sclz.setPackageJavaDoc(serviceBinding2.getPackageJavaDoc());
            }
        }
        sclz.setServiceName(service.getName().getLocalPart());
        sclz.setNamespace(namespace);
        if (jaxwsBinding.getPackage() != null) {
            packageName = jaxwsBinding.getPackage();
        }
        sclz.setPackageName(packageName);
        name = mapName(packageName, name);
        sclz.setName(name);
        ClassCollector collector = context.get(ClassCollector.class);
        String checkName = name;
        int count = 0;
        while (collector.containServiceClass(packageName, checkName)) {
            checkName = name + (++count);
        }
        name = checkName;
        sclz.setName(name);
        collector.addServiceClassName(packageName, name, packageName + "." + name);
        Element handler = (Element) context.get(ToolConstants.HANDLER_CHAIN);
        sclz.setHandlerChains(handler);
    }
    Collection<EndpointInfo> ports = service.getEndpoints();
    for (EndpointInfo port : ports) {
        JavaPort javaport = processPort(model, service, port);
        sclz.addPort(javaport);
    }
    sclz.setClassJavaDoc(jaxwsBinding.getClassJavaDoc());
    if (StringUtils.isEmpty(sclz.getClassJavaDoc())) {
        sclz.setClassJavaDoc(service.getDocumentation());
    }
    model.addServiceClass(sclz.getName(), sclz);
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) ClassCollector(org.apache.cxf.tools.util.ClassCollector) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) JavaPort(org.apache.cxf.tools.common.model.JavaPort)

Aggregations

ClassCollector (org.apache.cxf.tools.util.ClassCollector)19 ToolException (org.apache.cxf.tools.common.ToolException)6 File (java.io.File)4 IOException (java.io.IOException)4 Message (org.apache.cxf.common.i18n.Message)4 ArrayList (java.util.ArrayList)3 QName (javax.xml.namespace.QName)3 URL (java.net.URL)2 HashSet (java.util.HashSet)2 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)2 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)2 ClassUtils (org.apache.cxf.tools.common.ClassUtils)2 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)2 JavaModel (org.apache.cxf.tools.common.model.JavaModel)2 JavaPort (org.apache.cxf.tools.common.model.JavaPort)2 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)2 JAXWSBinding (org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding)2 Test (org.junit.Test)2 InputSource (org.xml.sax.InputSource)2 JClass (com.sun.codemodel.JClass)1