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: * PortTypeGenerator.java
044: *
045: * Created on September 6, 2006, 4:36 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.ArrayList;
054: import java.util.Collection;
055: import java.util.List;
056: import java.util.Map;
057: import org.netbeans.modules.xml.schema.model.Import;
058: import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
059: import org.netbeans.modules.xml.wsdl.model.Message;
060: import org.netbeans.modules.xml.wsdl.model.Operation;
061: import org.netbeans.modules.xml.wsdl.model.PortType;
062: import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
063: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
064: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
065: import org.openide.util.NbBundle;
066: import org.w3c.dom.Comment;
067: import org.w3c.dom.Element;
068:
069: /**
070: *
071: * @author radval
072: */
073: public class PortTypeGenerator implements Command {
074:
075: private WSDLModel mModel;
076:
077: private PortType mPortType;
078:
079: private Operation mOperation;
080:
081: private Map mConfigurationMap;
082:
083: private List<Message> mNewMessageList = new ArrayList<Message>();
084:
085: private Collection<Import> mImports = new ArrayList<Import>();
086:
087: private ExtensibilityElement mPartnerLinkTypeElement = null;
088:
089: private Comment mComment;
090:
091: /** Creates a new instance of PortTypeGenerator */
092: public PortTypeGenerator(WSDLModel model, Map configurationMap) {
093: this .mModel = model;
094: this .mConfigurationMap = configurationMap;
095: }
096:
097: public PortType getPortType() {
098: return this .mPortType;
099: }
100:
101: public Operation getOperation() {
102: return this .mOperation;
103: }
104:
105: public List<Message> getNewMessages() {
106: return this .mNewMessageList;
107: }
108:
109: public Collection<Import> getImports() {
110: return this .mImports;
111: }
112:
113: public ExtensibilityElement getPartnerLinkType() {
114: return mPartnerLinkTypeElement;
115: }
116:
117: public Comment getComment() {
118: return this .mComment;
119: }
120:
121: public void execute() {
122: if (mModel != null) {
123: //portType
124: String portTypeName = (String) this .mConfigurationMap
125: .get(WizardPortTypeConfigurationStep.PORTTYPE_NAME);
126: if (portTypeName == null)
127: return;
128:
129: this .mPortType = mModel.getFactory().createPortType();
130: this .mPortType.setName(portTypeName);
131: mModel.getDefinitions().addPortType(this .mPortType);
132:
133: OperationGenerator og = new OperationGenerator(this .mModel,
134: this .mPortType, this .mConfigurationMap);
135: og.execute();
136: this .mOperation = og.getOperation();
137: this .mNewMessageList = og.getNewMessages();
138: mImports.addAll(og.getImports());
139:
140: Boolean autoGenPLT = (Boolean) mConfigurationMap
141: .get(WizardPortTypeConfigurationStep.AUTOGEN_PARTNERLINKTYPE);
142: if (autoGenPLT != null && !autoGenPLT) {
143: return;
144: }
145: //automatically generate a partnerLinkType
146: PartnerLinkTypeGenerator pltGen = new PartnerLinkTypeGenerator(
147: this .mPortType, this .mModel);
148: pltGen.execute();
149: mPartnerLinkTypeElement = pltGen.getPartnerLinkType();
150: if (mPartnerLinkTypeElement != null) {
151: this .mModel.getDefinitions().addExtensibilityElement(
152: mPartnerLinkTypeElement);
153: List<WSDLComponent> children = mPartnerLinkTypeElement
154: .getChildren();
155: if (children != null && children.size() > 0) {
156: WSDLComponent role = children.get(0);
157: Element pltElement = mPartnerLinkTypeElement
158: .getPeer();
159: Element roleElement = role.getPeer();
160: this .mComment = this .mModel
161: .getAccess()
162: .getDocumentRoot()
163: .createComment(
164: NbBundle
165: .getMessage(
166: PortTypeGenerator.class,
167: "LBL_partnerLinkType_comment"));
168: this .mModel
169: .getAccess()
170: .insertBefore(
171: pltElement,
172: this .mComment,
173: roleElement,
174: (AbstractDocumentComponent) this.mPartnerLinkTypeElement);
175: }
176: }
177: }
178: }
179: }
|