01: /*
02: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package org.mandarax.rdf.lib;
20:
21: import java.lang.reflect.Method;
22: import org.mandarax.kernel.Predicate;
23: import org.mandarax.kernel.Function;
24: import org.mandarax.kernel.meta.InstanceOfPredicate;
25: import org.mandarax.kernel.meta.JPredicate;
26: import org.mandarax.kernel.meta.JFunction;
27: import org.mandarax.rdf.*;
28: import com.hp.hpl.jena.rdf.model.*;
29:
30: /**
31: * A library of re-useable RDF related predicates and functions.
32: * @author <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A> <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
33: * @version 1.1 <01 August 2004>
34: * @since 0.1
35: */
36: public class RDFLib implements RDFLogger, RDFConstants {
37: public static Predicate IS_RESOURCE = new InstanceOfPredicate(
38: Resource.class, RDFNode.class);
39: public static Predicate IS_LITERAL = new InstanceOfPredicate(
40: Literal.class, RDFNode.class);
41: public static RDFPredicate CONTAINS = new RDFPredicate(RDF_NS,
42: "contains");
43:
44: /**
45: * Create a predicate.
46: * @param name the name of the predicate.
47: * @param clazz the defining class.
48: * @param methodName the name of the method.
49: * @param paramTypes the list of parameters of the method.
50: * @return a predicate.
51: * @exception Exception occurs when the predicate can not be initialized.
52: */
53: private static Predicate createPredicate(String name, Class clazz,
54: String methodName, Class[] paramTypes) {
55: try {
56: Method m = clazz.getMethod(methodName, paramTypes);
57: JPredicate p = new JPredicate(m);
58: p.setName(name);
59: return p;
60: } catch (Exception x) {
61: LOG_RDF.error("Cannot initialize predicate " + name, x);
62: return null;
63: }
64:
65: }
66:
67: /**
68: * Create a function.
69: * @param name the name of the function.
70: * @param clazz the class defining the method.
71: * @param methodName the name of the method.
72: * @param paramTypes the list of parameters of the method.
73: * @return a function.
74: * @exception Exceptions occurs when the function can not be initialized.
75: */
76: private static Function createFunction(String name, Class clazz,
77: String methodName, Class[] paramTypes) {
78: try {
79: Function f = new JFunction(clazz.getMethod(methodName,
80: paramTypes), name);
81: return f;
82: } catch (Exception x) {
83: LOG_RDF.error("Cannot initialize function " + name, x);
84: return null;
85: }
86:
87: }
88:
89: }
|