KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > 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.model.extensions;
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.wsdl.model.extensions.TestCatalogModel;
26 import org.netbeans.modules.xml.xam.ModelSource;
27 import org.openide.cookies.SaveCookie;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.loaders.DataObject;
31
32 /**
33  *
34  * @author nn136682
35  */

36 public enum NamespaceLocation {
37     HOTEL("http://www.sun.com/javaone/05/HotelReservationService", "resources/HotelReservationService.wsdl"),
38     AIRLINE("http://www.sun.com/javaone/05/AirlineReservationService", "resources/AirlineReservationService.wsdl"),
39     EMPTY_TRAVEL("http://www.sun.com/javaone/05/TravelReservationService", "resources/emptyTravel.wsdl"),
40     TRAVEL("http://www.sun.com/javaone/05/TravelReservationService", "resources/TravelReservationService.wsdl"),
41     VEHICLE("http://www.sun.com/javaone/05/VehicleReservationService", "resources/VehicleReservationService.wsdl"),
42     OTA("http://www.opentravel.org/OTA/2003/05", "resources/OTA_TravelItinerary.xsd");
43     
44     private String JavaDoc namespace;
45     private String JavaDoc resourcePath;
46     private String JavaDoc location;
47     
48     /** Creates a new instance of NamespaceLocation */
49     NamespaceLocation(String JavaDoc namespace, String JavaDoc resourcePath) {
50         this.namespace = namespace;
51         this.resourcePath = resourcePath;
52         this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10);
53     }
54     public String JavaDoc getNamespace() { return namespace; }
55     public String JavaDoc getResourcePath() { return resourcePath; }
56     public URI JavaDoc getLocationURI() throws URISyntaxException JavaDoc {
57         return new URI JavaDoc(getLocation());
58     }
59     public String JavaDoc getLocation() { return location; }
60     public URI JavaDoc getNamespaceURI() throws URISyntaxException JavaDoc { return new URI JavaDoc(getNamespace()); }
61     public static File JavaDoc wsdlTestDir = null;
62     public static File JavaDoc getWsdlTestTempDir() throws Exception JavaDoc {
63         if (wsdlTestDir == null) {
64             wsdlTestDir = Util.getTempDir("wsdltest");
65         }
66         return wsdlTestDir;
67     }
68     public File JavaDoc getResourceFile() throws Exception JavaDoc {
69         return new File JavaDoc(getWsdlTestTempDir(), Util.getFileName(getResourcePath()));
70     }
71     public void refreshResourceFile() throws Exception JavaDoc {
72         if (getResourceFile().exists()) {
73             ModelSource source = TestCatalogModel.getDefault().getModelSource(getLocationURI());
74             DataObject dobj = (DataObject) source.getLookup().lookup(DataObject.class);
75             SaveCookie save = (SaveCookie) dobj.getCookie(SaveCookie.class);
76             if (save != null) save.save();
77             //Thread.sleep(2000);
78
FileObject fo = (FileObject) source.getLookup().lookup(FileObject.class);
79             if (fo != null) fo.delete();
80         }
81         Util.copyResource(getResourcePath(), FileUtil.toFileObject(getWsdlTestTempDir().getCanonicalFile()));
82     }
83     public URI JavaDoc getResourceURI() throws Exception JavaDoc {
84         return getResourceFile().toURI();
85     }
86     public static NamespaceLocation valueFromResourcePath(String JavaDoc resourcePath) {
87         for (NamespaceLocation nl : values()) {
88             if (nl.getResourcePath().equals(resourcePath)) {
89                 return nl;
90             }
91         }
92         return null;
93     }
94 }
95
Popular Tags