src/share/jaxws_classes/com/sun/tools/internal/ws/processor/generator/JwsImplGenerator.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/processor/generator/JwsImplGenerator.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,582 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.ws.processor.generator;
    1.30 +
    1.31 +import com.sun.codemodel.internal.*;
    1.32 +import com.sun.tools.internal.ws.processor.model.*;
    1.33 +import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
    1.34 +import com.sun.tools.internal.ws.processor.model.java.JavaMethod;
    1.35 +import com.sun.tools.internal.ws.processor.model.java.JavaParameter;
    1.36 +import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
    1.37 +import com.sun.tools.internal.ws.wsdl.document.Definitions;
    1.38 +import com.sun.tools.internal.ws.wsdl.document.Binding;
    1.39 +import com.sun.tools.internal.ws.wsdl.document.soap.SOAP12Binding;
    1.40 +import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding;
    1.41 +import com.sun.tools.internal.ws.wsdl.document.soap.SOAPConstants;
    1.42 +import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension;
    1.43 +import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
    1.44 +import com.sun.tools.internal.ws.processor.model.ModelProperties;
    1.45 +import com.sun.tools.internal.ws.wscompile.WsimportOptions;
    1.46 +import com.sun.codemodel.internal.JClassAlreadyExistsException;
    1.47 +import com.sun.xml.internal.ws.api.SOAPVersion;
    1.48 +
    1.49 +import com.sun.xml.internal.ws.util.ServiceFinder;
    1.50 +
    1.51 +import javax.jws.WebService;
    1.52 +import javax.xml.ws.BindingType;
    1.53 +import javax.xml.namespace.QName;
    1.54 +import javax.xml.ws.Holder;
    1.55 +import java.io.File;
    1.56 +import java.text.MessageFormat;
    1.57 +import java.util.ArrayList;
    1.58 +import java.util.HashMap;
    1.59 +import java.util.List;
    1.60 +import java.util.Iterator;
    1.61 +import java.util.Map;
    1.62 +
    1.63 +/**
    1.64 + * Generator for placeholder JWS implementations
    1.65 + *
    1.66 + * @since 2.2.6
    1.67 + */
    1.68 +public final class JwsImplGenerator extends GeneratorBase {
    1.69 +        private static final Map<String, String> TRANSLATION_MAP = new HashMap<String, String>(
    1.70 +      1);
    1.71 +        static
    1.72 +  {
    1.73 +    TRANSLATION_MAP.put(SOAPConstants.URI_SOAP_TRANSPORT_HTTP,
    1.74 +                javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING);
    1.75 +  }
    1.76 +        // save the generated impl files' info
    1.77 +        private final List<String> implFiles = new ArrayList<String>();
    1.78 +
    1.79 +        public static List<String> generate(Model model, WsimportOptions options,
    1.80 +            ErrorReceiver receiver) {
    1.81 +                // options check
    1.82 +
    1.83 +                // Generate it according the implDestDir option
    1.84 +                if (options.implDestDir == null)
    1.85 +                        return null;
    1.86 +
    1.87 +                JwsImplGenerator jwsImplGenerator = new JwsImplGenerator();
    1.88 +                jwsImplGenerator.init(model, options, receiver);
    1.89 +                jwsImplGenerator.doGeneration();
    1.90 +                // print a warning message while implFiles.size() is zero
    1.91 +                if (jwsImplGenerator.implFiles.isEmpty()) {
    1.92 +                        StringBuilder msg = new StringBuilder();
    1.93 +                        if (options.implServiceName != null)
    1.94 +                                msg.append("serviceName=[").append(options.implServiceName).append("] ");
    1.95 +                        if (options.implPortName != null)
    1.96 +                                msg.append("portName=[").append(options.implPortName).append("] ");
    1.97 +
    1.98 +                        if (msg.length() > 0)
    1.99 +                                msg.append(", Not found in wsdl file.\n");
   1.100 +
   1.101 +                        msg.append("No impl files generated!");
   1.102 +                        receiver.warning(null, msg.toString());
   1.103 +                }
   1.104 +
   1.105 +                return jwsImplGenerator.implFiles;
   1.106 +        }
   1.107 +
   1.108 +        /**
   1.109 +         * Move impl files to implDestDir
   1.110 +         */
   1.111 +        public static boolean moveToImplDestDir(List<String> gImplFiles,
   1.112 +            WsimportOptions options, ErrorReceiver receiver) {
   1.113 +                if (options.implDestDir == null || gImplFiles == null
   1.114 +                    || gImplFiles.isEmpty())
   1.115 +                        return true;
   1.116 +
   1.117 +                List<ImplFile> generatedImplFiles = ImplFile.toImplFiles(gImplFiles);
   1.118 +
   1.119 +                try {
   1.120 +                        File implDestDir = makePackageDir(options);
   1.121 +
   1.122 +                        File movedF;
   1.123 +                        File f;
   1.124 +                        for (ImplFile implF : generatedImplFiles) {
   1.125 +                                movedF = findFile(options, implF.qualifiedName);
   1.126 +                                if (movedF == null) {
   1.127 +                                        // should never happen
   1.128 +                                        receiver.warning(null, "Class " + implF.qualifiedName
   1.129 +                                            + " is not generated. Not moving.");
   1.130 +                                        return false;
   1.131 +                                }
   1.132 +
   1.133 +                                f = new File(implDestDir, implF.name);
   1.134 +                            if (!movedF.equals(f)) {    //bug 10102169
   1.135 +
   1.136 +                    if (f.exists())
   1.137 +                    {
   1.138 +                        if (!f.delete()){
   1.139 +                            receiver.error("Class " + implF.qualifiedName
   1.140 +                                    + " has existed in destImplDir, and it "
   1.141 +                                    + "can not be written!", null);
   1.142 +                        }
   1.143 +                    }
   1.144 +                    if(!movedF.renameTo(f))
   1.145 +                    {
   1.146 +                        throw new Exception();
   1.147 +                    }
   1.148 +                }
   1.149 +                        }
   1.150 +                } catch (Exception e) {
   1.151 +                        receiver.error("Moving WebService Impl files failed!", e);
   1.152 +                        return false;
   1.153 +                }
   1.154 +                return true;
   1.155 +        }
   1.156 +
   1.157 +        private JwsImplGenerator() {
   1.158 +                donotOverride = true;
   1.159 +        }
   1.160 +
   1.161 +        @Override
   1.162 +        public void visit(Service service) {
   1.163 +                QName serviceName = service.getName();
   1.164 +                // process the ordered service only if it is defined
   1.165 +                if (options.implServiceName != null
   1.166 +                    && !equalsNSOptional(options.implServiceName, serviceName))
   1.167 +                        return;
   1.168 +
   1.169 +                for (Port port : service.getPorts()) {
   1.170 +                        if (port.isProvider()) {
   1.171 +                                continue; // Not generating for Provider based endpoint
   1.172 +                        }
   1.173 +
   1.174 +                        // Generate the impl class name according to
   1.175 +                        // Xpath(/definitions/service/port[@name]);
   1.176 +                        QName portName = port.getName();
   1.177 +
   1.178 +                        // process the ordered port only if it is defined
   1.179 +                        if (options.implPortName != null
   1.180 +                            && !equalsNSOptional(options.implPortName, portName))
   1.181 +                                continue;
   1.182 +
   1.183 +                        String simpleClassName = serviceName.getLocalPart() + "_"
   1.184 +                            + portName.getLocalPart() + "Impl";
   1.185 +                        String className = makePackageQualified(simpleClassName);
   1.186 +                        implFiles.add(className);
   1.187 +
   1.188 +                        if (donotOverride && GeneratorUtil.classExists(options, className)) {
   1.189 +                                log("Class " + className + " exists. Not overriding.");
   1.190 +                                return;
   1.191 +                        }
   1.192 +
   1.193 +                        JDefinedClass cls = null;
   1.194 +                        try {
   1.195 +                                cls = getClass(className, ClassType.CLASS);
   1.196 +                        } catch (JClassAlreadyExistsException e) {
   1.197 +                                log("Class " + className
   1.198 +                                    + " generates failed. JClassAlreadyExistsException[" + className
   1.199 +                                    + "].");
   1.200 +                                return;
   1.201 +                        }
   1.202 +
   1.203 +                        // Each serviceImpl will implements one port interface
   1.204 +                        JavaInterface portIntf = port.getJavaInterface();
   1.205 +                        String portClassName = Names.customJavaTypeClassName(portIntf);
   1.206 +                        JDefinedClass portCls = null;
   1.207 +                        try {
   1.208 +                                portCls = getClass(portClassName, ClassType.INTERFACE);
   1.209 +                        } catch (JClassAlreadyExistsException e) {
   1.210 +                                log("Class " + className
   1.211 +                                    + " generates failed. JClassAlreadyExistsException["
   1.212 +                                    + portClassName + "].");
   1.213 +                                return;
   1.214 +                        }
   1.215 +                        cls._implements(portCls);
   1.216 +
   1.217 +                        // create a default constructor
   1.218 +                        cls.constructor(JMod.PUBLIC);
   1.219 +
   1.220 +                        // write class comment - JAXWS warning
   1.221 +                        JDocComment comment = cls.javadoc();
   1.222 +
   1.223 +                        if (service.getJavaDoc() != null) {
   1.224 +                                comment.add(service.getJavaDoc());
   1.225 +                                comment.add("\n\n");
   1.226 +                        }
   1.227 +
   1.228 +                        for (String doc : getJAXWSClassComment()) {
   1.229 +                                comment.add(doc);
   1.230 +                        }
   1.231 +
   1.232 +                        // @WebService
   1.233 +                        JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
   1.234 +                        writeWebServiceAnnotation(service, port, webServiceAnn);
   1.235 +
   1.236 +                        // @BindingType
   1.237 +                        JAnnotationUse bindingTypeAnn = cls.annotate(cm.ref(BindingType.class));
   1.238 +                        writeBindingTypeAnnotation(port, bindingTypeAnn);
   1.239 +
   1.240 +                        // extra annotation
   1.241 +                        for( GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
   1.242 +                            f.writeWebServiceAnnotation(model, cm, cls, port);
   1.243 +                        }
   1.244 +
   1.245 +                        // WebMethods
   1.246 +                        for (Operation operation : port.getOperations()) {
   1.247 +                                JavaMethod method = operation.getJavaMethod();
   1.248 +
   1.249 +                                // @WebMethod
   1.250 +                                JMethod m;
   1.251 +                                JDocComment methodDoc;
   1.252 +                                String methodJavaDoc = operation.getJavaDoc();
   1.253 +                                if (method.getReturnType().getName().equals("void")) {
   1.254 +                                        m = cls.method(JMod.PUBLIC, void.class, method.getName());
   1.255 +                                        methodDoc = m.javadoc();
   1.256 +                                } else {
   1.257 +                                        JAXBTypeAndAnnotation retType = method.getReturnType().getType();
   1.258 +                                        m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
   1.259 +                                        retType.annotate(m);
   1.260 +                                        methodDoc = m.javadoc();
   1.261 +                                        JCommentPart ret = methodDoc.addReturn();
   1.262 +                                        ret.add("returns " + retType.getName());
   1.263 +                                }
   1.264 +
   1.265 +                                if (methodJavaDoc != null)
   1.266 +                                        methodDoc.add(methodJavaDoc);
   1.267 +
   1.268 +                                JClass holder = cm.ref(Holder.class);
   1.269 +                                for (JavaParameter parameter : method.getParametersList()) {
   1.270 +                                        JVar var;
   1.271 +                                        JAXBTypeAndAnnotation paramType = parameter.getType().getType();
   1.272 +                                        if (parameter.isHolder()) {
   1.273 +                                                var = m.param(holder.narrow(paramType.getType().boxify()),
   1.274 +                                                    parameter.getName());
   1.275 +                                        } else {
   1.276 +                                                var = m.param(paramType.getType(), parameter.getName());
   1.277 +                                        }
   1.278 +                                        methodDoc.addParam(var);
   1.279 +                                }
   1.280 +
   1.281 +                                com.sun.tools.internal.ws.wsdl.document.Operation wsdlOp = operation
   1.282 +                                    .getWSDLPortTypeOperation();
   1.283 +                                for (Fault fault : operation.getFaultsSet()) {
   1.284 +                                        m._throws(fault.getExceptionClass());
   1.285 +                                        methodDoc.addThrows(fault.getExceptionClass());
   1.286 +                                        wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
   1.287 +                                }
   1.288 +                                m.body().block().directStatement("//replace with your impl here");
   1.289 +                                m.body().block().directStatement(
   1.290 +                                    getReturnString(method.getReturnType().getName()));
   1.291 +                        }
   1.292 +                }
   1.293 +        }
   1.294 +
   1.295 +        /**
   1.296 +         * Generate return statement according to return type.
   1.297 +         *
   1.298 +         * @param type
   1.299 +         *          The method's return type
   1.300 +         * @return The whole return statement
   1.301 +         */
   1.302 +        private String getReturnString(String type) {
   1.303 +                final String nullReturnStr = "return null;";
   1.304 +                // complex type or array
   1.305 +                if (type.indexOf('.') > -1 || type.indexOf('[') > -1) {
   1.306 +                        return nullReturnStr;
   1.307 +                }
   1.308 +
   1.309 +                // primitive type
   1.310 +                if (type.equals("void")) {
   1.311 +                        return "return;";
   1.312 +                }
   1.313 +                if (type.equals("boolean")) {
   1.314 +                        return "return false;";
   1.315 +                }
   1.316 +                if (type.equals("int") || type.equals("byte") || type.equals("short")
   1.317 +                    || type.equals("long") || type.equals("double") || type.equals("float")) {
   1.318 +                        return "return 0;";
   1.319 +                }
   1.320 +                if (type.equals("char")) {
   1.321 +                        return "return '0';";
   1.322 +                }
   1.323 +
   1.324 +                return nullReturnStr;
   1.325 +        }
   1.326 +
   1.327 +        /**
   1.328 +         *
   1.329 +         * @param service
   1.330 +         * @param port
   1.331 +         * @param webServiceAnn
   1.332 +         * @param options
   1.333 +         */
   1.334 +        private void writeWebServiceAnnotation(Service service, Port port,
   1.335 +            JAnnotationUse webServiceAnn) {
   1.336 +                webServiceAnn.param("portName", port.getName().getLocalPart());
   1.337 +                webServiceAnn.param("serviceName", service.getName().getLocalPart());
   1.338 +                webServiceAnn.param("targetNamespace", service.getName().getNamespaceURI());
   1.339 +                webServiceAnn.param("wsdlLocation", wsdlLocation);
   1.340 +                webServiceAnn.param("endpointInterface", port.getJavaInterface().getName());
   1.341 +        }
   1.342 +
   1.343 +        //CR373098 To transform the java class name as validate.
   1.344 +        private String transToValidJavaIdentifier(String s) {
   1.345 +            if (s == null) {
   1.346 +                return null;
   1.347 +            }
   1.348 +            final int len = s.length();
   1.349 +            StringBuilder retSB = new StringBuilder();
   1.350 +            if (len == 0 || !Character.isJavaIdentifierStart(s.charAt(0))) {
   1.351 +                retSB.append("J"); //update to a default start char
   1.352 +            } else {
   1.353 +                retSB.append(s.charAt(0));
   1.354 +            }
   1.355 +
   1.356 +            for (int i = 1; i < len; i++) {
   1.357 +                if (!Character.isJavaIdentifierPart(s.charAt(i)))
   1.358 +                  ; //delete it if it is illegal //TODO: It might conflict "a-b" vs. "ab"
   1.359 +                else {
   1.360 +                    retSB.append(s.charAt(i));
   1.361 +                }
   1.362 +            }
   1.363 +            return retSB.toString();
   1.364 +        }
   1.365 +
   1.366 +        private String makePackageQualified(String s) {
   1.367 +                s = transToValidJavaIdentifier(s);
   1.368 +                if (options.defaultPackage != null && !options.defaultPackage.equals("")) {
   1.369 +                        return options.defaultPackage + "." + s;
   1.370 +                } else {
   1.371 +                        return s;
   1.372 +                }
   1.373 +        }
   1.374 +
   1.375 +
   1.376 +        /**
   1.377 +         * TODO
   1.378 +         *
   1.379 +         * @param port
   1.380 +         * @param bindingTypeAnn
   1.381 +         */
   1.382 +        private void writeBindingTypeAnnotation(Port port,
   1.383 +            JAnnotationUse bindingTypeAnn) {
   1.384 +                QName bName = (QName) port
   1.385 +                    .getProperty(ModelProperties.PROPERTY_WSDL_BINDING_NAME);
   1.386 +                if (bName == null)
   1.387 +                        return;
   1.388 +
   1.389 +                String v = getBindingType(bName);
   1.390 +
   1.391 +                // TODO: How to decide if it is a mtom?
   1.392 +                if (v != null) {
   1.393 +                        // transport = translate(transport);
   1.394 +                        bindingTypeAnn.param("value", v);
   1.395 +                }
   1.396 +
   1.397 +        }
   1.398 +
   1.399 +        private String resolveBindingValue(TWSDLExtension wsdlext) {
   1.400 +                if (wsdlext.getClass().equals(SOAPBinding.class)) {
   1.401 +                        SOAPBinding sb = (SOAPBinding) wsdlext;
   1.402 +                        if(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(sb.getTransport()))
   1.403 +                                return javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING;
   1.404 +                        else {
   1.405 +                            for(GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
   1.406 +                                String bindingValue = f.getBindingValue(sb.getTransport(), SOAPVersion.SOAP_11);
   1.407 +                                if(bindingValue!=null) {
   1.408 +                                    return bindingValue;
   1.409 +                                }
   1.410 +                            }
   1.411 +                                return javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
   1.412 +                        }
   1.413 +                }
   1.414 +                if (wsdlext.getClass().equals(SOAP12Binding.class)) {
   1.415 +                        SOAP12Binding sb = (SOAP12Binding) wsdlext;
   1.416 +                        if(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(sb.getTransport()))
   1.417 +                                return javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING;
   1.418 +                    else {
   1.419 +                        for(GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
   1.420 +                            String bindingValue = f.getBindingValue(sb.getTransport(), SOAPVersion.SOAP_12);
   1.421 +                            if(bindingValue!=null) {
   1.422 +                                return bindingValue;
   1.423 +                            }
   1.424 +                        }
   1.425 +                            return javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING;
   1.426 +                    }
   1.427 +                }
   1.428 +                return null;
   1.429 +        }
   1.430 +
   1.431 +        private String getBindingType(QName bName) {
   1.432 +
   1.433 +                String value = null;
   1.434 +                // process the bindings in definitions of model.entity
   1.435 +                if (model.getEntity() instanceof Definitions) {
   1.436 +                        Definitions definitions = (Definitions) model.getEntity();
   1.437 +                        if (definitions != null) {
   1.438 +                                Iterator bindings = definitions.bindings();
   1.439 +                                if (bindings != null) {
   1.440 +                                        while (bindings.hasNext()) {
   1.441 +                                                Binding binding = (Binding) bindings.next();
   1.442 +                                                if (bName.getLocalPart().equals(binding.getName())
   1.443 +                                                    && bName.getNamespaceURI().equals(binding.getNamespaceURI())) {
   1.444 +                                                        List<TWSDLExtension> bindextends = (List<TWSDLExtension>) binding
   1.445 +                                                            .extensions();
   1.446 +                                                        for (TWSDLExtension wsdlext : bindextends) {
   1.447 +                                                                value = resolveBindingValue(wsdlext);
   1.448 +                                                                if (value != null)
   1.449 +                                                                        break;
   1.450 +                                                        }
   1.451 +                                                        break;
   1.452 +                                                }
   1.453 +                                        }
   1.454 +                                }
   1.455 +                        }
   1.456 +                }
   1.457 +
   1.458 +                // process the bindings in whole document
   1.459 +                if (value == null) {
   1.460 +                        if (model.getEntity() instanceof Definitions) {
   1.461 +                            Definitions definitions = (Definitions) model.getEntity();
   1.462 +                            Binding b = (Binding) definitions.resolveBindings().get(bName);
   1.463 +                            if (b != null) {
   1.464 +                                List<TWSDLExtension> bindextends = (List<TWSDLExtension>) b
   1.465 +                                    .extensions();
   1.466 +                                for (TWSDLExtension wsdlext : bindextends) {
   1.467 +                                    value = resolveBindingValue(wsdlext);
   1.468 +                                    if (value != null)
   1.469 +                                    break;
   1.470 +                                }
   1.471 +                            }
   1.472 +                        }
   1.473 +                }
   1.474 +
   1.475 +                return value;
   1.476 +        }
   1.477 +
   1.478 +  /**
   1.479 +   * Since the SOAP 1.1 binding transport URI defined in WSDL 1.1 specification
   1.480 +   * is different with the SOAPBinding URI defined by JAX-WS 2.0 specification.
   1.481 +   * We must translate the wsdl version into JAX-WS version. If the given
   1.482 +   * transport URI is NOT one of the predefined transport URIs, it is returned
   1.483 +   * as is.
   1.484 +   *
   1.485 +   * @param transportURI
   1.486 +   *          retrieved from WSDL
   1.487 +   * @return Standard BindingType URI defined by JAX-WS 2.0 specification.
   1.488 +   */
   1.489 +//  private String translate(String transportURI)
   1.490 +//  {
   1.491 +//    String translatedBindingId = TRANSLATION_MAP.get(transportURI);
   1.492 +//    if (translatedBindingId == null)
   1.493 +//      translatedBindingId = transportURI;
   1.494 +//
   1.495 +//    return translatedBindingId;
   1.496 +//  }
   1.497 +
   1.498 +        /*****************************************************************************
   1.499 +         * Inner classes definition
   1.500 +         */
   1.501 +        static final class ImplFile {
   1.502 +                public String qualifiedName; // package+"."+simpleClassName + ".java"
   1.503 +
   1.504 +                public String name; // simpleClassName + ".java"
   1.505 +
   1.506 +                private ImplFile(String qualifiedClassName) {
   1.507 +                        this.qualifiedName = qualifiedClassName + ".java";
   1.508 +
   1.509 +                        String simpleClassName = qualifiedClassName;
   1.510 +                        int i = qualifiedClassName.lastIndexOf(".");
   1.511 +                        if (i != -1)
   1.512 +                                simpleClassName = qualifiedClassName.substring(i + 1);
   1.513 +
   1.514 +                        this.name = simpleClassName + ".java";
   1.515 +                }
   1.516 +
   1.517 +                public static List<ImplFile> toImplFiles(List<String> qualifiedClassNames) {
   1.518 +                        List<ImplFile> ret = new ArrayList<ImplFile>();
   1.519 +
   1.520 +                        for (String qualifiedClassName : qualifiedClassNames)
   1.521 +                                ret.add(new ImplFile(qualifiedClassName));
   1.522 +
   1.523 +                        return ret;
   1.524 +                }
   1.525 +        }
   1.526 +
   1.527 +        /*****************************************************************************
   1.528 +         * Other utility methods
   1.529 +         */
   1.530 +
   1.531 +        private static File makePackageDir(WsimportOptions options) {
   1.532 +                File ret = null;
   1.533 +                if (options.defaultPackage != null && !options.defaultPackage.equals("")) {
   1.534 +                        String subDir = options.defaultPackage.replace('.', '/');
   1.535 +                        ret = new File(options.implDestDir, subDir);
   1.536 +                } else {
   1.537 +                        ret = options.implDestDir;
   1.538 +                }
   1.539 +
   1.540 +                boolean created = ret.mkdirs();
   1.541 +                if (options.verbose && !created) {
   1.542 +                    System.out.println(MessageFormat.format("Directory not created: {0}", ret));
   1.543 +                }
   1.544 +                return ret;
   1.545 +        }
   1.546 +
   1.547 +        private static String getQualifiedFileName(String canonicalBaseDir, File f)
   1.548 +            throws java.io.IOException {
   1.549 +                String fp = f.getCanonicalPath();
   1.550 +                if (fp == null)
   1.551 +                        return null;
   1.552 +                fp = fp.replace(canonicalBaseDir, "");
   1.553 +                fp = fp.replace('\\', '.');
   1.554 +                fp = fp.replace('/', '.');
   1.555 +                if (fp.startsWith("."))
   1.556 +                        fp = fp.substring(1);
   1.557 +
   1.558 +                return fp;
   1.559 +        }
   1.560 +
   1.561 +        private static File findFile(WsimportOptions options, String qualifiedFileName)
   1.562 +            throws java.io.IOException {
   1.563 +                String baseDir = options.sourceDir.getCanonicalPath();
   1.564 +                String fp = null;
   1.565 +                for (File f : options.getGeneratedFiles()) {
   1.566 +                        fp = getQualifiedFileName(baseDir, f);
   1.567 +                        if (qualifiedFileName.equals(fp))
   1.568 +                                return f;
   1.569 +                }
   1.570 +
   1.571 +                return null;
   1.572 +        }
   1.573 +
   1.574 +        private static boolean equalsNSOptional(String strQName, QName checkQN) {
   1.575 +                if (strQName == null)
   1.576 +                        return false;
   1.577 +                strQName = strQName.trim();
   1.578 +                QName reqQN = QName.valueOf(strQName);
   1.579 +
   1.580 +                if (reqQN.getNamespaceURI() == null || reqQN.getNamespaceURI().equals(""))
   1.581 +                        return reqQN.getLocalPart().equals(checkQN.getLocalPart());
   1.582 +
   1.583 +                return reqQN.equals(checkQN);
   1.584 +        }
   1.585 +}

mercurial