01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.osgi;
22:
23: import org.osgi.framework.*;
24:
25: import com.db4o.*;
26: import com.db4o.config.*;
27: import com.db4o.ext.*;
28: import com.db4o.reflect.jdk.*;
29:
30: class Db4oServiceImpl implements Db4oService {
31:
32: private final Bundle _bundle;
33:
34: public Db4oServiceImpl(Bundle bundle) {
35: _bundle = bundle;
36: }
37:
38: public Configuration newConfiguration() {
39: Configuration config = Db4o.newConfiguration();
40: configureReflector(config);
41: return config;
42: }
43:
44: public ObjectContainer openClient(String hostName, int port,
45: String user, String password) throws Db4oException {
46: return openClient(null, hostName, port, user, password);
47: }
48:
49: public ObjectContainer openClient(Configuration config,
50: String hostName, int port, String user, String password)
51: throws Db4oException {
52: return Db4o.openClient(config(config), hostName, port, user,
53: password);
54: }
55:
56: public ObjectContainer openFile(String databaseFileName)
57: throws Db4oException {
58: return openFile(null, databaseFileName);
59: }
60:
61: public ObjectContainer openFile(Configuration config,
62: String databaseFileName) throws Db4oException {
63: return Db4o.openFile(config(config), databaseFileName);
64: }
65:
66: public ObjectServer openServer(String databaseFileName, int port)
67: throws Db4oException {
68: return openServer(null, databaseFileName, port);
69: }
70:
71: public ObjectServer openServer(Configuration config,
72: String databaseFileName, int port) throws Db4oException {
73: return Db4o.openServer(config(config), databaseFileName, port);
74: }
75:
76: private Configuration config(Configuration config) {
77: if (config == null) {
78: config = Db4o.newConfiguration();
79: } else {
80: configureReflector(config);
81: }
82: return config;
83: }
84:
85: private void configureReflector(Configuration config) {
86: config
87: .reflectWith(new JdkReflector(new OSGiLoader(_bundle,
88: new ClassLoaderJdkLoader(getClass()
89: .getClassLoader()))));
90: //config.reflectWith(new OSGiReflector(_bundle));
91: }
92:
93: }
|