67
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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.mj.impl.cenrep;
|
|
19 |
|
|
20 |
import com.nokia.mj.impl.utils.Uid;
|
|
21 |
import com.nokia.mid.cenrep.CentralRepositoryException;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Class for central repository UID.
|
|
25 |
*/
|
|
26 |
class CentralRepositoryUid extends Uid
|
|
27 |
{
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Default constructor.
|
|
31 |
*/
|
|
32 |
protected CentralRepositoryUid()
|
|
33 |
{
|
|
34 |
super();
|
|
35 |
}
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Returns int value
|
|
39 |
*
|
|
40 |
* @param value string representation of uid.
|
|
41 |
* @throws CentralRepositoryException, if value is null, empty or not valid.
|
|
42 |
*/
|
|
43 |
static int getIntValue(String value)
|
|
44 |
throws CentralRepositoryException
|
|
45 |
{
|
|
46 |
Uid uid = Uid.createUid(value);
|
|
47 |
if (uid == null)
|
|
48 |
{
|
|
49 |
throw new CentralRepositoryException("Uid is null or empty");
|
|
50 |
}
|
|
51 |
|
|
52 |
String numStr = uid.getStringValue();
|
|
53 |
|
|
54 |
// Check if value is negative.
|
|
55 |
boolean negative = false;
|
|
56 |
if (numStr.startsWith("-"))
|
|
57 |
{
|
|
58 |
negative = true;
|
|
59 |
numStr = numStr.substring(1);
|
|
60 |
}
|
|
61 |
|
|
62 |
// Check for optional radix prefix.
|
|
63 |
int radix = 10;
|
|
64 |
if (numStr.startsWith("0x"))
|
|
65 |
{
|
|
66 |
radix = 16;
|
|
67 |
numStr = numStr.substring(2);
|
|
68 |
}
|
|
69 |
|
|
70 |
// Check if numStr is in Symbian TUid form [12345678].
|
|
71 |
if (numStr.length() <= 10 && numStr.startsWith("[") && numStr.endsWith("]"))
|
|
72 |
{
|
|
73 |
radix = 16;
|
|
74 |
numStr = numStr.substring(1, numStr.length()-1);
|
|
75 |
}
|
|
76 |
|
|
77 |
int result = 0;
|
|
78 |
long val = Long.parseLong(numStr, radix);
|
|
79 |
if (negative)
|
|
80 |
{
|
|
81 |
result = (int)-val;
|
|
82 |
}
|
|
83 |
else
|
|
84 |
{
|
|
85 |
result = (int)val;
|
|
86 |
}
|
|
87 |
return result;
|
|
88 |
}
|
|
89 |
|
|
90 |
};
|