KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > query > Element


1 /*
2   (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: Element.java,v 1.7 2005/02/21 11:52:15 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.graph.query;
8
9 import com.hp.hpl.jena.graph.*;
10
11 /**
12     An Element of a matching triple. Elements have associated indexes, their place
13     in the Domain storing the matching values. Subclasses represent constants,
14     binding occurances of variables, and bound instances of variables.
15     
16     @author hedgehog
17 */

18
19 public abstract class Element
20     {
21     protected int index;
22     
23     /**
24         Answer this Element's index in the Domains it is compiled for.
25     */

26     public int getIndex()
27         { return index; }
28         
29     /**
30         Initialise this Element with its allocated index.
31     */

32     protected Element( int index )
33         { this.index = index; }
34         
35     /**
36         Initialiser invoked by sub-classes which need no index.
37     */

38     protected Element()
39         { this( -1 ); }
40         
41     /**
42         The constant ANY matches anything and binds nothing
43     */

44     public static final Element ANY = new Element()
45         {
46         public boolean match( Domain d, Node n ) { return true; }
47         public Node asNodeMatch( Domain d ) { return Node.ANY; }
48         public String JavaDoc toString() { return "<any>"; }
49         };
50         
51     /**
52         Answer true if this Element matches x given the bindings in d. May side-effect d
53         by (re)binding if this element is a variable.
54         @param d the variable bindings to read/update for variables
55         @param x the value to match
56         @return true if the match succeeded
57     */

58     public abstract boolean match( Domain d, Node x );
59         
60     /**
61         Answer a Node suitable as a pattern-match element in a TripleMatch approximating
62         this Element. Thus Bind elements map to null (or Node.ANY).
63         @param d the domain holding the variable bindings
64         @return the matched value (null if none, ie binding occurance or ANY)
65     */

66     public abstract Node asNodeMatch( Domain d );
67         
68     public String JavaDoc toString()
69         { return "<" + this.getClass() + " element>"; }
70     }
71
72 /*
73     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
74     All rights reserved.
75
76     Redistribution and use in source and binary forms, with or without
77     modification, are permitted provided that the following conditions
78     are met:
79
80     1. Redistributions of source code must retain the above copyright
81        notice, this list of conditions and the following disclaimer.
82
83     2. Redistributions in binary form must reproduce the above copyright
84        notice, this list of conditions and the following disclaimer in the
85        documentation and/or other materials provided with the distribution.
86
87     3. The name of the author may not be used to endorse or promote products
88        derived from this software without specific prior written permission.
89
90     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
91     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
92     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
93     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
94     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
95     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
96     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
97     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
98     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
99     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100 */

101
Popular Tags