KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > util > 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 package org.netbeans.modules.websvc.wsitconf.util;
20
21 import java.io.File JavaDoc;
22 import java.net.URI JavaDoc;
23 import java.net.URISyntaxException JavaDoc;
24 import org.netbeans.modules.xml.xam.ModelSource;
25 import org.openide.cookies.SaveCookie;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileUtil;
28 import org.openide.loaders.DataObject;
29
30 /**
31  *
32  * @author nn136682
33  */

34 public enum NamespaceLocation {
35     POLICY("http://policy/sss", "policysss.xml");
36     
37     private String JavaDoc namespace;
38     private String JavaDoc resourcePath;
39     private String JavaDoc location;
40     
41     /** Creates a new instance of NamespaceLocation */
42     NamespaceLocation(String JavaDoc namespace, String JavaDoc resourcePath) {
43         this.namespace = namespace;
44         this.resourcePath = resourcePath;
45         this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10);
46     }
47     public String JavaDoc getNamespace() { return namespace; }
48     public String JavaDoc getResourcePath() { return resourcePath; }
49     public URI JavaDoc getLocationURI() throws URISyntaxException JavaDoc {
50         return new URI JavaDoc(getLocation());
51     }
52     public String JavaDoc getLocation() { return location; }
53     public URI JavaDoc getNamespaceURI() throws URISyntaxException JavaDoc { return new URI JavaDoc(getNamespace()); }
54     public static File JavaDoc wsdlTestDir = null;
55     public static File JavaDoc getSchemaTestTempDir() throws Exception JavaDoc {
56         if (wsdlTestDir == null) {
57             wsdlTestDir = TestUtil.getTempDir("wsdltest");
58         }
59         return wsdlTestDir;
60     }
61     public File JavaDoc getResourceFile() throws Exception JavaDoc {
62         return new File JavaDoc(getSchemaTestTempDir(), TestUtil.getFileName(getResourcePath()));
63     }
64     public void refreshResourceFile() throws Exception JavaDoc {
65         if (getResourceFile().exists()) {
66             ModelSource source = TestCatalogModel.getDefault().getModelSource(getLocationURI());
67             DataObject dobj = (DataObject) source.getLookup().lookup(DataObject.class);
68             SaveCookie save = (SaveCookie) dobj.getCookie(SaveCookie.class);
69             if (save != null) save.save();
70             FileObject fo = (FileObject) source.getLookup().lookup(FileObject.class);
71             fo.delete();
72         }
73         TestUtil.copyResource(getResourcePath(), FileUtil.toFileObject(getSchemaTestTempDir().getCanonicalFile()));
74     }
75     public URI JavaDoc getResourceURI() throws Exception JavaDoc {
76         return getResourceFile().toURI();
77     }
78     public static NamespaceLocation valueFromResourcePath(String JavaDoc resourcePath) {
79         for (NamespaceLocation nl : values()) {
80             if (nl.getResourcePath().equals(resourcePath)) {
81                 return nl;
82             }
83         }
84         return null;
85     }
86 }
87
Popular Tags