001: /*
002: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: Free.java,v 1.8 2008/01/02 12:08:23 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.db.impl;
008:
009: import com.hp.hpl.jena.graph.*;
010: import com.hp.hpl.jena.graph.query.Domain;
011: import com.hp.hpl.jena.graph.query.Element;
012: import com.hp.hpl.jena.shared.JenaException;
013:
014: /**
015: A binding instance of a variable. It accepts any node and records it in the supplied
016: Domain at the index allocated to it when it is created.
017:
018: @author hedgehog
019: */
020: public class Free extends Element {
021:
022: /**
023: Track a (free) variable element: it will later be bound during compilation.
024: */
025:
026: private Node_Variable var;
027: private int listIx; // index of variable in varList.
028: private int mapIx; // index of (arg) variable in Mapping
029: private boolean isListed; // true when variable is in varList
030: private boolean isArgument; // true when variable can be bound by an argument
031:
032: public Free(Node n) {
033: super ();
034: var = (Node_Variable) n;
035: isArgument = false;
036: isListed = false;
037: }
038:
039: public int getListing() {
040: if (isListed)
041: return listIx;
042: else
043: throw new JenaException("UnListed variable");
044: }
045:
046: public void setListing(int ix) {
047: if (isListed)
048: throw new JenaException("Relisting of variable");
049: isListed = true;
050: listIx = ix;
051: }
052:
053: public void setIsArg(int ix) {
054: isArgument = true;
055: mapIx = ix;
056: }
057:
058: public boolean isArg() {
059: return isArgument;
060: }
061:
062: public int getMapping() {
063: if (isArgument)
064: return mapIx;
065: else
066: throw new JenaException("Unmapped variable");
067: }
068:
069: public boolean isListed() {
070: return isListed;
071: }
072:
073: public Node_Variable var() {
074: return var;
075: }
076:
077: public boolean match(Domain d, Node x) {
078: throw new JenaException("Attempt to match a free variable");
079: }
080:
081: public Node asNodeMatch(Domain d) {
082: throw new JenaException("asNodeMatch not supported");
083: }
084:
085: public String toString() {
086: return "<Free " + listIx + ">";
087: }
088: }
089:
090: /*
091: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
092: All rights reserved.
093:
094: Redistribution and use in source and binary forms, with or without
095: modification, are permitted provided that the following conditions
096: are met:
097:
098: 1. Redistributions of source code must retain the above copyright
099: notice, this list of conditions and the following disclaimer.
100:
101: 2. Redistributions in binary form must reproduce the above copyright
102: notice, this list of conditions and the following disclaimer in the
103: documentation and/or other materials provided with the distribution.
104:
105: 3. The name of the author may not be used to endorse or promote products
106: derived from this software without specific prior written permission.
107:
108: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
109: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
110: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
111: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
112: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
113: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
114: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
115: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
116: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
117: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118: */
|