Search in sources :

Example 11 with JavaModel

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

the class JaxwsServerGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    JavaModel javaModel = env.get(JavaModel.class);
    if (passthrough()) {
        return;
    }
    Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
    for (JavaInterface intf : interfaces.values()) {
        clearAttributes();
        setAttributes("intf", intf);
        setAttributes("address", penv.get(ToolConstants.CFG_ADDRESS));
        setAttributes("implClass", env.get(ToolConstants.IMPL_CLASS));
        setCommonAttributes();
        doWrite(SERVER_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Server"));
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Example 12 with JavaModel

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

the class SimpleFrontEndProcessor method process.

@SuppressWarnings("unchecked")
public void process() throws ToolException {
    List<ServiceInfo> services = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
    ServiceInfo serviceInfo = services.get(0);
    JavaInterface jinf = JavaFirstUtil.serviceInfo2JavaInf(serviceInfo);
    JavaModel jm = new JavaModel();
    jm.addInterface("inf", jinf);
    jinf.setJavaModel(jm);
    context.put(JavaModel.class, jm);
    generators.add(new SimpleSEIGenerator());
    generators.add(new SimpleImplGenerator());
    generators.add(new SimpleServerGenerator());
    generators.add(new SimpleClientGenerator());
    generators.add(new AntGenerator());
    for (AbstractGenerator generator : generators) {
        generator.generate(context);
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SimpleSEIGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.simple.generator.SimpleSEIGenerator) SimpleImplGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.simple.generator.SimpleImplGenerator) SimpleClientGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.simple.generator.SimpleClientGenerator) JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) SimpleServerGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.simple.generator.SimpleServerGenerator) JavaModel(org.apache.cxf.tools.common.model.JavaModel) AbstractGenerator(org.apache.cxf.tools.wsdlto.core.AbstractGenerator) ArrayList(java.util.ArrayList) List(java.util.List) AntGenerator(org.apache.cxf.tools.java2wsdl.processor.internal.AntGenerator)

Example 13 with JavaModel

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

the class SimpleImplGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    JavaModel javaModel = env.get(JavaModel.class);
    if (passthrough()) {
        return;
    }
    Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
    for (JavaInterface intf : interfaces.values()) {
        clearAttributes();
        setAttributes("intf", intf);
        setAttributes("seiClass", env.get(ToolConstants.SEI_CLASS));
        setCommonAttributes();
        doWrite(IMPL_TEMPLATE, parseOutputName(intf.getPackageName(), intf.getName() + "Impl"));
        env.put(ToolConstants.IMPL_CLASS, intf.getFullClassName() + "Impl");
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaModel(org.apache.cxf.tools.common.model.JavaModel)

Example 14 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel 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 15 with JavaModel

use of org.apache.cxf.tools.common.model.JavaModel 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) {
        String fName = null;
        String fNamespace = null;
        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

JavaModel (org.apache.cxf.tools.common.model.JavaModel)24 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)20 QName (javax.xml.namespace.QName)11 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 JavaPort (org.apache.cxf.tools.common.model.JavaPort)6 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)6 Message (org.apache.cxf.common.i18n.Message)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 JavaException (org.apache.cxf.tools.common.model.JavaException)3 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 ToolContext (org.apache.cxf.tools.common.ToolContext)2 JAnnotation (org.apache.cxf.tools.common.model.JAnnotation)2 JavaExceptionClass (org.apache.cxf.tools.common.model.JavaExceptionClass)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 JavaMethod (org.apache.cxf.tools.common.model.JavaMethod)2 AntGenerator (org.apache.cxf.tools.java2wsdl.processor.internal.AntGenerator)2 ClassCollector (org.apache.cxf.tools.util.ClassCollector)2 AbstractGenerator (org.apache.cxf.tools.wsdlto.core.AbstractGenerator)2