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;
20:
21: import java.util.*;
22:
23: import org.mandarax.kernel.Predicate;
24: import org.mandarax.rdf.lib.RDFLib;
25:
26: /**
27: * Registry for RDF predicates. Can be used to ensure that only one predicate per URI exists.
28: * @author <A HREF="mailto:j.b.dietrich@massey.ac.nz">Jens Dietrich</A> <A HREF="mailto:paschke@in.tum.de">Adrian Paschke</A>
29: * @version 1.1 <01 August 2004>
30: * @since 0.1
31: */
32: public class RDFPredicateRegistry implements RDFLogger, RDFConstants {
33:
34: private static Map registry = new Hashtable();
35:
36: /**
37: * Get a predicate for a qname.
38: * @param nameSpace a name space
39: * @param localName a local name
40: * @param isContainsPredicate whether this is a contains predicate
41: * @return a predicate
42: */
43: public static Predicate findOrCreatePredicate(String nameSpace,
44: String localName, boolean isContainsPredicate) {
45: if (isContainsPredicate)
46: return RDFLib.CONTAINS;
47: synchronized (registry) {
48: String key = (nameSpace == null ? "" : nameSpace)
49: + localName;
50: Predicate p = (Predicate) registry.get(key);
51: if (p == null) {
52: p = new RDFPredicate(nameSpace, localName);
53: registry.put(key, p);
54: if (LOG_RDF.isDebugEnabled()) {
55: LOG_RDF.debug("Added RDF predicate to registry: "
56: + p);
57: }
58: }
59: return p;
60: }
61: }
62: }
|