KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > extension > bpel > PropertyAliasConfigurator


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 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.extension.bpel;
21
22
23 import java.beans.PropertyEditor JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.List JavaDoc;
28
29 import javax.xml.namespace.QName JavaDoc;
30
31 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
32 import org.netbeans.modules.xml.wsdl.model.Message;
33 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
34 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.BPELQName;
35 import org.netbeans.modules.xml.wsdl.ui.api.property.ComboBoxPropertyEditor;
36 import org.netbeans.modules.xml.wsdl.ui.api.property.ExtensibilityElementPropertyAdapter;
37 import org.netbeans.modules.xml.wsdl.ui.api.property.MessageAttributeProperty;
38 import org.netbeans.modules.xml.wsdl.ui.api.property.MessageProvider;
39 import org.netbeans.modules.xml.wsdl.ui.api.property.PartAttributeProperty;
40 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
41 import org.netbeans.modules.xml.wsdl.ui.spi.ExtensibilityElementConfigurator;
42 import org.netbeans.modules.xml.xam.ui.XAMUtils;
43 import org.openide.ErrorManager;
44 import org.openide.nodes.Node;
45 import org.openide.nodes.PropertySupport;
46 import org.openide.nodes.Node.Property;
47 import org.openide.util.NbBundle;
48
49 public class PropertyAliasConfigurator extends
50         ExtensibilityElementConfigurator {
51     
52     private static QName JavaDoc myQName = BPELQName.PROPERTY_ALIAS.getQName();
53     private static QName JavaDoc queryQName = BPELQName.QUERY.getQName();
54     private static QName JavaDoc propertyQName = BPELQName.PROPERTY.getQName();
55     
56     private static QName JavaDoc[] supportedQNames = {myQName, queryQName};
57
58     @Override JavaDoc
59     public Collection JavaDoc<QName JavaDoc> getSupportedQNames() {
60         return Arrays.asList(supportedQNames);
61     }
62     
63     @Override JavaDoc
64     public Property getProperty(ExtensibilityElement extensibilityElement,
65             QName JavaDoc qname, String JavaDoc attributeName) {
66         Node.Property property = null;
67         if (myQName.equals(qname)) {
68             if ("messageType".equals(attributeName)) {//NOI18N
69
try {
70                     property = new MessageAttributeProperty(new ExtensibilityElementPropertyAdapter(extensibilityElement, attributeName), extensibilityElement, String JavaDoc.class, "getValue", "setValue");
71                     property.setName(NbBundle.getMessage(PropertyConfigurator.class, "PROPERTY_NAME_PA_MESSAGETYPE"));
72                 } catch (NoSuchMethodException JavaDoc e) {
73                     ErrorManager.getDefault().notify(e);
74                 }
75             } else if ("part".equals(attributeName)) {//NOI18N
76
MessageProvider prov = new MessageProviderImpl(extensibilityElement);
77                 try {
78                     property = new PartAttributeProperty(prov, extensibilityElement.getModel(), new ExtensibilityElementPropertyAdapter(extensibilityElement, attributeName), String JavaDoc.class, "getValue", "setValue", false);
79                     property.setName(NbBundle.getMessage(PropertyConfigurator.class, "PROPERTY_NAME_PA_PART"));
80                 } catch (NoSuchMethodException JavaDoc e) {
81                     ErrorManager.getDefault().notify(e);
82                 }
83             } else if ("propertyName".equals(attributeName)) {//NOI18N
84
try {
85                     property = new PropertyNameProperty(new ExtensibilityElementPropertyAdapter(extensibilityElement, attributeName), String JavaDoc.class, "getValue", "setValue");
86                 } catch (NoSuchMethodException JavaDoc e) {
87                     ErrorManager.getDefault().notify(e);
88                 }
89                 property.setName(NbBundle.getMessage(PropertyConfigurator.class, "PROPERTY_NAME_PROPERTY_NAME"));
90             }
91         }
92         return property;
93     }
94
95     @Override JavaDoc
96     public String JavaDoc getDisplayAttributeName(ExtensibilityElement extensibilityElement, QName JavaDoc qname) {
97         return "propertyName"; //NOI18N
98
}
99
100
101     
102     static class MessageProviderImpl implements MessageProvider {
103         private ExtensibilityElement element;
104         
105         public MessageProviderImpl (ExtensibilityElement elem) {
106             element = elem;
107         }
108         
109         public String JavaDoc getMessage() {
110             return element.getAttribute("messageType");//NOI18N
111
}
112
113         public Message getWSDLMessage() {
114             return null;
115         }
116         
117     }
118     
119     
120     class PropertyNameProperty extends PropertySupport.Reflection {
121
122         ExtensibilityElementPropertyAdapter adapter;
123         
124         public PropertyNameProperty(ExtensibilityElementPropertyAdapter instance, Class JavaDoc valueType, String JavaDoc getter, String JavaDoc setter) throws NoSuchMethodException JavaDoc {
125             super(instance, valueType, getter, setter);
126             adapter = instance;
127         }
128         
129         
130         @Override JavaDoc
131         public PropertyEditor JavaDoc getPropertyEditor() {
132             ArrayList JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>();
133             list.add("");
134             WSDLModel model = adapter.getExtensibilityElement().getModel();
135             addToPropertyList(list, model);
136             
137             //Get from imported wsdls too.
138
Collection JavaDoc<WSDLModel> importedModels = Utility.getImportedDocuments(model);
139             for (WSDLModel imp : importedModels ) {
140                 addToPropertyList(list, imp);
141             }
142             
143             return new ComboBoxPropertyEditor(list.toArray(new String JavaDoc[list.size()]));
144         }
145         
146         private void addToPropertyList(List JavaDoc<String JavaDoc> propertyList, WSDLModel model) {
147             List JavaDoc<ExtensibilityElement> ees = model.getDefinitions().getExtensibilityElements();
148             String JavaDoc prefix = Utility.getNamespacePrefix(model.getDefinitions().getTargetNamespace(),
149                     adapter.getExtensibilityElement());
150             for (ExtensibilityElement ee : ees) {
151                 if (propertyQName.equals(ee.getQName())) {
152                     propertyList.add(prefix + ":" + ee.getAttribute("name"));
153                 }
154             }
155         }
156         
157         @Override JavaDoc
158         public boolean canWrite() {
159             return XAMUtils.isWritable(adapter.getExtensibilityElement().getModel());
160         }
161         
162     }
163
164
165     @Override JavaDoc
166     public String JavaDoc getAttributeUniqueValuePrefix(ExtensibilityElement extensibilityElement, QName JavaDoc qname, String JavaDoc attributeName) {
167         // TODO Auto-generated method stub
168
return null;
169     }
170
171     @Override JavaDoc
172     public String JavaDoc getDefaultValue(ExtensibilityElement extensibilityElement, QName JavaDoc qname, String JavaDoc attributeName) {
173         // TODO Auto-generated method stub
174
return null;
175     }
176
177     @Override JavaDoc
178     public String JavaDoc getTypeDisplayName(ExtensibilityElement extensibilityElement, QName JavaDoc qname) {
179         if (qname.equals(myQName))
180             return NbBundle.getMessage(PropertyAliasConfigurator.class, "LBL_PropertyAlias_TypeDisplayName");
181         else if (qname.equals(queryQName))
182             return NbBundle.getMessage(PropertyAliasConfigurator.class, "LBL_PropertyAliasQuery_TypeDisplayName");
183         return null;
184     }
185
186 }
187
Popular Tags