1 package org.objectweb.celtix.tools.generators.java2; 2 3 import java.io.File ; 4 import java.io.FileNotFoundException ; 5 import java.io.FileOutputStream ; 6 import java.util.logging.Logger ; 7 8 import javax.xml.bind.SchemaOutputResolver; 9 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.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 getFile(String filename) { 31 Object obj = env.get(ToolConstants.CFG_OUTPUTFILE); 32 String wsdlFile = obj == null ? "./" : (String )obj; 33 File file = null; 34 if (wsdlFile != null) { 35 file = new File (wsdlFile); 36 if (file.isDirectory()) { 37 file = new File (file, filename); 38 } else { 39 file = new File (file.getParent(), filename); 40 } 41 } else { 42 file = new File (".", filename); 43 } 44 return file; 45 } 46 47 public Result createOutput(String namespaceUri, String suggestedFileName) { 48 wmodel.addSchemaNSFileToMap(namespaceUri, suggestedFileName); 49 File wsdlFile = getFile(suggestedFileName); 50 Result result = null; 51 try { 52 result = new StreamResult (new FileOutputStream (wsdlFile)); 53 result.setSystemId(wsdlFile.toString().replace('\\', '/')); 54 } catch (FileNotFoundException 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 |