01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.tools.java2wsdl;
19:
20: import java.util.HashSet;
21:
22: import org.apache.cxf.common.i18n.Message;
23: import org.apache.cxf.tools.common.AbstractCXFToolContainer;
24: import org.apache.cxf.tools.common.Processor;
25: import org.apache.cxf.tools.common.ToolConstants;
26: import org.apache.cxf.tools.common.ToolContext;
27: import org.apache.cxf.tools.common.ToolException;
28: import org.apache.cxf.tools.common.toolspec.ToolSpec;
29: import org.apache.cxf.tools.common.toolspec.parser.BadUsageException;
30: import org.apache.cxf.tools.common.toolspec.parser.ErrorVisitor;
31: import org.apache.cxf.tools.java2wsdl.processor.JavaToProcessor;
32: import org.apache.cxf.tools.util.AnnotationUtil;
33:
34: public class JavaToWSDLContainer extends AbstractCXFToolContainer {
35:
36: private static final String TOOL_NAME = "java2wsdl";
37:
38: public JavaToWSDLContainer(ToolSpec toolspec) throws Exception {
39: super (TOOL_NAME, toolspec);
40: }
41:
42: public void execute(boolean exitOnFinish) throws ToolException {
43: Processor processor = null;
44: try {
45: super .execute(exitOnFinish);
46: if (!hasInfoOption()) {
47: ToolContext env = new ToolContext();
48: env.setParameters(getParametersMap(new HashSet()));
49: if (isVerboseOn()) {
50: env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
51: }
52:
53: processor = new JavaToProcessor();
54:
55: processor.setEnvironment(env);
56: processor.process();
57: }
58: } catch (ToolException ex) {
59: if (ex.getCause() instanceof BadUsageException) {
60: printUsageException(TOOL_NAME, (BadUsageException) ex
61: .getCause());
62: if (isVerboseOn()) {
63: ex.printStackTrace();
64: }
65: }
66: throw ex;
67: } catch (Exception ex) {
68: System.err.println("Error : " + ex.getMessage());
69: System.err.println();
70: if (isVerboseOn()) {
71: ex.printStackTrace();
72: }
73:
74: throw new ToolException(ex.getMessage(), ex.getCause());
75: }
76: }
77:
78: public Class getServiceClass(ToolContext context) {
79: return AnnotationUtil.loadClass((String) context
80: .get(ToolConstants.CFG_CLASSNAME), getClass()
81: .getClassLoader());
82: }
83:
84: public void checkParams(ErrorVisitor errors) throws ToolException {
85: if (errors.getErrors().size() > 0) {
86: Message msg = new Message("PARAMETER_MISSSING", LOG);
87: throw new ToolException(msg, new BadUsageException(
88: getUsage(), errors));
89: }
90: }
91: }
|