1 19 20 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype; 21 22 import java.io.Serializable ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.Comparator ; 27 import java.util.List ; 28 29 import javax.xml.namespace.QName ; 30 31 import org.netbeans.modules.xml.wsdl.model.Binding; 32 import org.netbeans.modules.xml.wsdl.model.BindingFault; 33 import org.netbeans.modules.xml.wsdl.model.BindingInput; 34 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 35 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 36 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; 37 import org.netbeans.modules.xml.wsdl.model.Port; 38 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 39 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElement; 40 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementInfo; 41 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 42 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementsFactory; 43 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 44 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 45 import org.openide.ErrorManager; 46 import org.openide.util.datatransfer.NewType; 47 48 52 public class ExtensibilityElementNewTypesFactory implements NewTypesFactory { 53 54 private String mNodeType; 55 private String [] mSpecialTargetNamespaces; 56 57 public ExtensibilityElementNewTypesFactory(String nodeType) { 58 mNodeType = nodeType; 59 } 60 61 public ExtensibilityElementNewTypesFactory(String nodeType, String [] specialTargetNS) { 62 mNodeType = nodeType; 63 mSpecialTargetNamespaces = specialTargetNS; 64 } 65 66 public NewType[] getNewTypes(WSDLComponent component) { 67 ArrayList <ExtensibilityElementNewType> eeNewTypeList = new ArrayList <ExtensibilityElementNewType>(); 68 try { 69 WSDLExtensibilityElements extensibilityElement 70 = WSDLExtensibilityElementsFactory.getInstance().getWSDLExtensibilityElements(); 71 72 WSDLExtensibilityElement element = extensibilityElement.getWSDLExtensibilityElement(mNodeType); 73 String namespace = getExtensibilityElementNamespace(component); 74 if(element != null) { 75 Collection <WSDLExtensibilityElementInfo> elementInfos = null; 76 if (mSpecialTargetNamespaces != null) { 77 elementInfos = new ArrayList <WSDLExtensibilityElementInfo>(); 78 for (String ns : mSpecialTargetNamespaces) { 79 elementInfos.addAll(element.getWSDLExtensibilityElementInfos(ns)); 80 } 81 82 } else { 83 if (namespace != null) { 84 elementInfos = element.getWSDLExtensibilityElementInfos(namespace); 85 } else { 86 elementInfos = element.getAllWSDLExtensibilityElementInfos(); 87 } 88 } 89 90 92 createExtensibilityElementNewTypes(component, elementInfos, eeNewTypeList); 93 94 } 95 } catch(Exception ex) { 96 ErrorManager.getDefault().notify(ex); 97 } 98 return eeNewTypeList.toArray(new NewType[eeNewTypeList.size()]); 99 } 100 101 private void createExtensibilityElementNewTypes(WSDLComponent component, Collection <WSDLExtensibilityElementInfo> infos, List <ExtensibilityElementNewType> list) { 102 103 if (infos != null) { 104 for (WSDLExtensibilityElementInfo info : infos) { 105 list.add(new ExtensibilityElementNewType(component, info)); 106 } 107 Collections.sort(list, new ExtensibilityElementNewTypeComparator()); 108 } 109 } 110 111 private String getExtensibilityElementNamespace(WSDLComponent comp) { 112 Binding binding = null; 113 if (comp instanceof BindingOperation 114 || comp instanceof BindingInput 115 || comp instanceof BindingOutput 116 || comp instanceof BindingFault) 117 { 118 WSDLComponent tempComp = comp; 119 while (!((tempComp = tempComp.getParent()) instanceof Binding)) { 120 } 122 binding = (Binding) tempComp; 123 } else if (comp instanceof Port) { 124 NamedComponentReference<Binding> ref = ((Port)comp).getBinding(); 125 if (ref != null && ref.get() != null) { 126 binding = ref.get(); 127 } 128 } 129 if (binding != null) { 130 List <ExtensibilityElement> eeList = binding.getExtensibilityElements(); 131 if (eeList != null && !eeList.isEmpty()) { 132 ExtensibilityElement element = eeList.get(0); 133 QName qname = element.getQName(); 134 if (qname.getNamespaceURI() != null) { 135 return qname.getNamespaceURI(); 136 } else if (qname.getPrefix() != null) { 137 return Utility.getNamespaceURI(qname.getPrefix(), comp); 138 } 139 } 140 } 141 142 return null; 143 } 144 145 146 147 static class ExtensibilityElementNewTypeComparator implements Comparator <ExtensibilityElementNewType>, Serializable { 148 149 private static final long serialVersionUID = 8682651956156135260L; 150 151 public int compare(ExtensibilityElementNewType o1, ExtensibilityElementNewType o2) { 152 return o1.getName().compareTo(o2.getName()); 153 } 154 155 } 156 157 } 158 | Popular Tags |