KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > ARPQname


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  
27  * * $Id: ARPQname.java,v 1.6 2005/02/21 12:08:58 andy_seaborne Exp $
28    
29    AUTHOR: Jeremy J. Carroll
30 */

31 /*
32  * ARPQname.java
33  *
34  * Created on June 25, 2001, 10:00 PM
35  */

36
37 package com.hp.hpl.jena.rdf.arp;
38
39 /**
40  *
41  * @author jjc
42  * @version
43  */

44 class ARPQname extends Token {
45     final String JavaDoc nameSpace;
46     final String JavaDoc local;
47     final String JavaDoc qName;
48     /** Creates new ARPQname */
49     ARPQname(int kind, Location where, String JavaDoc ns,String JavaDoc name,String JavaDoc q) {
50         super(kind,where);
51         qName = q;
52         nameSpace = ns;
53         local = name;
54     }
55     ARPQname(String JavaDoc ns,String JavaDoc name) {
56         super(E_OTHER,null);
57         nameSpace = ns;
58         local = name;
59         qName = null;
60     }
61     String JavaDoc prefix() {
62         int ix = qName.indexOf(':');
63         return ix==-1?"":qName.substring(0,ix);
64     }
65     URIReference asURIReference(XMLHandler arp) throws ParseException {
66         URIReference uri;
67         try {
68             uri = new URIReference(nameSpace+local);
69             /*
70             if (nameSpace.startsWith("#"))
71                 System.err.println(nameSpace+local);
72                 */

73         }
74         catch ( MalformedURIException mal ) {
75             // Distinguish between relative namespaces and other problems.
76
try {
77                 arp.documentContext.resolve(location, nameSpace+local);
78                 //new URI(arp.documentContext.getURI(),nameSpace+local);
79
// May have been relative namespace, since this is now OK.
80
// Or maybe unqualified element.
81
if ( nameSpace.length() == 0 ) {
82                   arp.parseWarning(ARPErrorNumbers.WARN_UNQUALIFIED_ELEMENT,
83                    location,
84                    "Element node must be qualified.");
85                 
86                 } else {
87                   arp.parseWarning(ARPErrorNumbers.WARN_RELATIVE_NAMESPACE_URI_DEPRECATED,
88                    location,
89                    "The use of relative URIs in namespaces has been deprecated by the World Wide Web Consortium.");
90                 }
91             }
92             catch ( MalformedURIException mal2 ) {
93                 // Was other problem
94
arp.parseWarning(ARPErrorNumbers.WARN_MALFORMED_URI,location,"Bad URI <"+nameSpace+local+"> in qname: " + mal.getMessage());
95             }
96             uri = new BadURIReference(nameSpace+local);
97         }
98         return uri;
99     }
100
101 }
102
Popular Tags