1 19 20 26 package org.netbeans.modules.xml.wsdl.ui.extensibility.model.impl; 27 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 import javax.xml.namespace.QName ; 36 37 import org.netbeans.modules.xml.schema.model.GlobalElement; 38 import org.netbeans.modules.xml.schema.model.Schema; 39 import org.netbeans.modules.xml.wsdl.ui.common.Constants; 40 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElement; 41 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementInfo; 42 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementInfoContainer; 43 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.XMLSchemaFileInfo; 44 import org.openide.loaders.DataFolder; 45 import org.openide.loaders.DataObject; 46 47 48 49 56 public class WSDLExtensibilityElementImpl implements WSDLExtensibilityElement { 57 58 59 private DataFolder mDataFolder; 60 61 private Map elementInfoMap = new HashMap (); 62 63 private Map providersMap = new HashMap (); 64 65 private WSDLExtensibilityElementsImpl mRootElement; 66 67 public WSDLExtensibilityElementImpl(DataFolder dataObject, WSDLExtensibilityElementsImpl element) { 68 this.mDataFolder = dataObject; 69 this.mRootElement = element; 70 } 71 72 public WSDLExtensibilityElementInfo getWSDLExtensibilityElementInfos(QName elementQName) { 73 List allInfos = getAllWSDLExtensibilityElementInfos(); 74 Iterator it = allInfos.iterator(); 75 String ns = elementQName.getNamespaceURI(); 76 String localPart = elementQName.getLocalPart(); 77 while(it.hasNext()) { 78 WSDLExtensibilityElementInfo eInfo = (WSDLExtensibilityElementInfo) it.next(); 79 Schema schema = eInfo.getSchema(); 80 if(schema != null) { 81 if(ns != null) { 82 if(ns.equals(schema.getTargetNamespace()) 83 && localPart.equals(eInfo.getElementName())) { 84 if(findGlobalElement(elementQName, schema) != null) { 85 return eInfo; 86 } 87 } 88 } 89 } 90 } 91 92 return null; 93 } 94 95 public List getAllWSDLExtensibilityElementInfos() { 96 ArrayList elementsInfo = new ArrayList (); 97 elementsInfo.addAll(getWSDLExtensibilityElementInfos()); 98 99 List containers = getAllWSDLExtensibilityElementInfoContainers(); 100 Iterator it = containers.iterator(); 101 while(it.hasNext()) { 102 WSDLExtensibilityElementInfoContainer container = (WSDLExtensibilityElementInfoContainer) it.next(); 103 elementsInfo.addAll(container.getAllWSDLExtensibilityElementInfo()); 104 } 105 106 return elementsInfo; 107 } 108 109 public List getWSDLExtensibilityElementInfos() { 110 ArrayList elementInfos = new ArrayList (); 111 ArrayList allDataObjectNames = new ArrayList (); 112 113 DataObject[] children = this.mDataFolder.getChildren(); 114 for(int i = 0; i < children.length; i++ ) { 115 DataObject dObj = children[i]; 116 if(!(dObj instanceof DataFolder)) { 117 WSDLExtensibilityElementInfo elementInfo = 118 (WSDLExtensibilityElementInfo) elementInfoMap.get(dObj.getName()); 119 120 if(elementInfo == null) { 121 elementInfo = createNewElementInfo(dObj); 122 elementInfoMap.put(dObj.getName(), elementInfo); 123 } 124 125 elementInfos.add(elementInfo); 126 allDataObjectNames.add(dObj.getName()); 127 } 128 } 129 130 131 135 136 return elementInfos; 137 } 138 139 public List getAllWSDLExtensibilityElementInfoContainers() { 140 ArrayList providers = new ArrayList (); 141 DataObject[] children = this.mDataFolder.getChildren(); 142 for(int i = 0; i < children.length; i++ ) { 143 DataObject dObj = children[i]; 144 if(dObj instanceof DataFolder) { 145 WSDLExtensibilityElementInfoContainer provider = 146 (WSDLExtensibilityElementInfoContainer) providersMap.get(dObj.getName()); 147 148 if(provider == null) { 149 provider = createNewProvider((DataFolder) dObj); 150 providersMap.put(dObj.getName(), provider); 151 } 152 providers.add(provider); 153 } 154 } 155 156 160 return providers; 161 } 162 163 public String getName() { 164 return mDataFolder.getName(); 165 } 166 167 public boolean isExtensibilityElementsAvailable() { 168 boolean available = false; 169 170 if(this.getAllWSDLExtensibilityElementInfos().size() != 0) { 171 available = true; 172 } 173 return available; 174 } 175 176 private WSDLExtensibilityElementInfoContainer createNewProvider(DataFolder dataObject) { 177 WSDLExtensibilityElementInfoContainer provider = 178 new WSDLExtensibilityElementInfoContainerImpl(dataObject, this.mRootElement); 179 180 return provider; 181 } 182 183 184 private WSDLExtensibilityElementInfo createNewElementInfo(DataObject dataObject) { 185 186 Object val = dataObject.getPrimaryFile().getAttribute(Constants.XSD_FILE_NAME); 187 XMLSchemaFileInfo xmlSchemaInfo = null; 188 if(val instanceof String ) { 189 xmlSchemaInfo = this.mRootElement.getXMLSchemaFileInfoMatchingFileName((String ) val); 190 } 191 192 193 WSDLExtensibilityElementInfo elementInfo = 194 new WSDLExtensibilityElementInfoImpl(dataObject, xmlSchemaInfo); 195 196 return elementInfo; 197 } 198 199 200 private GlobalElement findGlobalElement(QName elementQName, Schema schema) { 201 Collection <GlobalElement> elements = schema.getElements(); 202 Iterator <GlobalElement> iter = elements.iterator(); 203 while (iter.hasNext()) { 204 GlobalElement elem = iter.next(); 205 if (elem.getName().equals(elementQName.getLocalPart())) { 206 return elem; 207 } 208 } 209 210 return null; 211 } 212 213 public Collection <WSDLExtensibilityElementInfo> getWSDLExtensibilityElementInfos(String namespace) { 214 List <WSDLExtensibilityElementInfo> allInfos = getAllWSDLExtensibilityElementInfos(); 215 List <WSDLExtensibilityElementInfo> result = new ArrayList <WSDLExtensibilityElementInfo>(); 216 for (WSDLExtensibilityElementInfo eInfo : allInfos) { 217 Schema schema = eInfo.getSchema(); 218 if(schema != null) { 219 if(namespace != null) { 220 if(namespace.equals(schema.getTargetNamespace())) { 221 result.add(eInfo); 222 } 223 } 224 } 225 } 226 227 return result; 228 } 229 } 230 | Popular Tags |