|
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 package com.nokia.amms; |
|
19 |
|
20 import javax.microedition.media.MediaException; |
|
21 import com.nokia.microedition.media.NativeError; |
|
22 |
|
23 /** |
|
24 * This class contains general helper methods for error conversion |
|
25 * between native side and java side. |
|
26 */ |
|
27 public final class AMMSError |
|
28 { |
|
29 /** |
|
30 * Private, because this class is not intended to be constructed. |
|
31 */ |
|
32 private AMMSError() |
|
33 { |
|
34 } |
|
35 |
|
36 /** |
|
37 * This method throws IllegalStateException if error code is |
|
38 * KErrNotReady (-18) |
|
39 * |
|
40 * @param aNativeErrorCode Native error code. |
|
41 */ |
|
42 static public void checkIllegalState(int aNativeErrorCode) |
|
43 { |
|
44 if (aNativeErrorCode == NativeError.KErrNotReady) |
|
45 { |
|
46 throw new IllegalStateException(); |
|
47 } |
|
48 } |
|
49 |
|
50 /** |
|
51 * This method throws MediaException if checked native error |
|
52 * code is below KErrNone. |
|
53 * @param aNativeErrorCode Native error code. |
|
54 */ |
|
55 static public void checkMediaException(int aNativeErrorCode) |
|
56 throws MediaException |
|
57 { |
|
58 NativeError.checkOOMOnly(aNativeErrorCode); |
|
59 if (aNativeErrorCode < NativeError.KErrNone) |
|
60 { |
|
61 throw new MediaException(); |
|
62 } |
|
63 } |
|
64 /** |
|
65 * @param aObject Object to be checked. |
|
66 */ |
|
67 static public void checkArgument(Object aObject) |
|
68 { |
|
69 if (aObject == null) |
|
70 { |
|
71 throw new IllegalArgumentException(); |
|
72 } |
|
73 } |
|
74 |
|
75 /** |
|
76 * Checks for basic native error codes that map to standard Java |
|
77 * exceptions and throws the exception if the error code matches. |
|
78 * Otherwise throws basic Error class. |
|
79 * @param aNativeErrorCode Native error code. |
|
80 */ |
|
81 static public void check(int aNativeErrorCode) |
|
82 { |
|
83 NativeError.check(aNativeErrorCode); |
|
84 } |
|
85 } |