1 19 20 package org.netbeans.modules.xml.wsdl.model.extensions; 21 22 import java.io.File ; 23 import java.net.URI ; 24 import java.net.URISyntaxException ; 25 import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel; 26 import org.netbeans.modules.xml.xam.ModelSource; 27 import org.openide.cookies.SaveCookie; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.loaders.DataObject; 31 32 36 public enum NamespaceLocation { 37 HOTEL("http://www.sun.com/javaone/05/HotelReservationService", "resources/HotelReservationService.wsdl"), 38 AIRLINE("http://www.sun.com/javaone/05/AirlineReservationService", "resources/AirlineReservationService.wsdl"), 39 EMPTY_TRAVEL("http://www.sun.com/javaone/05/TravelReservationService", "resources/emptyTravel.wsdl"), 40 TRAVEL("http://www.sun.com/javaone/05/TravelReservationService", "resources/TravelReservationService.wsdl"), 41 VEHICLE("http://www.sun.com/javaone/05/VehicleReservationService", "resources/VehicleReservationService.wsdl"), 42 OTA("http://www.opentravel.org/OTA/2003/05", "resources/OTA_TravelItinerary.xsd"); 43 44 private String namespace; 45 private String resourcePath; 46 private String location; 47 48 49 NamespaceLocation(String namespace, String resourcePath) { 50 this.namespace = namespace; 51 this.resourcePath = resourcePath; 52 this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10); 53 } 54 public String getNamespace() { return namespace; } 55 public String getResourcePath() { return resourcePath; } 56 public URI getLocationURI() throws URISyntaxException { 57 return new URI (getLocation()); 58 } 59 public String getLocation() { return location; } 60 public URI getNamespaceURI() throws URISyntaxException { return new URI (getNamespace()); } 61 public static File wsdlTestDir = null; 62 public static File getWsdlTestTempDir() throws Exception { 63 if (wsdlTestDir == null) { 64 wsdlTestDir = Util.getTempDir("wsdltest"); 65 } 66 return wsdlTestDir; 67 } 68 public File getResourceFile() throws Exception { 69 return new File (getWsdlTestTempDir(), Util.getFileName(getResourcePath())); 70 } 71 public void refreshResourceFile() throws Exception { 72 if (getResourceFile().exists()) { 73 ModelSource source = TestCatalogModel.getDefault().getModelSource(getLocationURI()); 74 DataObject dobj = (DataObject) source.getLookup().lookup(DataObject.class); 75 SaveCookie save = (SaveCookie) dobj.getCookie(SaveCookie.class); 76 if (save != null) save.save(); 77 FileObject fo = (FileObject) source.getLookup().lookup(FileObject.class); 79 if (fo != null) fo.delete(); 80 } 81 Util.copyResource(getResourcePath(), FileUtil.toFileObject(getWsdlTestTempDir().getCanonicalFile())); 82 } 83 public URI getResourceURI() throws Exception { 84 return getResourceFile().toURI(); 85 } 86 public static NamespaceLocation valueFromResourcePath(String resourcePath) { 87 for (NamespaceLocation nl : values()) { 88 if (nl.getResourcePath().equals(resourcePath)) { 89 return nl; 90 } 91 } 92 return null; 93 } 94 } 95 | Popular Tags |