KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitmodelext > util > NamespaceLocation


1 package org.netbeans.modules.websvc.wsitmodelext.util;
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     POLICY("http://policy/", "../wsdlmodelext/resources/policy.xml")/*,
18     PARKING("urn:ParkingLotManager/wsdl", "resources/ParkingLotManager.wsdl")*/
;
19     
20     private String JavaDoc namespace;
21     private String JavaDoc resourcePath;
22     private String JavaDoc location;
23     
24     /** Creates a new instance of NamespaceLocation */
25     NamespaceLocation(String JavaDoc namespace, String JavaDoc resourcePath) {
26         this.namespace = namespace;
27         this.resourcePath = resourcePath;
28         this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10);
29     }
30     public String JavaDoc getNamespace() { return namespace; }
31     public String JavaDoc getResourcePath() { return resourcePath; }
32     public URI JavaDoc getLocationURI() throws URISyntaxException JavaDoc {
33         return new URI JavaDoc(getLocation());
34     }
35     public String JavaDoc getLocation() { return location; }
36     public URI JavaDoc getNamespaceURI() throws URISyntaxException JavaDoc { return new URI JavaDoc(getNamespace()); }
37     public static File JavaDoc wsdlTestDir = null;
38     public static File JavaDoc getSchemaTestTempDir() throws Exception JavaDoc {
39         if (wsdlTestDir == null) {
40             wsdlTestDir = Util.getTempDir("wsdltest");
41         }
42         return wsdlTestDir;
43     }
44     public File JavaDoc getResourceFile() throws Exception JavaDoc {
45         return new File JavaDoc(getSchemaTestTempDir(), Util.getFileName(getResourcePath()));
46     }
47     public void refreshResourceFile() throws Exception JavaDoc {
48         if (getResourceFile().exists()) {
49             ModelSource source = TestCatalogModel.getDefault().getModelSource(getLocationURI());
50             DataObject dobj = (DataObject) source.getLookup().lookup(DataObject.class);
51             SaveCookie save = (SaveCookie) dobj.getCookie(SaveCookie.class);
52             if (save != null) save.save();
53             FileObject fo = (FileObject) source.getLookup().lookup(FileObject.class);
54             fo.delete();
55         }
56         Util.copyResource(getResourcePath(), FileUtil.toFileObject(getSchemaTestTempDir().getCanonicalFile()));
57     }
58     public URI JavaDoc getResourceURI() throws Exception JavaDoc {
59         return getResourceFile().toURI();
60     }
61     public static NamespaceLocation valueFromResourcePath(String JavaDoc resourcePath) {
62         for (NamespaceLocation nl : values()) {
63             if (nl.getResourcePath().equals(resourcePath)) {
64                 return nl;
65             }
66         }
67         return null;
68     }
69 }
70
Popular Tags