1 19 package org.netbeans.modules.xml.wsdl.ui.completion; 20 21 import java.io.InputStream ; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import org.netbeans.modules.xml.schema.completion.spi.CompletionContext; 26 import org.netbeans.modules.xml.schema.completion.spi.CompletionModelProvider; 27 import org.netbeans.modules.xml.schema.model.SchemaModel; 28 import org.netbeans.modules.xml.schema.model.SchemaModelFactory; 29 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 30 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementsFactory; 31 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.XMLSchemaFileInfo; 32 import org.netbeans.modules.xml.xam.ModelSource; 33 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel; 34 import org.openide.util.lookup.Lookups; 35 36 41 public class WSDLCompletionModelProvider extends CompletionModelProvider { 42 43 public WSDLCompletionModelProvider() { 44 } 45 46 51 @Override 52 public List <CompletionModel> getModels(CompletionContext context) { 53 if (!context.getPrimaryFile().getExt().equals("wsdl")) { 55 return null; 56 } 57 58 SchemaModel wsdlSchemaModel = createWSDLSchemaModel(); 59 if(wsdlSchemaModel == null) 60 return null; 61 CompletionModel cm = new WSDLCompletionModel(context, wsdlSchemaModel, "wsdl"); List <CompletionModel> models = new ArrayList <CompletionModel>(); 63 models.add(cm); 64 65 try { 66 WSDLExtensibilityElements elements = WSDLExtensibilityElementsFactory.getInstance().getWSDLExtensibilityElements(); 67 for (XMLSchemaFileInfo info : elements.getAllXMLSchemaFileInfos()) { 68 CompletionModel model = createExtensibilityElementSchemaCompletionModel(info); 69 if (model != null) { 70 models.add(model); 71 } 72 } 73 } catch (Exception e) { 74 e.printStackTrace(); 75 } 76 return models; 77 } 78 79 private CompletionModel createExtensibilityElementSchemaCompletionModel(XMLSchemaFileInfo info) { 80 if (info.getSchema() != null) { 81 return new ExtensibilityElementCompletionModel(info.getSchema().getModel(), info.getPrefix(), info.getSchema().getTargetNamespace()); 82 } 83 return null; 84 } 85 86 private SchemaModel createWSDLSchemaModel() { 87 try { 88 InputStream in = getClass().getResourceAsStream("/org/netbeans/modules/xml/wsdl/ui/netbeans/module/resources/wsdl.xsd"); javax.swing.text.Document d = AbstractDocumentModel. 90 getAccessProvider().loadSwingDocument(in); 91 ModelSource ms = new ModelSource(Lookups.singleton(d), false); 92 SchemaModel m = SchemaModelFactory.getDefault().createFreshModel(ms); 93 m.sync(); 94 return m; 95 } catch (Exception ex) { 96 } 98 return null; 99 } 100 101 102 class ExtensibilityElementCompletionModel extends CompletionModel { 103 104 SchemaModel schemaModel; 105 String targetNamespace; 106 String prefix; 107 108 public ExtensibilityElementCompletionModel(SchemaModel schemaModel, String prefix, String targetNamespace) { 109 this.schemaModel = schemaModel; 110 this.prefix = prefix; 111 this.targetNamespace = targetNamespace; 112 } 113 114 @Override 115 public SchemaModel getSchemaModel() { 116 return schemaModel; 117 } 118 119 @Override 120 public String getSuggestedPrefix() { 121 return prefix; 122 } 123 124 @Override 125 public String getTargetNamespace() { 126 127 return targetNamespace; 128 } 129 130 } 131 132 } 133 | Popular Tags |