01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.gps.device.ojb;
18:
19: import org.apache.ojb.broker.PersistenceBroker;
20: import org.compass.gps.CompassGpsDevice;
21:
22: /**
23: * Sets of utilies to hadle the persistence broker and ojb device.
24: *
25: * @author kimchy
26: *
27: */
28: public abstract class OjbGpsDeviceUtils {
29:
30: /**
31: * Attaches the persistence broker for batch indexing operation to the
32: * device.
33: */
34: public static void attachPersistenceBrokerForMirror(
35: CompassGpsDevice device, PersistenceBroker persistenceBroker)
36: throws NonOjbDeviceException {
37: if (!(device instanceof OjbGpsDevice)) {
38: throw new NonOjbDeviceException(
39: "The device is not an ojb device");
40: }
41:
42: ((OjbGpsDevice) device)
43: .attachLifecycleListeners(persistenceBroker);
44: }
45:
46: /**
47: * Removes the ojb device as a lifecycle listener from the persistence
48: * broker.
49: */
50: public static void removePersistenceBrokerForMirror(
51: CompassGpsDevice device, PersistenceBroker persistenceBroker)
52: throws NonOjbDeviceException {
53: if (!(device instanceof OjbGpsDevice)) {
54: throw new NonOjbDeviceException(
55: "The device is not an ojb device");
56: }
57:
58: ((OjbGpsDevice) device)
59: .removeLifecycleListeners(persistenceBroker);
60: }
61:
62: /**
63: * Attach the ojb device as a lifecycle listener to the persistence broker.
64: */
65: public static void attachPersistenceBrokerForIndex(
66: CompassGpsDevice device, PersistenceBroker persistenceBroker)
67: throws NonOjbDeviceException {
68:
69: if (!(device instanceof OjbGpsDevice)) {
70: throw new NonOjbDeviceException(
71: "The device is not an ojb device");
72: }
73:
74: ((OjbGpsDevice) device)
75: .setIndexPersistenceBroker(persistenceBroker);
76: }
77: }
|