001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * NewWSDLGenerator.java
044: *
045: * Created on September 1, 2006, 3:45 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.modules.xml.wsdl.ui.wizard;
052:
053: import java.util.HashMap;
054: import java.util.List;
055: import java.util.Map;
056:
057: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplate;
058: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplateGroup;
059: import org.netbeans.modules.xml.wsdl.model.Operation;
060: import org.netbeans.modules.xml.wsdl.model.PortType;
061: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
062: import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory;
063: import org.netbeans.modules.xml.wsdl.ui.view.OperationType;
064: import org.netbeans.modules.xml.wsdl.ui.view.PartAndElementOrTypeTableModel;
065: import org.netbeans.modules.xml.xam.ModelSource;
066: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
067: import org.openide.filesystems.FileObject;
068: import org.openide.loaders.TemplateWizard;
069:
070: /**
071: *
072: * @author radval
073: */
074: public class NewWSDLGenerator {
075:
076: private FileObject mWsdlFile;
077:
078: private TemplateWizard mTemplateWizard;
079:
080: private WSDLModel mModel;
081:
082: //private WsdlGenerationUtil mUtil;
083:
084: /** Creates a new instance of NewWSDLGenerator */
085: public NewWSDLGenerator(FileObject newWSDLFile,
086: TemplateWizard templateWizard) {
087: this .mWsdlFile = newWSDLFile;
088: this .mTemplateWizard = templateWizard;
089: ModelSource modelSource = org.netbeans.modules.xml.retriever.catalog.Utilities
090: .getModelSource(this .mWsdlFile, true);
091:
092: mModel = WSDLModelFactory.getDefault().getModel(modelSource);
093: //this.mUtil = new WsdlGenerationUtil(this.mModel);
094: }
095:
096: public void generate() {
097:
098: if (mModel != null) {
099: mModel.startTransaction();
100:
101: Map configurationMap = new HashMap();
102:
103: //portType
104: String portTypeName = (String) this .mTemplateWizard
105: .getProperty(WizardPortTypeConfigurationStep.PORTTYPE_NAME);
106: String operationName = (String) this .mTemplateWizard
107: .getProperty(WizardPortTypeConfigurationStep.OPERATION_NAME);
108: OperationType ot = (OperationType) this .mTemplateWizard
109: .getProperty(WizardPortTypeConfigurationStep.OPERATION_TYPE);
110:
111: configurationMap.put(
112: WizardPortTypeConfigurationStep.PORTTYPE_NAME,
113: portTypeName);
114: configurationMap.put(
115: WizardPortTypeConfigurationStep.OPERATION_NAME,
116: operationName);
117: configurationMap.put(
118: WizardPortTypeConfigurationStep.OPERATION_TYPE, ot);
119:
120: //opertion type
121: List<PartAndElementOrTypeTableModel.PartAndElementOrType> inputMessageParts = (List<PartAndElementOrTypeTableModel.PartAndElementOrType>) this .mTemplateWizard
122: .getProperty(WizardPortTypeConfigurationStep.OPERATION_INPUT);
123:
124: List<PartAndElementOrTypeTableModel.PartAndElementOrType> outputMessageParts = (List<PartAndElementOrTypeTableModel.PartAndElementOrType>) this .mTemplateWizard
125: .getProperty(WizardPortTypeConfigurationStep.OPERATION_OUTPUT);
126:
127: List<PartAndElementOrTypeTableModel.PartAndElementOrType> faultMessageParts = (List<PartAndElementOrTypeTableModel.PartAndElementOrType>) this .mTemplateWizard
128: .getProperty(WizardPortTypeConfigurationStep.OPERATION_FAULT);
129:
130: Map<String, String> namespaceToPrefixMap = (Map<String, String>) mTemplateWizard
131: .getProperty(WizardPortTypeConfigurationStep.NAMESPACE_TO_PREFIX_MAP);
132: configurationMap.put(
133: WizardPortTypeConfigurationStep.OPERATION_INPUT,
134: inputMessageParts);
135: configurationMap.put(
136: WizardPortTypeConfigurationStep.OPERATION_OUTPUT,
137: outputMessageParts);
138: configurationMap.put(
139: WizardPortTypeConfigurationStep.OPERATION_FAULT,
140: faultMessageParts);
141: configurationMap
142: .put(
143: WizardPortTypeConfigurationStep.NAMESPACE_TO_PREFIX_MAP,
144: namespaceToPrefixMap);
145: //binding
146: String bindingName = (String) this .mTemplateWizard
147: .getProperty(WizardBindingConfigurationStep.BINDING_NAME);
148: LocalizedTemplateGroup bindingType = (LocalizedTemplateGroup) this .mTemplateWizard
149: .getProperty(WizardBindingConfigurationStep.BINDING_TYPE);
150: configurationMap.put(
151: WizardBindingConfigurationStep.BINDING_NAME,
152: bindingName);
153: configurationMap.put(
154: WizardBindingConfigurationStep.BINDING_TYPE,
155: bindingType);
156:
157: //this could be null for a binding which does not have a sub type
158: LocalizedTemplate bindingSubType = (LocalizedTemplate) this .mTemplateWizard
159: .getProperty(WizardBindingConfigurationStep.BINDING_SUBTYPE);
160: configurationMap.put(
161: WizardBindingConfigurationStep.BINDING_SUBTYPE,
162: bindingSubType);
163:
164: //service and port
165: String serviceName = (String) this .mTemplateWizard
166: .getProperty(WizardBindingConfigurationStep.SERVICE_NAME);
167: String servicePortName = (String) this .mTemplateWizard
168: .getProperty(WizardBindingConfigurationStep.SERVICEPORT_NAME);
169: configurationMap.put(
170: WizardBindingConfigurationStep.SERVICE_NAME,
171: serviceName);
172: configurationMap.put(
173: WizardBindingConfigurationStep.SERVICEPORT_NAME,
174: servicePortName);
175:
176: mModel.getDefinitions().setName(
177: (String) configurationMap
178: .get(WsdlPanel.WSDL_DEFINITION_NAME));
179:
180: if (namespaceToPrefixMap != null) {
181: for (String namespace : namespaceToPrefixMap.keySet()) {
182: ((AbstractDocumentComponent) mModel
183: .getDefinitions()).addPrefix(
184: namespaceToPrefixMap.get(namespace),
185: namespace);
186: }
187: }
188:
189: PortTypeGenerator ptGenerator = new PortTypeGenerator(
190: this .mModel, configurationMap);
191: ptGenerator.execute();
192: PortType pt = ptGenerator.getPortType();
193:
194: if (pt != null) {
195: BindingGenerator bg = new BindingGenerator(this.mModel,
196: pt, configurationMap);
197: bg.execute();
198: }
199:
200: mModel.endTransaction();
201: }
202:
203: }
204:
205: }
|