KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > property > view > BuiltInCustomizerFactory


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  * BuiltInCustomizerFactory.java
22  *
23  * Created on January 29, 2007, 6:16 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.property.view;
30
31 import java.util.logging.Level JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33
34 import javax.xml.namespace.QName JavaDoc;
35
36 import org.netbeans.modules.xml.wsdl.model.BindingFault;
37 import org.netbeans.modules.xml.wsdl.model.BindingInput;
38 import org.netbeans.modules.xml.wsdl.model.BindingOutput;
39 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
40 import org.netbeans.modules.xml.wsdl.model.Message;
41 import org.netbeans.modules.xml.wsdl.model.OperationParameter;
42 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
43 import org.netbeans.modules.xml.wsdl.ui.api.property.ExtensibilityElementPropertyAdapter;
44 import org.netbeans.modules.xml.wsdl.ui.api.property.MessageAttributeProperty;
45 import org.netbeans.modules.xml.wsdl.ui.api.property.MessageProvider;
46 import org.netbeans.modules.xml.wsdl.ui.api.property.PartAttributeProperty;
47 import org.netbeans.modules.xml.wsdl.ui.api.property.PortTypeAttributeProperty;
48 import org.openide.nodes.Node;
49 import org.openide.nodes.Node.Property;
50
51 /**
52  *
53  * @author radval
54  */

