KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.refactoring;
21
22 import java.io.File JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URISyntaxException JavaDoc;
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 /**
32  *
33  * @author nn136682
34  */

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 JavaDoc namespace;
44     private String JavaDoc resourcePath;
45     private String JavaDoc location;
46     
47     /** Creates a new instance of NamespaceLocation */
48     NamespaceLocation(String JavaDoc namespace, String JavaDoc resourcePath) {
49         this.namespace = namespace;
50         this.resourcePath = resourcePath;
51         this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10);
52     }
53     public String JavaDoc getNamespace() { return namespace; }
54     public String JavaDoc getResourcePath() { return resourcePath; }
55     public URI JavaDoc getLocationURI() throws URISyntaxException JavaDoc {
56         return new URI JavaDoc(getLocation());
57     }
58     public String JavaDoc getLocation() { return location; }
59     public URI JavaDoc getNamespaceURI() throws URISyntaxException JavaDoc { return new URI JavaDoc(getNamespace()); }
60     public static File JavaDoc wsdlTestDir = null;
61     public static File JavaDoc getWsdlTestTempDir() throws Exception JavaDoc {
62         if (wsdlTestDir == null) {
63             wsdlTestDir = Util.getTempDir("wsdltest");
64         }
65         return wsdlTestDir;
66     }
67     public File JavaDoc getResourceFile() throws Exception JavaDoc {
68         return new File JavaDoc(getWsdlTestTempDir(), Util.getFileName(getResourcePath()));
69     }
70     public void refreshResourceFile() throws Exception JavaDoc {
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             //Thread.sleep(2000);
77
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 JavaDoc getResourceURI() throws Exception JavaDoc {
83         return getResourceFile().toURI();
84     }
85     public static NamespaceLocation valueFromResourcePath(String JavaDoc 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