01: package org.netbeans.modules.iep.model.common;
02:
03: import java.io.File;
04: import java.net.URI;
05: import java.net.URISyntaxException;
06: import org.netbeans.modules.xml.xam.ModelSource;
07: import org.openide.cookies.SaveCookie;
08: import org.openide.filesystems.FileObject;
09: import org.openide.filesystems.FileUtil;
10: import org.openide.loaders.DataObject;
11:
12: /**
13: *
14: * @author nn136682
15: */
16: public enum NamespaceLocation {
17: PURCHASE_ORDER(
18: "http://jbi.com.sun/wfse/wsdl/WorkflowApp2/ApprovePurchase_TM_BPEL",
19: "data/ApprovePurchase_TM_BPEL.wsdl");
20:
21: private String namespace;
22: private String resourcePath;
23: private String location;
24:
25: /** Creates a new instance of NamespaceLocation */
26: NamespaceLocation(String namespace, String resourcePath) {
27: this .namespace = namespace;
28: this .resourcePath = resourcePath;
29: this .location = resourcePath.substring(resourcePath
30: .lastIndexOf("resources/") + 10);
31: }
32:
33: public String getNamespace() {
34: return namespace;
35: }
36:
37: public String getResourcePath() {
38: return resourcePath;
39: }
40:
41: public URI getLocationURI() throws URISyntaxException {
42: return new URI(getLocation());
43: }
44:
45: public String getLocation() {
46: return location;
47: }
48:
49: public URI getNamespaceURI() throws URISyntaxException {
50: return new URI(getNamespace());
51: }
52:
53: public static File wsdlTestDir = null;
54:
55: public static File getSchemaTestTempDir() throws Exception {
56: if (wsdlTestDir == null) {
57: wsdlTestDir = Util.getTempDir("wsdltest");
58: }
59: return wsdlTestDir;
60: }
61:
62: public File getResourceFile() throws Exception {
63: return new File(getSchemaTestTempDir(), Util
64: .getFileName(getResourcePath()));
65: }
66:
67: public void refreshResourceFile() throws Exception {
68: if (getResourceFile().exists()) {
69: ModelSource source = TestCatalogModel.getDefault()
70: .getModelSource(getLocationURI());
71: DataObject dobj = (DataObject) source.getLookup().lookup(
72: DataObject.class);
73: SaveCookie save = (SaveCookie) dobj
74: .getCookie(SaveCookie.class);
75: if (save != null)
76: save.save();
77: FileObject fo = (FileObject) source.getLookup().lookup(
78: FileObject.class);
79: fo.delete();
80: }
81: Util.copyResource(getResourcePath(),
82: FileUtil.toFileObject(getSchemaTestTempDir()
83: .getCanonicalFile()));
84: }
85:
86: public URI getResourceURI() throws Exception {
87: return getResourceFile().toURI();
88: }
89:
90: public static NamespaceLocation valueFromResourcePath(
91: String resourcePath) {
92: for (NamespaceLocation nl : values()) {
93: if (nl.getResourcePath().equals(resourcePath)) {
94: return nl;
95: }
96: }
97: return null;
98: }
99: }
|