xref: /trunk/main/avmedia/source/java/Manager.java (revision e357d40e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // UNO
25 import com.sun.star.uno.UnoRuntime;
26 import com.sun.star.uno.XComponentContext;
27 import com.sun.star.uno.AnyConverter;
28 import com.sun.star.uno.IQueryInterface;
29 import com.sun.star.lang.XInitialization;
30 
31 // media
32 import com.sun.star.media.*;
33 
34 public class Manager implements com.sun.star.lang.XServiceInfo,
35                                 com.sun.star.lang.XTypeProvider,
36                                 com.sun.star.media.XManager
37 
38 {
39     private com.sun.star.lang.XMultiServiceFactory maFactory;
40 
41     // -------------------------------------------------------------------------
42 
Manager( com.sun.star.lang.XMultiServiceFactory aFactory )43     public Manager( com.sun.star.lang.XMultiServiceFactory aFactory )
44     {
45         maFactory = aFactory;
46     }
47 
48     // ------------
49     // - XManager -
50     // ------------
51 
createPlayer( String aURL )52     public com.sun.star.media.XPlayer createPlayer( String aURL )
53     {
54         javax.media.Player aPlayer = null;
55 
56         try
57         {
58             aPlayer = javax.media.Manager.createRealizedPlayer( new java.net.URL( aURL ) );
59         }
60         catch( java.net.MalformedURLException e )
61         {
62         }
63         catch( java.io.IOException e )
64         {
65         }
66         catch( javax.media.NoPlayerException e )
67         {
68         }
69         catch( javax.media.CannotRealizeException e )
70         {
71         }
72         catch( java.lang.Exception e )
73         {
74         }
75 
76         if( aPlayer != null )
77         {
78             return new Player( maFactory, aPlayer, aURL );
79         }
80         else
81             return null;
82     }
83 
84     // ----------------
85     // - XServiceInfo -
86     // ----------------
87 
88     private static final String s_implName = "com.sun.star.comp.media.Manager_Java";
89     private static final String s_serviceName = "com.sun.star.media.Manager_Java";
90 
getImplementationName()91     public synchronized String getImplementationName()
92     {
93         return s_implName;
94     }
95 
96     // -------------------------------------------------------------------------
97 
getSupportedServiceNames()98     public synchronized String [] getSupportedServiceNames()
99     {
100         return new String [] { s_serviceName };
101     }
102 
103     // -------------------------------------------------------------------------
104 
supportsService( String serviceName )105     public synchronized boolean supportsService( String serviceName )
106     {
107         return serviceName.equals( s_serviceName );
108     }
109 
110     // -----------------
111     // - XTypeProvider -
112     // -----------------
113     protected byte[] maImplementationId;
114 
getTypes()115     public com.sun.star.uno.Type[] getTypes()
116     {
117         com.sun.star.uno.Type[] retValue = new com.sun.star.uno.Type[ 3 ];
118 
119         retValue[ 0 ]= new com.sun.star.uno.Type( com.sun.star.lang.XServiceInfo.class );
120         retValue[ 1 ]= new com.sun.star.uno.Type( com.sun.star.lang.XTypeProvider.class );
121         retValue[ 2 ]= new com.sun.star.uno.Type( com.sun.star.media.XManager.class );
122 
123         return retValue;
124     }
125 
126     // -------------------------------------------------------------------------
127 
getImplementationId()128     synchronized public byte[] getImplementationId()
129     {
130         if( maImplementationId == null)
131         {
132             maImplementationId = new byte[ 16 ];
133 
134             int hash = hashCode();
135 
136             maImplementationId[ 0 ] = (byte)(hash & 0xff);
137             maImplementationId[ 1 ] = (byte)((hash >>> 8) & 0xff);
138             maImplementationId[ 2 ] = (byte)((hash >>> 16) & 0xff);
139             maImplementationId[ 3 ] = (byte)((hash >>>24) & 0xff);
140         }
141 
142         return maImplementationId;
143     }
144 }
145