|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.microedition.media.protocol; |
|
20 |
|
21 import com.nokia.microedition.media.InternalPlayer; |
|
22 import com.nokia.microedition.media.Locator; |
|
23 import javax.microedition.media.MediaException; |
|
24 |
|
25 /** |
|
26 * Factory for creating the Protocols |
|
27 */ |
|
28 public class ProtocolFactory |
|
29 { |
|
30 private Protocol iConnectorProtocol = null; |
|
31 |
|
32 public static final String PROTOCOL_CLASS_NAME = ".Protocol"; |
|
33 public static final String PROTOCOL_BASE_PACKAGE = |
|
34 "com.nokia.microedition.media.protocol."; |
|
35 |
|
36 /** |
|
37 * Constructor |
|
38 */ |
|
39 public ProtocolFactory() |
|
40 { |
|
41 iConnectorProtocol = new ConnectorProtocol(); |
|
42 } |
|
43 |
|
44 /** |
|
45 * Factory method for creating player from locator |
|
46 * Tries to load assosiated <code>Protocol</code> first, if this fails |
|
47 * then we try to create player by using <code>Connector</code> |
|
48 * @param aLocator Media locator |
|
49 * @return Player according to locator or null if cannot create |
|
50 */ |
|
51 public InternalPlayer createPlayer(Locator aLocator) |
|
52 throws java.io.IOException, |
|
53 MediaException, |
|
54 java.lang.SecurityException |
|
55 { |
|
56 InternalPlayer player = null; |
|
57 try |
|
58 { |
|
59 Class protocolClass = |
|
60 Class.forName(PROTOCOL_BASE_PACKAGE + |
|
61 aLocator.getProtocol() + PROTOCOL_CLASS_NAME); |
|
62 Protocol protocol = (Protocol)protocolClass.newInstance(); |
|
63 player = protocol.createPlayer(aLocator); |
|
64 } |
|
65 catch (InstantiationException ie) |
|
66 { |
|
67 throw new MediaException("Instantiation failed: " + ie); |
|
68 } |
|
69 catch (IllegalAccessException iae) |
|
70 { |
|
71 throw new MediaException("Illegal access: " + iae); |
|
72 } |
|
73 catch (ClassNotFoundException cnfe) |
|
74 { |
|
75 // we did not find specified Protocol, trying to create player |
|
76 // with connector |
|
77 player = iConnectorProtocol.createPlayer(aLocator); |
|
78 } |
|
79 return player; |
|
80 } |
|
81 } |
|
82 |