55 public class BuiltInCustomizerFactory {
56    
57     public static final String JavaDoc BUILTIN_MESSAGE_CHOOSER = "MessageChooser"; //NO I18N
58

59     public static final String JavaDoc BUILTIN_PART_CHOOSER = "PartChooser"; //NO I18N
60
public static final String JavaDoc BUILTIN_PARTS_CHOOSER = "PartsChooser"; //NO I18N
61
public static final String JavaDoc BUILTIN_PORTTYPE_CHOOSER = "PortTypeChooser"; //NO I18N
62

63     
64     /** Creates a new instance of BuiltInCustomizerFactory */
65     public BuiltInCustomizerFactory() {
66     }
67     
68     /**
69      * For SimpleCustomizer
70      *
71      * @param extensibilityElement
72      * @param attributeQName
73      * @param chooserType
74      * @return
75      */

76     public static Node.Property getProperty(ExtensibilityElement extensibilityElement,
77                               QName JavaDoc attributeQName,
78                               String JavaDoc chooserType, boolean isOptional) {
79         Node.Property property = null;
80         ExtensibilityElementPropertyAdapter adapter = new ExtensibilityElementPropertyAdapter(extensibilityElement, attributeQName.getLocalPart(), isOptional);
81         try {
82             if(chooserType.equals(BUILTIN_PART_CHOOSER)) {
83                 MessageProvider prov = new MessageProviderImpl(extensibilityElement);
84                 property = new PartAttributeProperty(prov, extensibilityElement.getModel(), adapter, String JavaDoc.class, "getValue", "setValue", false);
85                 property.setName(attributeQName.getLocalPart());
86             } else if(chooserType.equals(BUILTIN_PARTS_CHOOSER)) {
87                 MessageProvider prov = new MessageProviderImpl(extensibilityElement);
88                 property = new PartAttributeProperty(prov, extensibilityElement.getModel(), adapter, String JavaDoc.class, "getValue", "setValue", true);
89                 property.setName(attributeQName.getLocalPart());
90             } else if(chooserType.equals(BUILTIN_MESSAGE_CHOOSER)) {
91                 property = new MessageAttributeProperty(adapter, extensibilityElement, String JavaDoc.class, "getValue", "setValue");
92                 property.setName(attributeQName.getLocalPart());
93             } else if(chooserType.equals(BUILTIN_PORTTYPE_CHOOSER)) {
94                 property = new PortTypeAttributeProperty(adapter, String JavaDoc.class, "getValue", "setValue");
95                 property.setName(attributeQName.getLocalPart());
96             } else {
97                 Logger.getLogger(BuiltInCustomizerFactory.class.getName()).log(Level.INFO, "Not a recognized builtin in chooser");
98             }
99         } catch (Exception JavaDoc e) {
100             //TODO:
101
e.printStackTrace();
102         }
103         
104         return property;
105     }
106
107     
108     /**
109      * For DependsOn StaticCustomizer
110      *
111      * @param extensibilityElement
112      * @param attributeQName
113      * @param dependsOnAttributeQName
114      * @param chooserType
115      * @return
116      */

117     public static Node.Property getProperty(ExtensibilityElement extensibilityElement,
118             QName JavaDoc attributeQName, QName JavaDoc dependsOnAttributeQName,
119             String JavaDoc chooserType, boolean isOptional) {
120         Node.Property property = null;
121         try {
122             if(chooserType.equals(BUILTIN_PART_CHOOSER)) {
123                 MessageProvider prov = new DependsOnMessageProviderImpl(extensibilityElement, dependsOnAttributeQName);
124                 property = new PartAttributeProperty(prov, extensibilityElement.getModel(), new ExtensibilityElementPropertyAdapter(extensibilityElement, attributeQName.getLocalPart(), isOptional), String JavaDoc.class, "getValue", "setValue", false);
125                 property.setName(attributeQName.getLocalPart());
126
127             } else {
128                 Logger.getLogger(BuiltInCustomizerFactory.class.getName()).log(Level.INFO, "Not a recognized builtin in chooser");
129             }
130         } catch (Exception JavaDoc e) {
131 // TODO:
132
e.printStackTrace();
133         }
134
135         return property;
136     }
137     
138     
139     /**
140      * For DependsOn DynamicCustomizer.. Not yet used.
141      *
142      * @param extensibilityElement
143      * @param attributeQName
144      * @param nameOfCustomizer
145      * @param className
146      * @param valueType
147      * @return
148      */

149     public static Property getProperty(ExtensibilityElement extensibilityElement, QName JavaDoc attributeQName, String JavaDoc nameOfCustomizer, String JavaDoc className, String JavaDoc valueType, boolean isOptional) {
150         Node.Property property = null;
151         try {
152             if(nameOfCustomizer.equals(BUILTIN_PART_CHOOSER)) {
153                 MessageProvider prov = null; //TODO: to create a provider using the className.
154
property = new PartAttributeProperty(prov, extensibilityElement.getModel(), new ExtensibilityElementPropertyAdapter(extensibilityElement, attributeQName.getLocalPart(), isOptional), String JavaDoc.class, "getValue", "setValue", false);
155                 property.setName(attributeQName.getLocalPart());
156
157             } else {
158                 Logger.getLogger(BuiltInCustomizerFactory.class.getName()).log(Level.INFO, "Not a recognized builtin in chooser");
159             }
160         } catch (Exception JavaDoc e) {
161 // TODO:
162
e.printStackTrace();
163         }
164
165         return property;
166     }
167     
168     /**
169      * Default MessageProvider for elements wanting to get parts of the message that are linked to parent binding input/output/fault.
170      */

171     static class MessageProviderImpl implements MessageProvider {
172         
173         private ExtensibilityElement element;
174         
175         
176         public MessageProviderImpl (ExtensibilityElement elem) {
177             element = elem;
178         }
179         
180         public String JavaDoc getMessage() {
181             return null;
182         }
183
184         public Message getWSDLMessage() {
185             //look for parent of this ExtensibilityElement which is
186
//either binding input/output/fault, once you get that, get the message
187
//from it
188
Message message = null;
189             WSDLComponent parent = element;
190             while (parent != null) {
191                 if (parent instanceof BindingOutput) {
192                     BindingOutput output = (BindingOutput) parent;
193                     OperationParameter op = output.getOutput() != null ? output.getOutput().get() : null;
194                     return op == null ? null : (op.getMessage() == null ? null : op.getMessage().get());
195                 } else if (parent instanceof BindingInput) {
196                     BindingInput input = (BindingInput) parent;
197                     OperationParameter op = input.getInput() != null ? input.getInput().get() : null;
198                     return op == null ? null : (op.getMessage() == null ? null : op.getMessage().get());
199                 } else if (parent instanceof BindingFault) {
200                     BindingFault fault = (BindingFault) parent;
201                     OperationParameter op = fault.getFault() != null ? fault.getFault().get() : null;
202                     return op == null ? null : (op.getMessage() == null ? null : op.getMessage().get());
203                 }
204                 parent = parent.getParent();
205             }
206             
207             return message;
208         }
209         
210     }
211     
212     static class DependsOnMessageProviderImpl implements MessageProvider {
213
214         private ExtensibilityElement element;
215         private QName JavaDoc dependsOnAttributeQName;
216
217
218         public DependsOnMessageProviderImpl (ExtensibilityElement elem, QName JavaDoc dependsOnAttributeQName) {
219             element = elem;
220             this.dependsOnAttributeQName = dependsOnAttributeQName;
221         }
222
223         public String JavaDoc getMessage() {
224             return element.getAttribute(dependsOnAttributeQName.getLocalPart());
225         }
226
227         public Message getWSDLMessage() {
228             return null;
229         }
230
231     }
232
233
234 }
235
Popular Tags