001: /*
002: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.mandarax.rdf;
020:
021: import org.mandarax.kernel.*;
022:
023: /**
024: * RDF predicate implementation.
025: * @author <A HREF="mailto:j.b.dietrich@massey.ac.nz">Jens Dietrich</A> <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
026: * @version 1.1 <01 August 2004>
027: * @since 0.1
028: */
029:
030: public class RDFPredicate implements Predicate, RDFLogger {
031: private static final String[] slotNames = { "subject", "object" };
032: // TODO inventing our own classes Resource and Literals seems to be the easiest way, but is memory intensive
033: // should we just use the respective JENA types??
034: private static final Class[] structure = { Object.class,
035: Object.class };
036:
037: private String nameSpace = null;
038: private String localName = null;
039:
040: /**
041: * Constructor.
042: */
043: public RDFPredicate() {
044: super ();
045: }
046:
047: /**
048: * Constructor.
049: * @param nameSpace a name space
050: * @param localName a local name
051: */
052: public RDFPredicate(String nameSpace, String localName) {
053: super ();
054: this .nameSpace = nameSpace;
055: this .localName = localName;
056: }
057:
058: /**
059: * Get the slot names.
060: * @return an array of strings
061: */
062: public String[] getSlotNames() {
063: return slotNames;
064: }
065:
066: /**
067: * Set the slot names. This method is ignored, the slot names are fixed
068: * @param names an array of strings
069: */
070: public void setSlotNames(String[] names) {
071: throw new UnsupportedOperationException(
072: "The slot names cannot be changed ");
073: }
074:
075: /**
076: * Indicates whether the slot names can be modified.
077: * @return a boolean
078: */
079: public boolean slotNamesCanBeEdited() {
080: return false;
081: }
082:
083: /**
084: * Get the name of the object.
085: * @return the name of the constructor
086: */
087: public String getName() {
088: return (nameSpace == null ? "" : nameSpace) + localName;
089: }
090:
091: /**
092: * Get the type structure of the object, e.g. the types of terms
093: * that can be used with this constructor.
094: * @return the structure of this constructor
095: */
096: public Class[] getStructure() {
097:
098: return structure;
099: }
100:
101: /**
102: * Perform the function or predicate using an array of terms as parameters.
103: * @return the result of the perform operation
104: * @param parameter an array of terms
105: * @param session a session object
106: * @throws java.lang.UnsupportedOperationException thrown if this constructor does not have a sematics and this operation cannot be supported
107: * @throws java.lang.IllegalArgumentException
108: */
109: public Object perform(Term[] parameter, Session session)
110: throws IllegalArgumentException,
111: UnsupportedOperationException {
112: throw new UnsupportedOperationException(
113: "RDF Predicates do not support \"perform\"");
114: }
115:
116: /**
117: * Indicates whether this predicate is executable.
118: * @return a boolean
119: */
120: public boolean isExecutable() {
121: return false;
122: }
123:
124: /**
125: * Get the local name.
126: * @return Returns the localName.
127: */
128: public String getLocalName() {
129: return localName;
130: }
131:
132: /**
133: * Set the local name.
134: * @param localName The localName to set.
135: */
136: public void setLocalName(String localName) {
137: this .localName = localName;
138: }
139:
140: /**
141: * Get the name space.
142: * @return Returns the nameSpace.
143: */
144: public String getNameSpace() {
145: return nameSpace;
146: }
147:
148: /**
149: * Set the name space.
150: * @param nameSpace The nameSpace to set.
151: */
152: public void setNameSpace(String nameSpace) {
153: this .nameSpace = nameSpace;
154: }
155:
156: /**
157: * Convert this object to a string.
158: * @return the string representation of the object.
159: */
160: public String toString() {
161: return new StringBuffer().append("anRDFPredicate(").append(
162: nameSpace == null ? "" : nameSpace).append(localName)
163: .append(')').toString();
164: }
165: }
|