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: * WsdlGenerationUtil.java
044: *
045: * Created on September 6, 2006, 5:32 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 javax.xml.namespace.QName;
054:
055: import org.netbeans.modules.xml.wsdl.bindingsupport.template.ExtensionAttrType;
056: import org.netbeans.modules.xml.wsdl.bindingsupport.template.ExtensionElementType;
057: import org.netbeans.modules.xml.wsdl.bindingsupport.template.WsdlElementType;
058: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplate;
059: import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
060: import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
061: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
062:
063: /**
064: *
065: * @author radval
066: */
067: public class WsdlGenerationUtil {
068:
069: private WSDLModel mModel;
070:
071: /** Creates a new instance of WsdlGenerationUtil */
072: public WsdlGenerationUtil(WSDLModel model) {
073: this .mModel = model;
074: }
075:
076: public ExtensibilityElement createAndAddExtensionElementAndAttribute(
077: String wsdlElementNameInTemplate,
078: LocalizedTemplate bindingSubType,
079: WSDLComponent parentWSDLComponent) {
080: ExtensibilityElement e = null;
081: String namespace = bindingSubType.getTemplateGroup()
082: .getNamespace();
083: String prefix = bindingSubType.getTemplateGroup().getPrefix();
084:
085: WsdlElementType wsdlElement = bindingSubType
086: .getWSDLElementType(wsdlElementNameInTemplate);
087:
088: if (wsdlElement != null) {
089: ExtensionElementType[] ees = wsdlElement
090: .getExtensionElement();
091: if (ees != null) {
092: for (int i = 0; i < ees.length; i++) {
093: ExtensionElementType ee = ees[i];
094: String name = ee.getName();
095: if (name != null) {
096: e = createExtensibilityElement(name, prefix,
097: namespace, parentWSDLComponent);
098: if (e != null) {
099: parentWSDLComponent
100: .addExtensibilityElement(e);
101: createAndAddExtensibilityElementAttributes(
102: e, ee.getExtensionAttr());
103: }
104: }
105: }
106: }
107: }
108:
109: return e;
110: }
111:
112: public void createAndAddExtensibilityElementAttributes(
113: ExtensibilityElement ee, ExtensionAttrType[] attrs) {
114: if (attrs != null) {
115: for (int i = 0; i < attrs.length; i++) {
116: ExtensionAttrType attr = attrs[i];
117: String name = attr.getName();
118: String defaultValue = attr.getDefaultValue();
119: if (name != null) {
120: ee.setAttribute(name, defaultValue);
121: }
122: }
123: }
124: }
125:
126: public ExtensibilityElement createExtensibilityElement(
127: String elementName, String prefix, String targetNamespace,
128: WSDLComponent parent) {
129: QName qName = null;
130:
131: if (prefix != null) {
132: qName = new QName(targetNamespace, elementName, prefix);
133: } else {
134: qName = new QName(targetNamespace, elementName);
135: }
136:
137: //create extensibility element
138: //set all its attribute as defined in schema element
139: ExtensibilityElement exElement = (ExtensibilityElement) this.mModel
140: .getFactory().create(parent, qName);
141:
142: return exElement;
143:
144: }
145: }
|