KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > NamespaceLocation


1 package org.netbeans.modules.xml.schema.model;
2
3 import java.io.File JavaDoc;
4 import java.net.URI JavaDoc;
5 import java.net.URISyntaxException JavaDoc;
6 import org.openide.filesystems.FileUtil;
7
8 /**
9  *
10  * @author nn136682
11  */

12 public enum NamespaceLocation {
13     OTA("http://www.opentravel.org/OTA/2003/05", "resources/J1_TravelItinerary.xsd"),
14     ORGCHART("http://www.xmlspy.com/schemas/orgchart", "resources/OrgChart.xsd"),
15     IPO("http://www.altova.com/IPO", "resources/ipo.xsd"),
16     CUTPASTE("resources/CutPasteTest_before.xsd"),
17     EXPREPORT("resources/ExpReport.xsd"),
18     KEYREF("namespace1", "resources/KeyRef.xsd"),
19     TEST_INCLUDE("http://www.example.com/testInclude", "resources/testInclude.xsd"),
20     SOMEFILE("http://www.example.com/testInclude", "resources/somefile.xsd"),
21     TEST_LENGTH("resources/testLength.xsd"),
22     TEST_LIST("resources/testList.xsd"),
23     TEST_BAD("resources/testBad.xsd"),
24     LOANAPP("resources/loanApplication.xsd"),
25     ADDRESS("resources/address.xsd"),
26     REORDER_TEST("resources/ReorderTest.xsd"),
27     SYNCTEST_PO("resources/PurchaseOrderSyncTest.xsd"),
28     SYNCTEST_GLOBAL("resources/SyncTestGlobal_before.xsd"),
29     SYNCTEST_NONGLOBAL("resources/SyncTestNonGlobal_before.xsd"),
30     PO("http://www.example.com/PO1", "resources/PurchaseOrder.xsd");
31
32     private String JavaDoc namespace;
33     private String JavaDoc resourcePath;
34     private String JavaDoc location;
35     
36     /** Creates a new instance of NamespaceLocation */
37     NamespaceLocation(String JavaDoc location) {
38         this("http://www.example.com/" +nameFromLocation(location), location);
39     }
40     
41     NamespaceLocation(String JavaDoc namespace, String JavaDoc resourcePath) {
42         this.namespace = namespace;
43         this.resourcePath = resourcePath;
44         this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10);
45     }
46     
47     private static String JavaDoc nameFromLocation(String JavaDoc loc) {
48          File JavaDoc f = new File JavaDoc(loc);
49          String JavaDoc name = f.getName();
50          return name.substring(0, name.length()-4);
51     }
52     
53     public String JavaDoc getNamespace() { return namespace; }
54     public String JavaDoc getResourcePath() { return resourcePath; }
55     public String JavaDoc getLocationString() { return location; }
56     public URI JavaDoc getNamespaceURI() throws URISyntaxException JavaDoc { return new URI JavaDoc(getNamespace()); }
57     public static File JavaDoc schemaTestDir = null;
58     public static File JavaDoc getSchemaTestTempDir() throws Exception JavaDoc {
59         if (schemaTestDir == null) {
60             schemaTestDir = Util.getTempDir("schematest");
61         }
62         return schemaTestDir;
63     }
64     public File JavaDoc getResourceFile() throws Exception JavaDoc {
65         return new File JavaDoc(getSchemaTestTempDir(), Util.getFileName(getResourcePath()));
66     }
67     public void refreshResourceFile() throws Exception JavaDoc {
68         Util.copyResource(getResourcePath(), FileUtil.toFileObject(getSchemaTestTempDir().getCanonicalFile()));
69     }
70     public URI JavaDoc getResourceURI() throws Exception JavaDoc {
71         return getResourceFile().toURI();
72     }
73     public URI JavaDoc getLocationURI() throws Exception JavaDoc { return new URI JavaDoc(location); }
74     
75     public static NamespaceLocation valueFromResourcePath(String JavaDoc resourcePath) {
76         for (NamespaceLocation nl : values()) {
77             if (nl.getResourcePath().equals(resourcePath)) {
78                 return nl;
79             }
80         }
81         return null;
82     }
83 }
84
Popular Tags