001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.wsdlextensions.ftp.validation.test;
021:
022: import java.io.File;
023: import java.net.URI;
024: import java.net.URISyntaxException;
025: import org.netbeans.modules.xml.xam.ModelSource;
026: import org.openide.cookies.SaveCookie;
027: import org.openide.filesystems.FileObject;
028: import org.openide.filesystems.FileUtil;
029: import org.openide.loaders.DataObject;
030:
031: public enum NamespaceLocation {
032: HOTEL("http://www.sun.com/javaone/05/HotelReservationService",
033: "resources/HotelReservationService.wsdl"), AIRLINE(
034: "http://www.sun.com/javaone/05/AirlineReservationService",
035: "resources/AirlineReservationService.wsdl"), EMPTY_TRAVEL(
036: "http://www.sun.com/javaone/05/TravelReservationService",
037: "resources/emptyTravel.wsdl"), TRAVEL(
038: "http://www.sun.com/javaone/05/TravelReservationService",
039: "resources/TravelReservationService.wsdl"), VEHICLE(
040: "http://www.sun.com/javaone/05/VehicleReservationService",
041: "resources/VehicleReservationService.wsdl"), OTA(
042: "http://www.opentravel.org/OTA/2003/05",
043: "resources/OTA_TravelItinerary.xsd"), TESTOP(
044: "test/operations", "resources/TestOperations.wsdl"), TESTIMPORT(
045: "http://com.stc.database/pointbase/purchaseOrder",
046: "resources/testImports.wsdl"), PO_1(
047: "http://com.stc.database/pointbase/purchaseOrder",
048: "resources/purchaseOrder_1.xsd"), PO(
049: "http://www.w3.org/2001/XMLSchema",
050: "resources/PurchaseOrder.xsd"), SCHEMA_NS_IN_WSDL(
051: "http://new.webservice.namespace",
052: "resources/schemaUsingNamespaceFromWsdlRoot.wsdl"), ECHO(
053: "http://localhost/echo/echo", "resources/echo.wsdl"), ECHOCONCAT(
054: "http://stc.com/echoConcat", "resources/echoConcat.wsdl"), PARKING(
055: "urn:ParkingLotManager/wsdl",
056: "resources/ParkingLotManager.wsdl");
057:
058: private String namespace;
059: private String resourcePath;
060: private String location;
061:
062: /** Creates a new instance of NamespaceLocation */
063: NamespaceLocation(String namespace, String resourcePath) {
064: this .namespace = namespace;
065: this .resourcePath = resourcePath;
066: this .location = resourcePath.substring(resourcePath
067: .lastIndexOf("resources/") + 10);
068: }
069:
070: public String getNamespace() {
071: return namespace;
072: }
073:
074: public String getResourcePath() {
075: return resourcePath;
076: }
077:
078: public URI getLocationURI() throws URISyntaxException {
079: return new URI(getLocation());
080: }
081:
082: public String getLocation() {
083: return location;
084: }
085:
086: public URI getNamespaceURI() throws URISyntaxException {
087: return new URI(getNamespace());
088: }
089:
090: public static File wsdlTestDir = null;
091:
092: public static File getSchemaTestTempDir() throws Exception {
093: if (wsdlTestDir == null) {
094: wsdlTestDir = Util.getTempDir("wsdltest");
095: }
096: return wsdlTestDir;
097: }
098:
099: public File getResourceFile() throws Exception {
100: return new File(getSchemaTestTempDir(), Util
101: .getFileName(getResourcePath()));
102: }
103:
104: public void refreshResourceFile() throws Exception {
105: if (getResourceFile().exists()) {
106: ModelSource source = TestCatalogModel.getDefault()
107: .getModelSource(getLocationURI());
108: DataObject dobj = (DataObject) source.getLookup().lookup(
109: DataObject.class);
110: SaveCookie save = (SaveCookie) dobj
111: .getCookie(SaveCookie.class);
112: if (save != null)
113: save.save();
114: FileObject fo = (FileObject) source.getLookup().lookup(
115: FileObject.class);
116: fo.delete();
117: }
118: Util.copyResource(getResourcePath(),
119: FileUtil.toFileObject(getSchemaTestTempDir()
120: .getCanonicalFile()));
121: }
122:
123: public URI getResourceURI() throws Exception {
124: return getResourceFile().toURI();
125: }
126:
127: public static NamespaceLocation valueFromResourcePath(
128: String resourcePath) {
129: for (NamespaceLocation nl : values()) {
130: if (nl.getResourcePath().equals(resourcePath)) {
131: return nl;
132: }
133: }
134: return null;
135: }
136: }
|