KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xam > ui > 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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.xam.ui;
21
22 import java.io.File JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URISyntaxException JavaDoc;
25 import org.openide.filesystems.FileUtil;
26
27 /**
28  *
29  * @author nn136682
30  */

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