001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.sail.memory.model;
007:
008: import org.openrdf.model.URI;
009: import org.openrdf.model.impl.LiteralImpl;
010:
011: /**
012: * A MemoryStore-specific extension of Literal giving it node properties.
013: *
014: * @author Arjohn Kampman
015: */
016: public class MemLiteral extends LiteralImpl implements MemValue {
017:
018: private static final long serialVersionUID = 4288477328829845024L;
019:
020: /*-----------*
021: * Variables *
022: *-----------*/
023:
024: /**
025: * The object that created this MemLiteral.
026: */
027: transient private Object creator;
028:
029: /**
030: * The list of statements for which this MemLiteral is the object.
031: */
032: transient private MemStatementList objectStatements = null;
033:
034: /*--------------*
035: * Constructors *
036: *--------------*/
037:
038: /**
039: * Creates a new Literal which will get the supplied label.
040: *
041: * @param creator
042: * The object that is creating this MemLiteral.
043: * @param label
044: * The label for this literal.
045: */
046: public MemLiteral(Object creator, String label) {
047: super (label);
048: this .creator = creator;
049: }
050:
051: /**
052: * Creates a new Literal which will get the supplied label and language code.
053: *
054: * @param creator
055: * The object that is creating this MemLiteral.
056: * @param label
057: * The label for this literal.
058: * @param lang
059: * The language code of the supplied label.
060: */
061: public MemLiteral(Object creator, String label, String lang) {
062: super (label, lang);
063: this .creator = creator;
064: }
065:
066: /**
067: * Creates a new Literal which will get the supplied label and datatype.
068: *
069: * @param creator
070: * The object that is creating this MemLiteral.
071: * @param label
072: * The label for this literal.
073: * @param datatype
074: * The datatype of the supplied label.
075: */
076: public MemLiteral(Object creator, String label, URI datatype) {
077: super (label, datatype);
078: this .creator = creator;
079: }
080:
081: /*---------*
082: * Methods *
083: *---------*/
084:
085: public Object getCreator() {
086: return creator;
087: }
088:
089: public MemStatementList getObjectStatementList() {
090: if (objectStatements == null) {
091: return EMPTY_LIST;
092: } else {
093: return objectStatements;
094: }
095: }
096:
097: public int getObjectStatementCount() {
098: if (objectStatements == null) {
099: return 0;
100: } else {
101: return objectStatements.size();
102: }
103: }
104:
105: public void addObjectStatement(MemStatement st) {
106: if (objectStatements == null) {
107: objectStatements = new MemStatementList(1);
108: }
109:
110: objectStatements.add(st);
111: }
112:
113: public void removeObjectStatement(MemStatement st) {
114: objectStatements.remove(st);
115:
116: if (objectStatements.isEmpty()) {
117: objectStatements = null;
118: }
119: }
120: }
|