KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > dig > DIGValueToNodeMapper


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email ian.dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created 04-Dec-2003
9  * Filename $RCSfile: DIGValueToNodeMapper.java,v $
10  * Revision $Revision: 1.3 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:16:24 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * [See end of file]
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.reasoner.dig;
23
24
25
26 // Imports
27
///////////////
28
import org.w3c.dom.Element JavaDoc;
29
30 import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
31 import com.hp.hpl.jena.graph.Node;
32 import com.hp.hpl.jena.rdf.model.AnonId;
33 import com.hp.hpl.jena.util.iterator.Map1;
34
35
36 /**
37  * <p>
38  * Mapper to map DIG identifier names and concrete value elements to Jena graph nodes.
39  * </p>
40  *
41  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
42  * @version CVS $Id: DIGValueToNodeMapper.java,v 1.3 2005/02/21 12:16:24 andy_seaborne Exp $
43  */

44 public class DIGValueToNodeMapper
45     implements Map1
46 {
47     // Constants
48
//////////////////////////////////
49

50     // Static variables
51
//////////////////////////////////
52

53     // Instance variables
54
//////////////////////////////////
55

56     // Constructors
57
//////////////////////////////////
58

59     // External signature methods
60
//////////////////////////////////
61

62
63     /**
64      * <p>Return the node corresponding to the given element; either a literal
65      * node for ival and sval values, or a URI node for named elements.</p>
66      * @param o An object, expected to be an XML element
67      */

68     public Object JavaDoc map1( Object JavaDoc o ) {
69         if (o instanceof Element JavaDoc) {
70             // we know that this mapper is applied to lists of Elements
71
Element JavaDoc elem = (Element JavaDoc) o;
72             
73             if (elem.getNodeName().equals( DIGProfile.IVAL )) {
74                 // this is an integer element
75
return Node.createLiteral( elem.getNodeValue(), null, XSDDatatype.XSDint );
76             }
77             else if (elem.getNodeName().equals( DIGProfile.SVAL )) {
78                 // this is an integer element
79
return Node.createLiteral( elem.getNodeValue(), null, XSDDatatype.XSDstring );
80             }
81             else if (elem.hasAttribute( DIGProfile.NAME )) {
82                 return convertNameToNode( elem.getAttribute( DIGProfile.NAME ) );
83             }
84         }
85         else if (o instanceof String JavaDoc) {
86             return convertNameToNode( (String JavaDoc) o );
87         }
88
89         throw new IllegalArgumentException JavaDoc( "Cannot map value " + o + " to an RDF node because it is not a recognised type" );
90     }
91
92
93     // Internal implementation methods
94
//////////////////////////////////
95

96     /** Answer the node with the given name. It may be the node ID of a bNode */
97     private Object JavaDoc convertNameToNode( String JavaDoc name ) {
98         if (name.startsWith( DIGAdapter.ANON_MARKER )) {
99             String JavaDoc anonID = name.substring( DIGAdapter.ANON_MARKER.length() );
100             return Node.createAnon( new AnonId( anonID ) );
101         }
102         else {
103             return Node.createURI( name );
104         }
105     }
106
107
108     //==============================================================================
109
// Inner class definitions
110
//==============================================================================
111

112 }
113
114
115 /*
116  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
117  * All rights reserved.
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  * notice, this list of conditions and the following disclaimer.
124  * 2. Redistributions in binary form must reproduce the above copyright
125  * notice, this list of conditions and the following disclaimer in the
126  * documentation and/or other materials provided with the distribution.
127  * 3. The name of the author may not be used to endorse or promote products
128  * derived from this software without specific prior written permission.
129  *
130  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
131  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
132  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
133  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
134  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
135  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
136  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
137  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
138  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
139  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
140  */

141
142
Popular Tags