1 19 20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel.validation; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.net.URI ; 25 import javax.swing.text.Document ; 26 import org.netbeans.modules.xml.retriever.catalog.impl.CatalogWriteModelImpl; 27 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 28 import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory; 29 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 30 import org.netbeans.modules.xml.xam.ModelSource; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.Lookup; 34 import org.openide.util.lookup.Lookups; 35 36 40 41 public class TestCatalogModel extends CatalogWriteModelImpl { 42 private TestCatalogModel(){ 43 } 44 45 static TestCatalogModel singletonCatMod = null; 46 47 public static TestCatalogModel getDefault(){ 48 if (singletonCatMod == null){ 49 singletonCatMod = new TestCatalogModel(); 50 } 51 return singletonCatMod; 52 } 53 54 public ModelSource getModelSource(URI locationURI) throws CatalogModelException { 55 File file = new File (locationURI); 56 FileObject thisFileObj = FileUtil.toFileObject(file); 57 return createModelSource(thisFileObj, true); 58 } 59 60 public ModelSource getModelSource(URI locationURI, ModelSource modelSourceOfSourceDocument) throws CatalogModelException { 61 if(locationURI == null) { 62 return null; 63 } 64 65 URI resolvedURI = locationURI; 66 67 if(modelSourceOfSourceDocument != null) { 68 FileObject sFileObj = (FileObject) modelSourceOfSourceDocument.getLookup().lookup(FileObject.class); 69 if(sFileObj != null) { 70 File sFile = FileUtil.toFile(sFileObj); 71 if(sFile != null) { 72 URI sURI = sFile.toURI(); 73 resolvedURI = sURI.resolve(locationURI); 74 } 75 } 76 } 77 78 if(resolvedURI != null) { 79 return getModelSource(resolvedURI); 80 } 81 82 return null; 83 } 84 85 86 protected Document getDocument(FileObject fo){ 87 Document result = null; 88 89 if (result != null) return result; 90 try { 91 92 File file = FileUtil.toFile(fo); 93 FileInputStream fis = new FileInputStream (file); 94 byte buffer[] = new byte[fis.available()]; 95 result = new org.netbeans.editor.BaseDocument( 96 org.netbeans.modules.xml.text.syntax.XMLKit.class, false); 97 result.remove(0, result.getLength()); 99 fis.read(buffer); 100 fis.close(); 101 String str = new String (buffer); 102 result.insertString(0,str,null); 103 104 } catch (Exception dObjEx) { 105 return null; 106 } 107 108 return result; 109 } 110 111 public ModelSource createModelSource(FileObject thisFileObj, boolean readOnly) throws CatalogModelException{ 112 File file = FileUtil.toFile(thisFileObj); 113 Lookup lookup = Lookups.fixed(new Object []{ 114 file, 115 thisFileObj, 116 getDocument(thisFileObj), 117 getDefault() 118 }); 119 return new ModelSource(lookup, readOnly); 120 } 121 122 123 124 public WSDLModel getWSDLModel(URI locationURI) throws Exception { 125 ModelSource source = getDefault().getModelSource(locationURI); 126 WSDLModel model = WSDLModelFactory.getDefault().getModel(source); 127 model.sync(); 128 return model; 129 } 130 131 132 public String toString(){ 133 return "TestCatalogModel"+super.toString(); 134 } 135 } 136 137 | Popular Tags |