001: /*
002: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: * 1. Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * 3. The name of the author may not be used to endorse or promote products
014: * derived from this software without specific prior written permission.
015:
016: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026:
027: * * $Id: ARPResource.java,v 1.5 2008/01/02 12:09:09 andy_seaborne Exp $
028:
029: AUTHOR: Jeremy J. Carroll
030: */
031: /*
032: * ARPResource.java
033: *
034: * Created on June 25, 2001, 9:57 PM
035: */
036:
037: package com.hp.hpl.jena.rdf.arp.impl;
038:
039: /**
040: *
041: * @author jjc
042: */
043: public class ARPResource extends TaintImpl implements AResourceInternal {
044: // Constants cribbed from com.megginson.sax.rdf.RDFFilter
045: static public final boolean DEBUG = false;
046: final private XMLHandler arp;
047:
048: final String nodeID;
049:
050: static private int genIdCounter = 0;
051: final private int genId = genIdCounter++;
052: static String dummy = "http://jena.hpl.hp.com/arp/not/a/real/uri/";
053: static String nullDummy = "nullpointerexception://jena.hpl.hp.com/arp/";
054:
055: public ARPResource(XMLHandler parent) {
056: this (parent, null);
057: }
058:
059: public ARPResource(XMLHandler parent, String nid) {
060: arp = parent;
061: nodeID = nid;
062: if (DEBUG) {
063: RuntimeException rte = new RuntimeException(
064: "bnode allocated here");
065: rte.fillInStackTrace();
066: userData = rte;
067: }
068:
069: }
070:
071: // AResource interface.
072: public boolean isAnonymous() {
073: return true;
074: }
075:
076: public String getAnonymousID() {
077: return nodeID == null ? ("A" + Integer.toString(genId)) : "U"
078: + nodeID;
079: }
080:
081: public String getURI() {
082: return null;
083: }
084:
085: public String toString() {
086: return "_:" + getAnonymousID();
087: }
088:
089: public int hashCode() {
090: return nodeID == null ? genId : nodeID.hashCode();
091: }
092:
093: public boolean equals(Object o) {
094: if (o == null || !(o instanceof ARPResource))
095: return false;
096: if (this == o)
097: return true;
098: // AResourceInternal a=(AResourceInternal)o;
099: // if ( uri != null )
100: // return (!a.isAnonymous()) && uri.equals(a.getURI());
101: ARPResource aa = (ARPResource) o;
102: return nodeID != null && nodeID.equals(aa.nodeID);
103: }
104:
105: private Object userData;
106:
107: public Object getUserData() {
108: // if ( uri != null )
109: // throw new IllegalStateException("User data only supported on blank nodes");
110: return nodeID == null ? userData : arp.getUserData(nodeID);
111: }
112:
113: public void setUserData(Object d) {
114: // if ( uri != null )
115: // throw new IllegalStateException("User data only supported on blank nodes");
116: if (nodeID == null)
117: userData = d;
118: else
119: arp.setUserData(nodeID, d);
120: }
121:
122: /* (non-Javadoc)
123: * @see com.hp.hpl.jena.rdf.arp.AResource#hasNodeID()
124: */
125: public boolean hasNodeID() {
126: return nodeID != null;
127: }
128:
129: private boolean used = false;
130:
131: /* (non-Javadoc)
132: * @see com.hp.hpl.jena.rdf.arp.AResourceInternal#setHasBeenUsed()
133: */
134: public void setHasBeenUsed() {
135: used = true;
136: }
137:
138: /* (non-Javadoc)
139: * @see com.hp.hpl.jena.rdf.arp.AResourceInternal#getHasBeenUsed()
140: */
141: public boolean getHasBeenUsed() {
142: return used;
143: }
144:
145: }
|