01: package org.objectweb.celtix.tools.generators.java2;
02:
03: import java.io.File;
04: import java.io.FileNotFoundException;
05: import java.io.FileOutputStream;
06: import java.util.logging.Logger;
07:
08: import javax.xml.bind.SchemaOutputResolver;
09: import javax.xml.transform.Result;
10: import javax.xml.transform.stream.StreamResult;
11:
12: import org.objectweb.celtix.common.i18n.Message;
13: import org.objectweb.celtix.common.logging.LogUtils;
14: import org.objectweb.celtix.tools.common.ProcessorEnvironment;
15: import org.objectweb.celtix.tools.common.ToolConstants;
16: import org.objectweb.celtix.tools.common.ToolException;
17: import org.objectweb.celtix.tools.common.model.WSDLModel;
18: import org.objectweb.celtix.tools.processors.java2.JavaToWSDLProcessor;
19:
20: public class WSDLOutputResolver extends SchemaOutputResolver {
21: private static final Logger LOG = LogUtils
22: .getL7dLogger(JavaToWSDLProcessor.class);
23: private final ProcessorEnvironment env;
24: private final WSDLModel wmodel;
25:
26: public WSDLOutputResolver(ProcessorEnvironment penv, WSDLModel model) {
27: this .env = penv;
28: this .wmodel = model;
29: }
30:
31: private File getFile(String filename) {
32: Object obj = env.get(ToolConstants.CFG_OUTPUTFILE);
33: String wsdlFile = obj == null ? "./" : (String) obj;
34: File file = null;
35: if (wsdlFile != null) {
36: file = new File(wsdlFile);
37: if (file.isDirectory()) {
38: file = new File(file, filename);
39: } else {
40: file = new File(file.getParent(), filename);
41: }
42: } else {
43: file = new File(".", filename);
44: }
45: return file;
46: }
47:
48: public Result createOutput(String namespaceUri,
49: String suggestedFileName) {
50: wmodel.addSchemaNSFileToMap(namespaceUri, suggestedFileName);
51: File wsdlFile = getFile(suggestedFileName);
52: Result result = null;
53: try {
54: result = new StreamResult(new FileOutputStream(wsdlFile));
55: result.setSystemId(wsdlFile.toString().replace('\\', '/'));
56: } catch (FileNotFoundException e) {
57: Message msg = new Message("CANNOT_CREATE_SCHEMA_FILE", LOG);
58: throw new ToolException(msg, e);
59: }
60: return result;
61: }
62: }
|