01: package org.mandarax.jdbc.server;
02:
03: /*
04: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import java.io.*;
22: import java.net.URL;
23: import org.mandarax.util.logging.LogCategories;
24:
25: /**
26: * An abstract super class for knowledge base factory implementors.
27: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
28: * @version 3.3.2 <29 December 2004>
29: * @since 3.0
30: */
31:
32: public abstract class AbstractKnowledgeBaseFactory implements
33: KnowledgeBaseFactory, LogCategories {
34: /**
35: * Get an input stream for the respective knowledge source.
36: * @return an input stream
37: * @param source a data source name (file or URL)
38: * @throws an exception
39: */
40: protected InputStream getInputStream(String source)
41: throws Exception {
42: // try whether this is a file
43: try {
44: File f = new File(source);
45: if (f.exists())
46: return new FileInputStream(f);
47: else {
48: if (LOG_JDBC.isDebugEnabled())
49: LOG_JDBC.debug("Cannot find file " + source
50: + " try to handle this source as URL");
51: }
52: } catch (Exception x) {
53: if (LOG_JDBC.isDebugEnabled())
54: LOG_JDBC.debug("Cannot find file " + source
55: + " try to handle this source as URL");
56: }
57: // try whether this is a url
58: URL url = new URL(source);
59: return url.openStream();
60: }
61:
62: /**
63: * Indicates whether this factory is suitable to access knowledge bases
64: * using the given protocol.
65: * @param protocol a protocol (name) such as zkb, xkb, ruleml etc
66: * @return a boolean
67: */
68: public abstract boolean supportsProtocol(String protocolName);
69:
70: }
|