001: /*
002: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: */
032:
033: package com.db.layers.underlay;
034:
035: import javax.media.Time;
036: import javax.media.MediaLocator;
037: import javax.media.protocol.*;
038: import java.io.IOException;
039:
040: public class LiveDataSource extends PushBufferDataSource {
041:
042: private Object[] controls = new Object[0];
043: private boolean started = false;
044: private String contentType = "raw";
045: private boolean connected = false;
046: private Time duration = DURATION_UNKNOWN;
047: private LiveStream[] streams = null;
048: private LiveStream stream = null;
049:
050: public LiveDataSource() {
051: }
052:
053: public String getContentType() {
054:
055: if (!connected) {
056: System.err.println("Error: DataSource not connected");
057: return null;
058: }
059: return contentType;
060:
061: }
062:
063: public void connect() throws IOException {
064:
065: if (connected)
066: return;
067: connected = true;
068:
069: }
070:
071: public void disconnect() {
072:
073: try {
074: if (started)
075: stop();
076: } catch (IOException e) {
077: }
078: connected = false;
079:
080: }
081:
082: public void start() throws IOException {
083:
084: // we need to throw error if connect() has not been called
085: if (!connected)
086: throw new java.lang.Error(
087: "DataSource must be connected before it can be started");
088: if (started)
089: return;
090: started = true;
091: stream.start(true);
092:
093: }
094:
095: public void stop() throws IOException {
096:
097: if ((!connected) || (!started))
098: return;
099: started = false;
100: stream.start(false);
101:
102: }
103:
104: public Object[] getControls() {
105:
106: return controls;
107:
108: }
109:
110: public Object getControl(String controlType) {
111:
112: try {
113: Class cls = Class.forName(controlType);
114: Object cs[] = getControls();
115: for (int i = 0; i < cs.length; i++) {
116: if (cls.isInstance(cs[i]))
117: return cs[i];
118: }
119: return null;
120:
121: } catch (Exception e) { // no such controlType or such control
122: return null;
123: }
124:
125: }
126:
127: public Time getDuration() {
128:
129: return duration;
130:
131: }
132:
133: public PushBufferStream[] getStreams() {
134:
135: if (streams == null) {
136: streams = new LiveStream[1];
137: stream = streams[0] = new LiveStream();
138: }
139: return streams;
140:
141: }
142:
143: }
|