KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > wizard > WsdlGenerationUtil


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * WsdlGenerationUtil.java
22  *
23  * Created on September 6, 2006, 5:32 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.wsdl.ui.wizard;
30
31 import javax.xml.namespace.QName JavaDoc;
32 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
33 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
34 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
35 import org.netbeans.modules.xml.wsdl.ui.view.wizard.ExtensionAttrType;
36 import org.netbeans.modules.xml.wsdl.ui.view.wizard.ExtensionElementType;
37 import org.netbeans.modules.xml.wsdl.ui.view.wizard.WsdlElementType;
38 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplate;
39
40 /**
41  *
42  * @author radval
43  */

44 public class WsdlGenerationUtil {
45     
46     private WSDLModel mModel;
47     
48     /** Creates a new instance of WsdlGenerationUtil */
49     public WsdlGenerationUtil(WSDLModel model) {
50         this.mModel = model;
51     }
52     
53     
54     public ExtensibilityElement createAndAddExtensionElementAndAttribute(String JavaDoc wsdlElementNameInTemplate, LocalizedTemplate bindingSubType, WSDLComponent parentWSDLComponent) {
55          ExtensibilityElement e = null;
56          String JavaDoc namespace = bindingSubType.getTemplateGroup().getNamespace();
57          String JavaDoc prefix = bindingSubType.getTemplateGroup().getPrefix();
58         
59          WsdlElementType wsdlElement = bindingSubType.getWSDLElementType(wsdlElementNameInTemplate);
60          
61          if(wsdlElement != null) {
62              ExtensionElementType[] ees = wsdlElement.getExtensionElement();
63              if(ees != null) {
64                  for(int i=0; i < ees.length; i++) {
65                      ExtensionElementType ee = ees[i];
66                      String JavaDoc name = ee.getName();
67                      if(name != null) {
68                         e = createExtensibilityElement(name, prefix, namespace, parentWSDLComponent);
69                         if(e != null) {
70                             parentWSDLComponent.addExtensibilityElement(e);
71                             createAndAddExtensibilityElementAttributes(e, ee.getExtensionAttr());
72                         }
73                      }
74                  }
75              }
76          }
77          
78          return e;
79     }
80     
81      public void createAndAddExtensibilityElementAttributes(ExtensibilityElement ee, ExtensionAttrType[] attrs) {
82         if(attrs != null) {
83             for(int i =0; i< attrs.length; i++) {
84                 ExtensionAttrType attr = attrs[i];
85                 String JavaDoc name = attr.getName();
86                 String JavaDoc defaultValue = attr.getDefaultValue();
87                 if(name != null) {
88                     ee.setAttribute(name, defaultValue);
89                 }
90             }
91         }
92      }
93     
94      public ExtensibilityElement createExtensibilityElement(String JavaDoc elementName,
95             String JavaDoc prefix,
96             String JavaDoc targetNamespace,
97             WSDLComponent parent) {
98         QName JavaDoc qName = null;
99         
100         if(prefix != null) {
101             qName = new QName JavaDoc(targetNamespace, elementName, prefix);
102         } else {
103             qName = new QName JavaDoc(targetNamespace, elementName);
104         }
105         
106         //create extensibility element
107
//set all its attribute as defined in schema element
108
ExtensibilityElement exElement = (ExtensibilityElement) this.mModel.getFactory().create(parent, qName);
109         
110         return exElement;
111         
112     }
113 }
114
Popular Tags