1 19 20 26 package org.netbeans.modules.xml.wsdl.ui.extensibility.model.impl; 27 28 import java.io.InputStream ; 29 import java.util.ArrayList ; 30 import java.util.Collection ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 import java.util.Map ; 34 import java.util.logging.Level ; 35 import java.util.logging.Logger ; 36 import org.netbeans.modules.xml.wsdl.ui.common.Constants; 37 38 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElement; 39 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 40 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.XMLSchemaFileInfo; 41 import org.openide.loaders.DataFolder; 42 import org.openide.loaders.DataObject; 43 import org.openide.util.NbBundle; 44 45 46 52 public class WSDLExtensibilityElementsImpl implements WSDLExtensibilityElements { 53 54 private static final Logger mLogger = Logger.getLogger(WSDLExtensibilityElementsImpl.class.getName()); 55 56 private DataFolder mRootFolder = null; 57 58 private Map elementsMap = new HashMap (); 59 60 private Map <String , XMLSchemaFileInfo> schemasMap = new HashMap <String , XMLSchemaFileInfo>(); 61 62 public WSDLExtensibilityElementsImpl(DataFolder rootFolder) { 63 this.mRootFolder = rootFolder; 64 readAllSchemas(); 65 } 66 67 public WSDLExtensibilityElement getWSDLExtensibilityElement(String name) { 68 WSDLExtensibilityElement element = (WSDLExtensibilityElement) elementsMap.get(name); 69 if(element != null) { 70 return element; 71 } 72 73 DataObject[] dataObjects = this.mRootFolder.getChildren(); 74 for(int i = 0; i < dataObjects.length; i++ ) { 75 DataObject dObj = dataObjects[i]; 76 if(dObj instanceof DataFolder && dObj.getName().equals(name)) { 77 element = new WSDLExtensibilityElementImpl((DataFolder) dObj, this); 78 elementsMap.put(name, element); 79 break; 80 } 81 } 82 83 return element; 84 } 85 86 public InputStream [] getAllExtensionSchemas() { 87 ArrayList extensionSchemas = new ArrayList (); 88 DataObject[] dataObjects = this.mRootFolder.getChildren(); 89 for(int i = 0; i < dataObjects.length; i++ ) { 90 DataObject dObj = dataObjects[i]; 91 if(!(dObj instanceof DataFolder) && dObj.getPrimaryFile().hasExt(Constants.XSD_EXT)) { 92 InputStream in = null; 93 try { 94 in = dObj.getPrimaryFile().getInputStream(); 95 } catch(Throwable t) { 96 mLogger.log(Level.SEVERE, NbBundle.getMessage(WSDLExtensibilityElementsImpl.class, "ERR_MSG_FAILED_TO_GET_SCHEMA", dObj.getPrimaryFile().getPath())); 97 } 98 99 if(in != null) { 100 extensionSchemas.add(in); 101 } 102 } 103 } 104 105 return (InputStream []) extensionSchemas.toArray( new InputStream [] {}); 106 } 107 108 public XMLSchemaFileInfo getXMLSchemaFileInfoMatchingFileName(String fileName) { 109 XMLSchemaFileInfo schemaInfo = this.schemasMap.get(fileName); 110 return schemaInfo; 111 } 112 113 public XMLSchemaFileInfo getXMLSchemaFileInfo(String namespace) { 114 XMLSchemaFileInfo schemaInfo = null; 115 116 Iterator <XMLSchemaFileInfo> it = this.schemasMap.values().iterator(); 117 while(it.hasNext()) { 118 XMLSchemaFileInfo info = it.next(); 119 String ns = info.getSchema().getTargetNamespace(); 120 if(ns != null && ns.equals(namespace)) { 122 schemaInfo = info; 123 break; 124 } 125 } 126 127 return schemaInfo; 128 } 129 130 private void readAllSchemas() { 131 DataObject[] dataObjects = this.mRootFolder.getChildren(); 132 for(int i = 0; i < dataObjects.length; i++ ) { 133 DataObject dObj = dataObjects[i]; 134 if(!(dObj instanceof DataFolder) && dObj.getPrimaryFile().hasExt(Constants.XSD_EXT)) { 135 XMLSchemaFileInfo schemaFileInfo = new XMLSchemaFileInfoImpl(dObj); 136 this.schemasMap.put(dObj.getName(), schemaFileInfo); 137 } 138 } 139 } 140 141 public XMLSchemaFileInfo[] getAllXMLSchemaFileInfos() { 142 Collection <XMLSchemaFileInfo> infos = schemasMap.values(); 143 return infos.toArray(new XMLSchemaFileInfo[infos.size()]); 144 } 145 146 } 147 | Popular Tags |