Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.apache.cxf.tools.java2wsdl.processor;
 
 import java.io.File;
 import java.util.List;
 
 
 public class JavaToProcessor implements Processor {
     private static final Logger LOG = LogUtils.getL7dLogger(JavaToProcessor.class);
     private static final String DEFAULT_ADDRESS = "http://localhost:9090/hello";
     private static final String JAVA_CLASS_PATH = "java.class.path";
     private ToolContext context;
     private final List<AbstractGeneratorgenerators = new ArrayList<AbstractGenerator>();
 
     private void customize(ServiceInfo service) {
         if (.containsKey(.)) {
             String ns = (String).get(.);
             service.setTargetNamespace(ns);
         }
 
         if (.containsKey(.)) {
             String portName = (String).get(.);
             EndpointInfo einfo = service.getEndpoints().iterator().next();
             QName qn = new QName(einfo.getName().getNamespaceURI(), portName);
             einfo.setName(qn);
         }
 
             String svName = getServiceName();
             service.setName(new QName(service.getName().getNamespaceURI(), svName));
         }
     }
 
     public void process() throws ToolException {
         String oldClassPath = System.getProperty();
         .log(."OLD_CP"oldClassPath);
         if (.get(.) != null) {
             String newCp = (String).get(.
                 + . + oldClassPath;
             System.setProperty(newCp);
             .log(."NEW_CP"newCp);
         }
 
         ServiceBuilder builder = getServiceBuilder();
         ServiceInfo service = builder.createService();
 
         customize(service);
 
         File wsdlFile = getOutputFile(builder.getOutputFile(),
                                       service.getName().getLocalPart() + ".wsdl");
 
         File outputDir = getOutputDir(wsdlFile);
 
         .add(getWSDLGenerator(wsdlFile));
         .add(getFaultBeanGenerator());
        generate(serviceoutputDir);
        System.setProperty(oldClassPath);
        .log(."RESUME_CP"oldClassPath);
    }
        WrapperBeanGenerator generator = new WrapperBeanGenerator();
        generator.setOutputBase(getSourceDir());
        generator.setCompileToDir(getClassesDir());
        return generator;
    }
        FaultBeanGenerator generator = new FaultBeanGenerator();
        generator.setOutputBase(getSourceDir());
        generator.setCompileToDir(getClassesDir());
        return generator;
    }
    private AbstractGenerator getWSDLGenerator(final File wsdlFile) {
        WSDLGeneratorFactory factory = new WSDLGeneratorFactory();
        factory.setWSDLVersion(getWSDLVersion());
        AbstractGenerator generator = factory.newGenerator();
        generator.setOutputBase(wsdlFile);
        return generator;
    }
    public void generate(ServiceInfo serviceFile outputthrows ToolException {
        for (AbstractGenerator generator : ) {
            generator.setServiceModel(service);
            generator.setBus(getBus());
            generator.generate(output);
        }
    }
    public ServiceBuilder getServiceBuilder() throws ToolException {
        ServiceBuilderFactory builderFactory = ServiceBuilderFactory.getInstance();
        builderFactory.setServiceClass(getServiceClass());
        // TODO check if user specify the style from cli arguments
        //      builderFactory.setStyle(style/from/command/line);
        ServiceBuilder builder = builderFactory.newBuilder();
        builder.validate();
        if (.get(.) != null) {
            String address = (String).get(.);
            builder.setAddress(address);
        } else {
            builder.setAddress();
        }
        builder.setTransportId(getTransportId());
        builder.setBus(getBus());
        builder.setBindingId(getBindingId());
        return builder;
    }
    protected String getTransportId() {
        if (isSOAP12()) {
            return .;
        }
        return .;
    }
    protected String getBindingId() {
        if (isSOAP12()) {
            return .;
        } else {
            return .;
        }
    }
    protected boolean isSOAP12() {
        if (!this..optionSet(.)) {
            BindingType bType = getServiceClass().getAnnotation(BindingType.class);
            if (bType != null) {
                return ..equals(bType.value());
            }
            return false;
        }
        return true;
    }
    protected File getOutputDir(File wsdlLocation) {
        if (dir == null) {
            if (wsdlLocation == null 
                || wsdlLocation.getParentFile() == null
                || !wsdlLocation.getParentFile().exists()) {
                dir = "./";
            } else {
                dir = wsdlLocation.getParent();
            }
        }
        return new File(dir);
    }
    protected File getOutputFile(File nameFromClzString defaultOutputFile) {
        String output = (String.get(.);
        if (dir == null) {
            dir = "./";
        }
        File result;
        if (output != null) {
            result = new File(output);
            if (!result.isAbsolute()) {
                result = new File(new File(dir), output);
            }
        } else {
            result = new File(new File(dir), defaultOutputFile);
        }
        if (nameFromClz != null) {
            result = nameFromClz;
        }
        // rename the existing wsdl file
        if (result.exists()
            && !result.renameTo(new File(result.getParent(), result.getName()))) {
            throw new ToolException(new Message("OUTFILE_EXISTS"));
        }
        return result;
    }
    public Class<?> getServiceClass() {
        return AnnotationUtil.loadClass((String).get(.),
                                        getClass().getClassLoader());
    }
        String version = (String.get(.);
        WSDLConstants.WSDLVersion wsVersion = WSDLConstants.getVersion(version);
        if (wsVersion == ..) {
            wsVersion = ..;
        }
        return wsVersion;
    }
    public String getServiceName() {
        return (Stringthis..get(.);
    }
    File getSourceDir() {
        String dir = (Stringthis..get(.);
        if (StringUtils.isEmpty(dir)) {
            return null;
        }
        return new File(dir);
    }
    File getClassesDir() {
        String dir = (Stringthis..get(.);
        if (StringUtils.isEmpty(dir)) {
            return null;
        }
        return new File(dir);
    }
    public Bus getBus() {
        return BusFactory.getDefaultBus();
    }
    public void setEnvironment(ToolContext env) {
        this. = env;
    }
    public ToolContext getEnvironment() {
        return this.;
    }
New to GrepCode? Check out our FAQ X