javauis/mmapi_akn/baseline/javasrc.emc/com/nokia/microedition/media/ManagerImpl.java
branchRCL_3
changeset 83 26b2b12093af
parent 71 d5e927d5853b
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
    31 import com.nokia.mj.impl.rt.legacy.NativeError;
    31 import com.nokia.mj.impl.rt.legacy.NativeError;
    32 import com.nokia.microedition.media.protocol.ProtocolFactory;
    32 import com.nokia.microedition.media.protocol.ProtocolFactory;
    33 import com.nokia.microedition.media.tone.PlayToneImpl;
    33 import com.nokia.microedition.media.tone.PlayToneImpl;
    34 import com.nokia.microedition.volumekeys.ForegroundListener;
    34 import com.nokia.microedition.volumekeys.ForegroundListener;
    35 import com.nokia.mj.impl.rt.support.Finalizer;
    35 import com.nokia.mj.impl.rt.support.Finalizer;
    36 import com.nokia.mj.impl.utils.Logger;
       
    37 
    36 
    38 /**
    37 /**
    39  * ManagerImpl implements the functionality specified in
    38  * ManagerImpl implements the functionality specified in
    40  * javax.microedition.media.Manager class.
    39  * javax.microedition.media.Manager class.
    41  * This class is a singleton and instance can be got with getInstance method.
    40  * This class is a singleton and instance can be got with getInstance method.
    55     private final MIDEventServer iEventServer;
    54     private final MIDEventServer iEventServer;
    56     private final Vector iPlugIns = new Vector();
    55     private final Vector iPlugIns = new Vector();
    57     private final ProtocolFactory iProtocolFactory = new ProtocolFactory();
    56     private final ProtocolFactory iProtocolFactory = new ProtocolFactory();
    58     private final ForegroundListener iForegroundListener;
    57     private final ForegroundListener iForegroundListener;
    59 
    58 
    60     private boolean iClosed = false;
       
    61     private Finalizer mFinalizer = new Finalizer()
    59     private Finalizer mFinalizer = new Finalizer()
    62     {
    60     {
    63         public void finalizeImpl()
    61         public void finalizeImpl()
    64         {
    62         {
    65             doFinalize();
    63             doFinalize();
   166     public void addPlugIn(PlugIn aPlugIn)
   164     public void addPlugIn(PlugIn aPlugIn)
   167     {
   165     {
   168         iPlugIns.addElement(aPlugIn);
   166         iPlugIns.addElement(aPlugIn);
   169     }
   167     }
   170 
   168 
   171     private void checkClose() throws MediaException
       
   172     {
       
   173         if (iClosed)
       
   174         {
       
   175             MediaException me = new MediaException("MIDlet closed.");
       
   176             Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,
       
   177                        "Trying to create player when MIDlet is destroyed ", me);
       
   178             throw me;
       
   179         }
       
   180     }
       
   181 
       
   182     private void doFinalize()
   169     private void doFinalize()
   183     {
   170     {
   184         if (mFinalizer != null)
   171         if (mFinalizer != null)
   185         {
   172         {
   186             registeredFinalize();
   173             registeredFinalize();
   191     /**
   178     /**
   192      * This will be called when object is finalized.
   179      * This will be called when object is finalized.
   193      */
   180      */
   194     synchronized final void registeredFinalize()
   181     synchronized final void registeredFinalize()
   195     {
   182     {
   196         iClosed = true;
       
   197         _dispose(sEventSourceHandle);
   183         _dispose(sEventSourceHandle);
   198         sEventSourceHandle = 0;
   184         sEventSourceHandle = 0;
   199     }
   185     }
   200 
   186 
   201     /**
   187     /**
   203      * This will release convenient native resources. All native resource
   189      * This will release convenient native resources. All native resource
   204      * will be deleted in registeredFinalize() method.
   190      * will be deleted in registeredFinalize() method.
   205      */
   191      */
   206     synchronized final void release()
   192     synchronized final void release()
   207     {
   193     {
   208         iClosed = true;
       
   209         _release(sEventSourceHandle);
   194         _release(sEventSourceHandle);
   210     }
   195     }
   211 
   196 
   212     /**
   197     /**
   213      * Create String array from Vector and remove String duplicates.
   198      * Create String array from Vector and remove String duplicates.
   361     }
   346     }
   362 
   347 
   363     /**
   348     /**
   364      * From PlugIn.
   349      * From PlugIn.
   365      */
   350      */
   366     public synchronized InternalPlayer createPlayer(DataSource aSource)
   351     public InternalPlayer createPlayer(DataSource aSource)
   367     throws MediaException, IOException
   352     throws MediaException, IOException
   368     {
   353     {
   369         checkClose();
       
   370         InternalPlayer player = null;
   354         InternalPlayer player = null;
   371         if (aSource.getContentType() != null)
   355         if (aSource.getContentType() != null)
   372         {
   356         {
   373             // Create player from content type
   357             // Create player from content type
   374             if (isValidContentType(aSource.getContentType()))
   358             if (isValidContentType(aSource.getContentType()))
   438      * @exception IOException Thrown if there was a problem connecting
   422      * @exception IOException Thrown if there was a problem connecting
   439      * with the source pointed to by the <code>locator</code>.
   423      * with the source pointed to by the <code>locator</code>.
   440      * @exception SecurityException Thrown if the caller does not
   424      * @exception SecurityException Thrown if the caller does not
   441      * have security permission to create the <code>Player</code>.
   425      * have security permission to create the <code>Player</code>.
   442      */
   426      */
   443     public synchronized Player createPlayer(String aLocator)
   427     public Player createPlayer(String aLocator)
   444     throws IOException, MediaException
   428     throws IOException, MediaException
   445     {
   429     {
   446         checkClose();
       
   447         if (aLocator == null)
   430         if (aLocator == null)
   448         {
   431         {
   449             throw new IllegalArgumentException("Locator is null.");
   432             throw new IllegalArgumentException("Locator is null.");
   450         }
   433         }
   451         InternalPlayer player = iProtocolFactory.createPlayer(
   434         InternalPlayer player = iProtocolFactory.createPlayer(
   534      * @exception IOException Thrown if there was a problem reading data
   517      * @exception IOException Thrown if there was a problem reading data
   535      * from the <code>InputStream</code>.
   518      * from the <code>InputStream</code>.
   536      * @exception SecurityException Thrown if the caller does not
   519      * @exception SecurityException Thrown if the caller does not
   537      * have security permission to create the <code>Player</code>.
   520      * have security permission to create the <code>Player</code>.
   538      */
   521      */
   539     public synchronized Player createPlayer(InputStream aStream, String aType)
   522     public Player createPlayer(InputStream aStream, String aType)
   540     throws IOException, MediaException
   523     throws IOException, MediaException
   541     {
   524     {
   542         checkClose();
       
   543         if (aStream == null)
   525         if (aStream == null)
   544         {
   526         {
   545             throw new IllegalArgumentException("InputStream is null.");
   527             throw new IllegalArgumentException("InputStream is null.");
   546         }
   528         }
   547 
   529