KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > generators > java2 > WSDLOutputResolver


1 package org.objectweb.celtix.tools.generators.java2;
2
3 import java.io.File JavaDoc;
4 import java.io.FileNotFoundException JavaDoc;
5 import java.io.FileOutputStream JavaDoc;
6 import java.util.logging.Logger JavaDoc;
7
8 import javax.xml.bind.SchemaOutputResolver;
9 import javax.xml.transform.Result JavaDoc;
10 import javax.xml.transform.stream.StreamResult JavaDoc;
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 JavaDoc LOG = LogUtils.getL7dLogger(JavaToWSDLProcessor.class);
22     private final ProcessorEnvironment env;
23     private final WSDLModel wmodel;
24
25     public WSDLOutputResolver(ProcessorEnvironment penv, WSDLModel model) {
26         this.env = penv;
27         this.wmodel = model;
28     }
29
30     private File JavaDoc getFile(String JavaDoc filename) {
31         Object JavaDoc obj = env.get(ToolConstants.CFG_OUTPUTFILE);
32         String JavaDoc wsdlFile = obj == null ? "./" : (String JavaDoc)obj;
33         File JavaDoc file = null;
34         if (wsdlFile != null) {
35             file = new File JavaDoc(wsdlFile);
36             if (file.isDirectory()) {
37                 file = new File JavaDoc(file, filename);
38             } else {
39                 file = new File JavaDoc(file.getParent(), filename);
40             }
41         } else {
42             file = new File JavaDoc(".", filename);
43         }
44         return file;
45     }
46
47     public Result JavaDoc createOutput(String JavaDoc namespaceUri, String JavaDoc suggestedFileName) {
48         wmodel.addSchemaNSFileToMap(namespaceUri, suggestedFileName);
49         File JavaDoc wsdlFile = getFile(suggestedFileName);
50         Result JavaDoc result = null;
51         try {
52             result = new StreamResult JavaDoc(new FileOutputStream JavaDoc(wsdlFile));
53             result.setSystemId(wsdlFile.toString().replace('\\', '/'));
54         } catch (FileNotFoundException JavaDoc e) {
55             Message msg = new Message("CANNOT_CREATE_SCHEMA_FILE", LOG);
56             throw new ToolException(msg, e);
57         }
58         return result;
59     }
60 }
61
Popular Tags