001: package org.netbeans.modules.xml.wsdl.model;
002:
003: import java.io.File;
004: import java.net.URI;
005: import java.net.URISyntaxException;
006: import org.netbeans.modules.xml.xam.ModelSource;
007: import org.openide.cookies.SaveCookie;
008: import org.openide.filesystems.FileObject;
009: import org.openide.filesystems.FileUtil;
010: import org.openide.loaders.DataObject;
011:
012: /**
013: *
014: * @author nn136682
015: */
016: public enum NamespaceLocation {
017: HOTEL("http://www.sun.com/javaone/05/HotelReservationService",
018: "resources/HotelReservationService.wsdl"), AIRLINE(
019: "http://www.sun.com/javaone/05/AirlineReservationService",
020: "resources/AirlineReservationService.wsdl"), EMPTY_TRAVEL(
021: "http://www.sun.com/javaone/05/TravelReservationService",
022: "resources/emptyTravel.wsdl"), TRAVEL(
023: "http://www.sun.com/javaone/05/TravelReservationService",
024: "resources/TravelReservationService.wsdl"), VEHICLE(
025: "http://www.sun.com/javaone/05/VehicleReservationService",
026: "resources/VehicleReservationService.wsdl"), OTA(
027: "http://www.opentravel.org/OTA/2003/05",
028: "resources/OTA_TravelItinerary.xsd"), TESTOP(
029: "test/operations", "resources/TestOperations.wsdl"), TESTIMPORT(
030: "http://com.stc.database/pointbase/purchaseOrder",
031: "resources/testImports.wsdl"), PO_1(
032: "http://com.stc.database/pointbase/purchaseOrder",
033: "resources/purchaseOrder_1.xsd"), PO(
034: "http://www.w3.org/2001/XMLSchema",
035: "resources/PurchaseOrder.xsd"), SCHEMA_NS_IN_WSDL(
036: "http://new.webservice.namespace",
037: "resources/schemaUsingNamespaceFromWsdlRoot.wsdl"), ECHO(
038: "http://localhost/echo/echo", "resources/echo.wsdl"), ECHOCONCAT(
039: "http://stc.com/echoConcat", "resources/echoConcat.wsdl"), PARKING(
040: "urn:ParkingLotManager/wsdl",
041: "resources/ParkingLotManager.wsdl");
042:
043: private String namespace;
044: private String resourcePath;
045: private String location;
046:
047: /** Creates a new instance of NamespaceLocation */
048: NamespaceLocation(String namespace, String resourcePath) {
049: this .namespace = namespace;
050: this .resourcePath = resourcePath;
051: this .location = resourcePath.substring(resourcePath
052: .lastIndexOf("resources/") + 10);
053: }
054:
055: public String getNamespace() {
056: return namespace;
057: }
058:
059: public String getResourcePath() {
060: return resourcePath;
061: }
062:
063: public URI getLocationURI() throws URISyntaxException {
064: return new URI(getLocation());
065: }
066:
067: public String getLocation() {
068: return location;
069: }
070:
071: public URI getNamespaceURI() throws URISyntaxException {
072: return new URI(getNamespace());
073: }
074:
075: public static File wsdlTestDir = null;
076:
077: public static File getSchemaTestTempDir() throws Exception {
078: if (wsdlTestDir == null) {
079: wsdlTestDir = Util.getTempDir("wsdltest");
080: }
081: return wsdlTestDir;
082: }
083:
084: public File getResourceFile() throws Exception {
085: return new File(getSchemaTestTempDir(), Util
086: .getFileName(getResourcePath()));
087: }
088:
089: public void refreshResourceFile() throws Exception {
090: if (getResourceFile().exists()) {
091: ModelSource source = TestCatalogModel.getDefault()
092: .getModelSource(getLocationURI());
093: DataObject dobj = (DataObject) source.getLookup().lookup(
094: DataObject.class);
095: SaveCookie save = (SaveCookie) dobj
096: .getCookie(SaveCookie.class);
097: if (save != null)
098: save.save();
099: FileObject fo = (FileObject) source.getLookup().lookup(
100: FileObject.class);
101: fo.delete();
102: }
103: Util.copyResource(getResourcePath(),
104: FileUtil.toFileObject(getSchemaTestTempDir()
105: .getCanonicalFile()));
106: }
107:
108: public URI getResourceURI() throws Exception {
109: return getResourceFile().toURI();
110: }
111:
112: public static NamespaceLocation valueFromResourcePath(
113: String resourcePath) {
114: for (NamespaceLocation nl : values()) {
115: if (nl.getResourcePath().equals(resourcePath)) {
116: return nl;
117: }
118: }
119: return null;
120: }
121: }
|