KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > NamespaceLocation


1 package org.netbeans.modules.xml.wsdl.model;
2
3 import java.io.File JavaDoc;
4 import java.net.URI JavaDoc;
5 import java.net.URISyntaxException JavaDoc;
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 /**
13  *
14  * @author nn136682
15  */

16 public enum NamespaceLocation {
17     HOTEL("http://www.sun.com/javaone/05/HotelReservationService", "resources/HotelReservationService.wsdl"),
18     AIRLINE("http://www.sun.com/javaone/05/AirlineReservationService", "resources/AirlineReservationService.wsdl"),
19     EMPTY_TRAVEL("http://www.sun.com/javaone/05/TravelReservationService", "resources/emptyTravel.wsdl"),
20     TRAVEL("http://www.sun.com/javaone/05/TravelReservationService", "resources/TravelReservationService.wsdl"),
21     VEHICLE("http://www.sun.com/javaone/05/VehicleReservationService", "resources/VehicleReservationService.wsdl"),
22     OTA("http://www.opentravel.org/OTA/2003/05", "resources/OTA_TravelItinerary.xsd"),
23     TESTOP("test/operations", "resources/TestOperations.wsdl"),
24     TESTIMPORT("http://com.stc.database/pointbase/purchaseOrder", "resources/testImports.wsdl"),
25     PO_1("http://com.stc.database/pointbase/purchaseOrder", "resources/purchaseOrder_1.xsd"),
26     PO("http://www.w3.org/2001/XMLSchema", "resources/PurchaseOrder.xsd"),
27     SCHEMA_NS_IN_WSDL("http://new.webservice.namespace", "resources/schemaUsingNamespaceFromWsdlRoot.wsdl"),
28     ECHO("http://localhost/echo/echo", "resources/echo.wsdl"),
29     ECHOCONCAT("http://stc.com/echoConcat", "resources/echoConcat.wsdl"),
30     PARKING("urn:ParkingLotManager/wsdl", "resources/ParkingLotManager.wsdl");
31     
32     private String JavaDoc namespace;
33     private String JavaDoc resourcePath;
34     private String JavaDoc location;
35     
36     /** Creates a new instance of NamespaceLocation */
37     NamespaceLocation(String JavaDoc namespace, String JavaDoc resourcePath) {
38         this.namespace = namespace;
39         this.resourcePath = resourcePath;
40         this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10);
41     }
42     public String JavaDoc getNamespace() { return namespace; }
43     public String JavaDoc getResourcePath() { return resourcePath; }
44     public URI JavaDoc getLocationURI() throws URISyntaxException JavaDoc {
45         return new URI JavaDoc(getLocation());
46     }
47     public String JavaDoc getLocation() { return location; }
48     public URI JavaDoc getNamespaceURI() throws URISyntaxException JavaDoc { return new URI JavaDoc(getNamespace()); }
49     public static File JavaDoc wsdlTestDir = null;
50     public static File JavaDoc getSchemaTestTempDir() throws Exception JavaDoc {
51         if (wsdlTestDir == null) {
52             wsdlTestDir = Util.getTempDir("wsdltest");
53         }
54         return wsdlTestDir;
55     }
56     public File JavaDoc getResourceFile() throws Exception JavaDoc {
57         return new File JavaDoc(getSchemaTestTempDir(), Util.getFileName(getResourcePath()));
58     }
59     public void refreshResourceFile() throws Exception JavaDoc {
60         if (getResourceFile().exists()) {
61             ModelSource source = TestCatalogModel.getDefault().getModelSource(getLocationURI());
62             DataObject dobj = (DataObject) source.getLookup().lookup(DataObject.class);
63             SaveCookie save = (SaveCookie) dobj.getCookie(SaveCookie.class);
64             if (save != null) save.save();
65             FileObject fo = (FileObject) source.getLookup().lookup(FileObject.class);
66             fo.delete();
67         }
68         Util.copyResource(getResourcePath(), FileUtil.toFileObject(getSchemaTestTempDir().getCanonicalFile()));
69     }
70     public URI JavaDoc getResourceURI() throws Exception JavaDoc {
71         return getResourceFile().toURI();
72     }
73     public static NamespaceLocation valueFromResourcePath(String JavaDoc resourcePath) {
74         for (NamespaceLocation nl : values()) {
75             if (nl.getResourcePath().equals(resourcePath)) {
76                 return nl;
77             }
78         }
79         return null;
80     }
81 }
82
Popular Tags