1 package org.netbeans.modules.websvc.wsitmodelext.util; 2 3 import java.io.File ; 4 import java.net.URI ; 5 import java.net.URISyntaxException ; 6 import org.netbeans.modules.xml.xam.ModelSource; 7 import org.openide.cookies.SaveCookie; 8 import org.openide.filesystems.FileObject; 9 import org.openide.filesystems.FileUtil; 10 import org.openide.loaders.DataObject; 11 12 16 public enum NamespaceLocation { 17 POLICY("http://policy/", "../wsdlmodelext/resources/policy.xml"); 19 20 private String namespace; 21 private String resourcePath; 22 private String location; 23 24 25 NamespaceLocation(String namespace, String resourcePath) { 26 this.namespace = namespace; 27 this.resourcePath = resourcePath; 28 this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10); 29 } 30 public String getNamespace() { return namespace; } 31 public String getResourcePath() { return resourcePath; } 32 public URI getLocationURI() throws URISyntaxException { 33 return new URI (getLocation()); 34 } 35 public String getLocation() { return location; } 36 public URI getNamespaceURI() throws URISyntaxException { return new URI (getNamespace()); } 37 public static File wsdlTestDir = null; 38 public static File getSchemaTestTempDir() throws Exception { 39 if (wsdlTestDir == null) { 40 wsdlTestDir = Util.getTempDir("wsdltest"); 41 } 42 return wsdlTestDir; 43 } 44 public File getResourceFile() throws Exception { 45 return new File (getSchemaTestTempDir(), Util.getFileName(getResourcePath())); 46 } 47 public void refreshResourceFile() throws Exception { 48 if (getResourceFile().exists()) { 49 ModelSource source = TestCatalogModel.getDefault().getModelSource(getLocationURI()); 50 DataObject dobj = (DataObject) source.getLookup().lookup(DataObject.class); 51 SaveCookie save = (SaveCookie) dobj.getCookie(SaveCookie.class); 52 if (save != null) save.save(); 53 FileObject fo = (FileObject) source.getLookup().lookup(FileObject.class); 54 fo.delete(); 55 } 56 Util.copyResource(getResourcePath(), FileUtil.toFileObject(getSchemaTestTempDir().getCanonicalFile())); 57 } 58 public URI getResourceURI() throws Exception { 59 return getResourceFile().toURI(); 60 } 61 public static NamespaceLocation valueFromResourcePath(String resourcePath) { 62 for (NamespaceLocation nl : values()) { 63 if (nl.getResourcePath().equals(resourcePath)) { 64 return nl; 65 } 66 } 67 return null; 68 } 69 } 70 | Popular Tags |