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;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.compass.gps.CompassGps;
22: import org.compass.gps.CompassGpsDevice;
23: import org.compass.gps.CompassGpsException;
24:
25: /**
26: * A helper base class that can wrap a {@link org.compass.gps.CompassGpsDevice}
27: * and delegate the calls defined at the
28: * {@link org.compass.gps.CompassGpsDevice} interface.
29: *
30: * @author kimchy
31: */
32: public class AbstractGpsDeviceWrapper implements CompassGpsDevice {
33:
34: protected Log log = LogFactory.getLog(getClass());
35:
36: protected CompassGpsDevice gpsDevice;
37:
38: public void setGpsDevice(CompassGpsDevice gpsDevice) {
39: this .gpsDevice = gpsDevice;
40: }
41:
42: public CompassGps getGps() {
43: checkDeviceSet();
44: return this .gpsDevice.getGps();
45: }
46:
47: public void injectGps(CompassGps compassGps) {
48: checkDeviceSet();
49: this .gpsDevice.injectGps(compassGps);
50: }
51:
52: public String getName() {
53: checkDeviceSet();
54: return gpsDevice.getName();
55: }
56:
57: public void setName(String name) {
58: checkDeviceSet();
59: this .gpsDevice.setName(name);
60: }
61:
62: public void start() throws CompassGpsException {
63: checkDeviceSet();
64: this .gpsDevice.start();
65: }
66:
67: public void stop() throws CompassGpsException {
68: checkDeviceSet();
69: this .gpsDevice.stop();
70: }
71:
72: public void index() throws CompassGpsException {
73: checkDeviceSet();
74: this .gpsDevice.index();
75: }
76:
77: public boolean isRunning() {
78: checkDeviceSet();
79: return this .gpsDevice.isRunning();
80: }
81:
82: public boolean isPerformingIndexOperation() {
83: checkDeviceSet();
84: return this .gpsDevice.isPerformingIndexOperation();
85: }
86:
87: public boolean shouldMirrorDataChanges() {
88: checkDeviceSet();
89: return this .gpsDevice.shouldMirrorDataChanges();
90: }
91:
92: protected void checkDeviceSet() {
93: if (this .gpsDevice == null) {
94: throw new IllegalStateException(
95: "Must set the wrapped device first");
96: }
97: }
98: }
|