1 19 package org.netbeans.modules.websvc.wsitconf.util; 20 21 import java.io.File ; 22 import java.net.URI ; 23 import java.net.URISyntaxException ; 24 import org.netbeans.modules.xml.xam.ModelSource; 25 import org.openide.cookies.SaveCookie; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileUtil; 28 import org.openide.loaders.DataObject; 29 30 34 public enum NamespaceLocation { 35 POLICY("http://policy/sss", "policysss.xml"); 36 37 private String namespace; 38 private String resourcePath; 39 private String location; 40 41 42 NamespaceLocation(String namespace, String resourcePath) { 43 this.namespace = namespace; 44 this.resourcePath = resourcePath; 45 this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10); 46 } 47 public String getNamespace() { return namespace; } 48 public String getResourcePath() { return resourcePath; } 49 public URI getLocationURI() throws URISyntaxException { 50 return new URI (getLocation()); 51 } 52 public String getLocation() { return location; } 53 public URI getNamespaceURI() throws URISyntaxException { return new URI (getNamespace()); } 54 public static File wsdlTestDir = null; 55 public static File getSchemaTestTempDir() throws Exception { 56 if (wsdlTestDir == null) { 57 wsdlTestDir = TestUtil.getTempDir("wsdltest"); 58 } 59 return wsdlTestDir; 60 } 61 public File getResourceFile() throws Exception { 62 return new File (getSchemaTestTempDir(), TestUtil.getFileName(getResourcePath())); 63 } 64 public void refreshResourceFile() throws Exception { 65 if (getResourceFile().exists()) { 66 ModelSource source = TestCatalogModel.getDefault().getModelSource(getLocationURI()); 67 DataObject dobj = (DataObject) source.getLookup().lookup(DataObject.class); 68 SaveCookie save = (SaveCookie) dobj.getCookie(SaveCookie.class); 69 if (save != null) save.save(); 70 FileObject fo = (FileObject) source.getLookup().lookup(FileObject.class); 71 fo.delete(); 72 } 73 TestUtil.copyResource(getResourcePath(), FileUtil.toFileObject(getSchemaTestTempDir().getCanonicalFile())); 74 } 75 public URI getResourceURI() throws Exception { 76 return getResourceFile().toURI(); 77 } 78 public static NamespaceLocation valueFromResourcePath(String resourcePath) { 79 for (NamespaceLocation nl : values()) { 80 if (nl.getResourcePath().equals(resourcePath)) { 81 return nl; 82 } 83 } 84 return null; 85 } 86 } 87 | Popular Tags |