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