All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.tv.si.TransportImpl Maven / Gradle / Ivy

The newest version!
/*
 * @(#)TransportImpl.java	1.18 00/01/14
 *
 * Copyright 1998-2000 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 * 
 * This software is the confidential and proprietary information
 * of Sun Microsystems, Inc. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Sun.
 */

package com.sun.tv.si;

import java.util.*;
import com.sun.tv.*;
import javax.tv.locator.*;
import javax.tv.service.*;
import javax.tv.service.transport.*;
import javax.tv.service.navigation.*;

/**
 *
 * This interface represents an individual content delivery mechanism.
 * Transport objects serve as an access point for acquiring
 * information about services and their groupings.

* * A Transport object may expose various types of * entities (e.g. Bouquets, Networks and/or TransportStreams) by * implementing additional optional interfaces * (i.e. BouquetCollection, * NetworkCollection, and/or * TransportStreamCollection), depending on the particular * SI format used and the presence of optional elements and tables in * the SI data being broadcast. * * @see BouquetCollection * @see NetworkCollection * @see TransportStreamCollection */ public class TransportImpl implements BouquetCollection, NetworkCollection, TransportStreamCollection { private static Hashtable detailsListeners = new Hashtable(); private static Hashtable bouquetListeners = new Hashtable(); private static Hashtable networkListeners = new Hashtable(); private static Hashtable transportStreamListeners = new Hashtable(); private int transportID = -1; private DeliverySystemType deliverySystemType; private Locator locator = null; public TransportImpl( int transportID, DeliverySystemType deliverySystemType) { this.transportID = transportID; this.deliverySystemType = deliverySystemType; } /** * Reports the type of mechanism by which this * Transport delivers content. * * @return The delivery system type of this transport. */ public DeliverySystemType getDeliverySystemType() { return this.deliverySystemType; } /** * Registers a ServiceDetailsChangeListener to be notified of * changes to ServiceDetails that are carried on * this Transport. Subsequent notification is made via * ServiceDetailsChangeEvent with this * Transport instance as the event source.

* * This method is only a request for notification. No guarantee is * provided that the SI database will detect all, or even any, SI * changes or whether such changes will be detected in a timely * fashion.

* * If the specified ServiceDetailsChangeListener is * already registered, no action is performed. * * @param listener An ServiceDetailsChangeListener to be * notified about changes related to ServiceDetails * carried on this Transport. * * @throws SecurityException If the caller does not have * javax.tv.service.ReadPermission(locator) for this * Transport. * * @see ServiceDetailsChangeEvent * @see javax.tv.service.ReadPermission */ public void addServiceDetailsChangeListener(ServiceDetailsChangeListener listener) throws SecurityException { if ( listener == null ) { throw new NullPointerException("SIChangeListener null"); } Vector listeners = getListeners(detailsListeners); listeners.removeElement(listener); listeners.addElement(listener); } /** * Called to unregister an * ServiceDetailsChangeListener. If the specified * ServiceDetailsChangeListener is not registered, no * action is performed. * * @param listener A previously registered listener. */ public void removeServiceDetailsChangeListener(ServiceDetailsChangeListener listener) { if ( listener == null ) { throw new NullPointerException("SIChangeListener null"); } Vector listeners = getListeners(detailsListeners); listeners.removeElement(listener); } /** * Notify all listeners that this transport has been changed. */ public void notifyServiceDetailsListeners(ServiceDetailsChangeEvent event) { Vector listeners = getListeners(detailsListeners); for (int i = 0; i < listeners.size(); i++) { ServiceDetailsChangeListener listener = (ServiceDetailsChangeListener)listeners.elementAt(i); if (listener == null) continue; notifyAsyncListener(event, listener); } } /** * Retrieves the specified Bouquet from the collection.

* * This method delivers its results asynchronously. * * @param locator Locator referencing the Bouquet of interest * * @param requestor The SIRequestor to be notified * when this retrieval operation completes. * * @return An SIRequest object identifying this * asynchronous retrieval request. * * @throws InvalidLocatorException If locator does not * reference a valid bouquet. * * @throws SecurityException if the caller does not have * javax.tv.service.ReadPermission(locator) * * @see Bouquet * @see javax.tv.service.ReadPermission */ public SIRequest retrieveBouquet(Locator locator, SIRequestor requestor) throws InvalidLocatorException, SecurityException { if ( requestor == null ) { throw new NullPointerException("SIRequestor null"); } if ( locator == null ) { throw new NullPointerException("Locator null"); } if (LocatorImpl.isBouquet(locator) == false) { throw new InvalidLocatorException(locator); } SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new ReadPermission(locator)); } return new SIRequestImpl(requestor, locator); } /** * * Retrieves an array of all the Bouquet objects in * this BouquetCollection. This array will only contain * Bouquet instances for which the caller has * javax.tv.service.ReadPermission on the underlying * locator.

* * This method delivers its results asynchronously. * * @param requestor The SIRequestor to be notified * when this retrieval operation completes. * * @return An SIRequest object identifying this * asynchronous retrieval request. * * @see Bouquet */ public SIRequest retrieveBouquets(SIRequestor requestor) { if ( requestor == null ) { throw new NullPointerException("SIRequestor null"); } Locator bouquetLocator = null; try { bouquetLocator = LocatorFactory.getInstance().createLocator( LocatorImpl.BouquetProtocol + "*"); } catch (Exception e) { ; } return new SIRequestImpl(requestor, bouquetLocator); } /** * Retrieves the specified Network from the collection.

* * This method delivers its results asynchronously. * * @param locator Locator referencing the Network of interest. * * @param requestor The SIRequestor to be notified * when this retrieval operation completes. * * @return An SIRequest object identifying this * asynchronous retrieval request. * * @throws InvalidLocatorException If locator does not * reference a valid network. * * @throws SecurityException if the caller does not have * javax.tv.service.ReadPermission(locator) * * @see Network * @see javax.tv.service.ReadPermission */ public SIRequest retrieveNetwork(Locator locator, SIRequestor requestor) throws InvalidLocatorException, SecurityException { if ( requestor == null ) { throw new NullPointerException("SIRequestor null"); } if ( locator == null ) { throw new NullPointerException("Locator is null"); } if (LocatorImpl.isNetwork(locator) == false) { throw new InvalidLocatorException(locator); } SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new ReadPermission(locator)); } return new SIRequestImpl(requestor, locator); } /** * Retrieves an array of all the Network objects in * this NetworkCollection. The collection will only * contain instances for which the caller has * javax.tv.service.ReadPermission on the underlying * locator.

* * This method delivers its results asynchronously. * * @param requestor The SIRequestor to be notified * when this retrieval operation completes. * * @return An SIRequest object identifying this * asynchronous retrieval request. * * @see Network */ public SIRequest retrieveNetworks(SIRequestor requestor) { if ( requestor == null ) { throw new NullPointerException("SIRequestor null"); } Locator networkLocator = null; try { networkLocator = LocatorFactory.getInstance().createLocator( LocatorImpl.NetworkProtocol + "*"); } catch (Exception e) { ; } return new SIRequestImpl(requestor, networkLocator); } /** * * Retrieves the specified TransportStream from the collection. * * @param locator Locator referencing the * TransportStream of interest * * @param requestor The SIRequestor to be notified * when this retrieval operation completes. * * @return An SIRequest object identifying this * asynchronous retrieval request. * * @throws InvalidLocatorException If locator does not * reference a valid transport stream. * * @throws SecurityException if the caller does not have * javax.tv.service.ReadPermission(locator) * * @see TransportStream * @see javax.tv.service.ReadPermission */ public SIRequest retrieveTransportStream(Locator locator, SIRequestor requestor) throws InvalidLocatorException, SecurityException { if ( requestor == null ) { throw new NullPointerException("SIRequestor null"); } if ( locator == null ) { throw new NullPointerException("Locator is null"); } if (LocatorImpl.isTransportStream(locator) == false) { throw new InvalidLocatorException(locator); } SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new ReadPermission(locator)); } return new SIRequestImpl(requestor, locator); } /** * * Retrieves an array of the TransportStream objects in * this TransportStreamCollection. Only * TransportStream instances for which the caller has * javax.tv.service.ReadPermission on the underlying locator will be * present in the array.

* * This method delivers its results asynchronously. * * @param requestor The SIRequestor to be notified * when this retrieval operation completes. * * @return An SIRequest object identifying this * asynchronous retrieval request. * * @see TransportStream * @see javax.tv.service.ReadPermission */ public SIRequest retrieveTransportStreams(SIRequestor requestor) { if ( requestor == null ) { throw new NullPointerException("SIRequestor null"); } Locator tsLocator = null; try { tsLocator = LocatorFactory.getInstance().createLocator( LocatorImpl.TransportStreamProtocol + "*"); } catch (Exception e) { ; } return new SIRequestImpl(requestor, tsLocator); } /** * Retrieves an array of TransportStream objects * representing the transport streams carried in the specified * Network.

* * This method delivers its results asynchronously. * * @param locator A locator referencing a Network from * which to retrieve transport stream information. * * @param requestor The SIRequestor to be notified * when this retrieval operation completes. * * @return An SIRequest object identifying this * asynchronous retrieval request. * * @throws InvalidLocatorException If locator does not * reference a valid Network on the Transport * implementing this interface. * * @throws SecurityException if the caller does not have * javax.tv.service.ReadPermission(locator) * * @see TransportStream * @see Transport * @see javax.tv.service.ReadPermission */ public SIRequest retrieveTransportStreams(Locator locator, SIRequestor requestor) throws InvalidLocatorException, SecurityException { if ( requestor == null ) { throw new NullPointerException("SIRequestor null"); } if ( locator == null ) { throw new NullPointerException("Locator is null"); } if (LocatorImpl.isNetwork(locator) == false) { throw new InvalidLocatorException(locator); } SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new ReadPermission(locator)); } Locator transportLocator = LocatorImpl.transformToTransportStream(locator); if (transportLocator == null) { throw new InvalidLocatorException(transportLocator); } return new SIRequestImpl(requestor, transportLocator); } /** * Registers a BouquetChangeListener to be * notified of changes to a Bouquet that is * part of this BouquetCollection. Subsequent * notification is made via BouquetChangeEvent * with this BouquetCollection as the event * source.

* * This method is only a request for notification. No guarantee is * provided that the SI database will detect all, or even any, SI * changes or whether such changes will be detected in a timely * fashion.

* * If the specified BouquetChangeListener is * already registered, no action is performed. * * @param listener A BouquetChangeListener to be * notified about changes related to Bouquet * carried on this Transport. * * @throws SecurityException If the caller does not have * javax.tv.service.ReadPermission(locator). * * @see BouquetChangeEvent * @see javax.tv.service.ReadPermission **/ public void addBouquetChangeListener(BouquetChangeListener listener) throws SecurityException { if ( listener == null ) { throw new NullPointerException("BouquetChangeListener null"); } Vector listeners = getListeners(bouquetListeners); listeners.removeElement(listener); listeners.addElement(listener); } /** * Called to unregister an * BouquetChangeListener. If the specified * BouquetChangeListener is not registered, no * action is performed. * * @param listener A previously registered listener. */ public void removeBouquetChangeListener(BouquetChangeListener listener) { if ( listener == null ) { throw new NullPointerException("BouquetChangeListener null"); } Vector listeners = getListeners(bouquetListeners); listeners.removeElement(listener); } /** * Notify all listeners that the bouquet has changed. */ public void notifyBouquetListeners(BouquetChangeEvent event) { Vector listeners = getListeners(bouquetListeners); for (int i = 0; i < listeners.size(); i++) { BouquetChangeListener listener = (BouquetChangeListener)listeners.elementAt(i); if (listener == null) continue; notifyAsyncListener(event, listener); } } /** * Registers a NetworkChangeListener to be * notified of changes to a Network that is * part of this NetworkCollection. Subsequent * notification is made via NetworkChangeEvent * with this NetworkCollection as the event * source.

* * This method is only a request for notification. No guarantee is * provided that the SI database will detect all, or even any, SI * changes or whether such changes will be detected in a timely * fashion.

* * If the specified NetworkChangeListener is * already registered, no action is performed. * * @param listener A NetworkChangeListener to be * notified about changes related to Network * carried on this Transport. * * @throws SecurityException If the caller does not have * javax.tv.service.ReadPermission(locator). * * @see NetworkChangeEvent * @see javax.tv.service.ReadPermission **/ public void addNetworkChangeListener(NetworkChangeListener listener) throws SecurityException { if ( listener == null ) { throw new NullPointerException("NetworkChangeListener null"); } Vector listeners = getListeners(networkListeners); listeners.removeElement(listener); listeners.addElement(listener); } /** * Called to unregister an * NetworkChangeListener. If the specified * NetworkChangeListener is not registered, no * action is performed. * * @param listener A previously registered listener. */ public void removeNetworkChangeListener(NetworkChangeListener listener) { if ( listener == null ) { throw new NullPointerException("NetworkChangeListener null"); } Vector listeners = getListeners(networkListeners); listeners.removeElement(listener); } /** * Notify all listeners that the bouquet has changed. */ public void notifyNetworkListeners(NetworkChangeEvent event) { Vector listeners = getListeners(networkListeners); for (int i = 0; i < listeners.size(); i++) { NetworkChangeListener listener = (NetworkChangeListener)listeners.elementAt(i); if (listener == null) continue; notifyAsyncListener(event, listener); } } /** * Registers a TransportStreamChangeListener to be * notified of changes to a TransportStream that is * part of this TransportStreamCollection. Subsequent * notification is made via TransportStreamChangeEvent * with this TransportStreamCollection as the event * source.

* * This method is only a request for notification. No guarantee is * provided that the SI database will detect all, or even any, SI * changes or whether such changes will be detected in a timely * fashion.

* * If the specified TransportStreamChangeListener is * already registered, no action is performed. * * @param listener A TransportStreamChangeListener to be * notified about changes related to TransportStream * carried on this Transport. * * @throws SecurityException If the caller does not have * javax.tv.service.ReadPermission(locator). * * @see TransportStreamChangeEvent * @see javax.tv.service.ReadPermission **/ public void addTransportStreamChangeListener(TransportStreamChangeListener listener) throws SecurityException { if ( listener == null ) { throw new NullPointerException("TransportStreamChangeListener null"); } Vector listeners = getListeners(transportStreamListeners); listeners.removeElement(listener); listeners.addElement(listener); } /** * Called to unregister an * TransportStreamChangeListener. If the specified * TransportStreamChangeListener is not registered, no * action is performed. * * @param listener A previously registered listener. */ public void removeTransportStreamChangeListener(TransportStreamChangeListener listener) { if ( listener == null ) { throw new NullPointerException("TransportStreamChangeListener null"); } Vector listeners = getListeners(transportStreamListeners); listeners.removeElement(listener); } /** * Notify all listeners that the transport stream has changed. */ public void notifyTransportStreamListeners(TransportStreamChangeEvent event) { Vector listeners = getListeners(transportStreamListeners); for (int i = 0; i < listeners.size(); i++) { TransportStreamChangeListener listener = (TransportStreamChangeListener)listeners.elementAt(i); if (listener == null) continue; notifyAsyncListener(event, listener); } } /** * */ private Vector getListeners(Hashtable listenerTable) { String key = Integer.toString(transportID); Vector listeners = (Vector)listenerTable.get(key); if (listeners == null) { listeners = new Vector(); listenerTable.put(key, listeners); } return listeners; } private void notifyAsyncListener( SIChangeEvent event, SIChangeListener listener) { if (listener == null || event == null) return; NotifySIChangeThread thread = new NotifySIChangeThread(event, listener); if (thread != null) thread.start(); } } class NotifySIChangeThread extends Thread { SIChangeListener listener = null; SIChangeEvent event = null; public NotifySIChangeThread( SIChangeEvent event, SIChangeListener listener) { super("NotifySIChangeThread"); this.listener = listener; this.event = event; } public void run() { if (this.listener == null || this.event == null) return; //if (listener instanceof BouquetChangeListener) { if (listener instanceof BouquetChangeListener && event instanceof BouquetChangeEvent) { BouquetChangeListener theListener = (BouquetChangeListener)listener; theListener.notifyChange((BouquetChangeEvent)this.event); } //if (listener instanceof NetworkChangeListener) { if (listener instanceof NetworkChangeListener && event instanceof NetworkChangeEvent) { NetworkChangeListener theListener = (NetworkChangeListener)listener; theListener.notifyChange((NetworkChangeEvent)this.event); } //if (listener instanceof ServiceDetailsChangeListener) { if (listener instanceof ServiceDetailsChangeListener && event instanceof ServiceDetailsChangeEvent) { ServiceDetailsChangeListener theListener = (ServiceDetailsChangeListener)listener; theListener.notifyChange((ServiceDetailsChangeEvent)this.event); } //if (listener instanceof TransportStreamChangeListener) { if (listener instanceof TransportStreamChangeListener && event instanceof TransportStreamChangeEvent) { TransportStreamChangeListener theListener = (TransportStreamChangeListener)listener; theListener.notifyChange((TransportStreamChangeEvent)this.event); } } }