001: /**
002: *
003: */package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra;
004:
005: import java.io.File;
006: import java.io.IOException;
007: import java.net.URL;
008: import java.util.ArrayList;
009: import java.util.List;
010:
011: import javax.wsdl.WSDLException;
012:
013: import org.apache.xmlbeans.XmlException;
014: import org.eclipse.core.resources.IResource;
015: import org.eclipse.jface.wizard.Wizard;
016:
017: import com.bostechcorp.cbesb.common.util.project.ProjectUtil;
018: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra.io.CustomWSDLReader;
019: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra.io.CustomWSDLWriter;
020: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra.io.WSDLFileGenerator;
021: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra.models.SchematicWSDLmodel;
022:
023: /**
024: * @author LPS
025: *
026: */
027: public class NewWSDLWizard extends Wizard {
028:
029: private SchematicWSDLmodel model = new SchematicWSDLmodel();
030: private String suNAme = "";
031: private String pathToProject = "";
032: final public static String fileName = ".customWsdl";
033: private List<String> freshImports = new ArrayList<String>();
034: //pages
035: private SchemaImportPage schemaImportPage;
036: private WSEditorPage wsEditorPage;
037: private String hostAddress;
038:
039: /**
040: * @param suNAme
041: * @param pathToProject
042: * @throws IOException
043: * @throws XmlException
044: */
045: public NewWSDLWizard(String suNAme, String pathToProject,
046: String host) throws IOException, XmlException {
047: super ();
048: this .suNAme = suNAme;
049: this .pathToProject = pathToProject;
050: this .hostAddress = host;
051:
052: loadModelFile(suNAme, pathToProject);
053: }
054:
055: private void loadModelFile(String suNAme2, String pathToProject2)
056: throws IOException, XmlException {
057: //check if dir exist
058: String dirName = pathToProject2 + File.separator + "src"
059: + File.separator + "wsdl" + File.separator + suNAme2;
060: File dir = new File(dirName);
061: File file = new File(dirName + File.separator + fileName);
062: if (dir.exists() || dir.mkdirs())
063: ; //make dir path
064: if (file.createNewFile()) {
065: //if file does not exist, create it
066: CustomWSDLWriter writer = new CustomWSDLWriter(file
067: .getAbsolutePath());
068: writer.writeModel(model);
069: } else {
070: //load file
071: CustomWSDLReader reader = new CustomWSDLReader(file
072: .getAbsolutePath());
073: model = reader.readModel();
074: }
075: }
076:
077: /* (non-Javadoc)
078: * @see org.eclipse.jface.wizard.Wizard#performFinish()
079: */
080: @Override
081: public boolean performFinish() {
082: CustomWSDLWriter writer = new CustomWSDLWriter(
083: pathToConfigFile());
084: try {
085: //write the model down
086: getModel().setWsName(getEditorPage().getText().getText());
087: writer.writeModel(getModel());
088: //generate the wsdl
089: WSDLFileGenerator wdlGenerator = new WSDLFileGenerator(
090: new File(pathToConfigFile()).getParent(), suNAme,
091: new URL(hostAddress), model);
092: wdlGenerator.buildDefinition();
093: wdlGenerator.writeToFile();
094: ProjectUtil.getCurProject().refreshLocal(
095: IResource.DEPTH_INFINITE, null);
096:
097: } catch (IOException e) {
098: e.printStackTrace();
099: return false;
100: } catch (XmlException e) {
101: e.printStackTrace();
102: } catch (WSDLException e) {
103: e.printStackTrace();
104: } catch (Exception e) {
105: e.printStackTrace();
106: }
107: return true;
108: }
109:
110: @Override
111: public void addPages() {
112: schemaImportPage = new SchemaImportPage("import");
113: addPage(schemaImportPage);
114: wsEditorPage = new WSEditorPage("editor");
115: addPage(wsEditorPage);
116: super .addPages();
117: }
118:
119: @Override
120: public boolean performCancel() {
121: //deleting imported files;
122: for (String fname : freshImports) {
123: if (!new File(pathToConfigFile().replace(fileName, fname))
124: .delete()) {
125: System.out.println("File "
126: + pathToConfigFile().replace(fileName, fname)
127: + "Was not deleted.");
128: }
129: }
130: return super .performCancel();
131: }
132:
133: private String pathToConfigFile() {
134: String file = "";
135: if (pathToProject.endsWith(File.separator))
136: file += pathToProject + "src" + File.separator + "wsdl"
137: + File.separator + suNAme + File.separator
138: + fileName;
139: else
140: file += pathToProject + File.separator + "src"
141: + File.separator + "wsdl" + File.separator + suNAme
142: + File.separator + fileName;
143: return file;
144: }
145:
146: /**
147: * @return the model
148: */
149: public SchematicWSDLmodel getModel() {
150: return model;
151: }
152:
153: /**
154: * @param model the model to set
155: */
156: public void setModel(SchematicWSDLmodel model) {
157: this .model = model;
158: }
159:
160: /**
161: * @return the pathToProject
162: */
163: public String getPathToProject() {
164: return pathToProject;
165: }
166:
167: /**
168: * @param pathToProject the pathToProject to set
169: */
170: public void setPathToProject(String pathToProject) {
171: this .pathToProject = pathToProject;
172: }
173:
174: /**
175: * @return the suNAme
176: */
177: public String getSuNAme() {
178: return suNAme;
179: }
180:
181: /**
182: * @param suNAme the suNAme to set
183: */
184: public void setSuNAme(String suNAme) {
185: this .suNAme = suNAme;
186: }
187:
188: /**
189: * @return the schemaImportPage
190: */
191: public SchemaImportPage getImportPage() {
192: return schemaImportPage;
193: }
194:
195: /**
196: * @return the wsEditorPage
197: */
198: public WSEditorPage getEditorPage() {
199: return wsEditorPage;
200: }
201:
202: /**
203: * @return the freshImports
204: */
205: public List<String> getFreshImports() {
206: return freshImports;
207: }
208:
209: /**
210: * @return the hostAddress
211: */
212: public String getHostAddress() {
213: return hostAddress;
214: }
215:
216: /**
217: * @param hostAddress the hostAddress to set
218: */
219: public void setHostAddress(String hostAddress) {
220: this.hostAddress = hostAddress;
221: }
222:
223: }
|