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.mid.cenrep;
|
|
19 |
|
|
20 |
import com.nokia.mj.impl.cenrep.CentralRepositoryImpl;
|
|
21 |
|
|
22 |
/**
|
|
23 |
* The <code>CentralRepository</code> is class to manage application
|
|
24 |
* settings and share data with other runtimes. In S60 this API can be used
|
|
25 |
* to set and get values in Symbian Central Repositories.<P>
|
|
26 |
*
|
|
27 |
* Example of usage:<P>
|
|
28 |
*
|
|
29 |
* <code style="white-space: pre">
|
|
30 |
* class CentralRepositoryExample {
|
|
31 |
* private static final String EXAMPLE_REPOSITORY= "0x20000000";
|
|
32 |
* private static final String EXAMPLE_KEY1 = "0x00000001";
|
|
33 |
* private static final String EXAMPLE_KEY2 = "0x00000002";
|
|
34 |
*
|
|
35 |
* public modifySetting() throws CentralRepositoryException {
|
|
36 |
* CentralRepository cenrep = CentralRepository.open(EXAMPLE_REPOSITORY);
|
|
37 |
* try {
|
|
38 |
* String value1 = cenrep.getString(EXAMPLE_KEY1);
|
|
39 |
* int value2 = cenrep.getInt(EXAMPLE_KEY2);
|
|
40 |
|
|
41 |
* cenrep.setString(EXAMPLE_KEY1, value3);
|
|
42 |
* cenrep.setInt(EXAMPLE_KEY2, value4);
|
|
43 |
* }
|
|
44 |
* catch (CentralRepositoryException cre) {
|
|
45 |
* System.out.println(cre);
|
|
46 |
* }
|
|
47 |
* finally {
|
|
48 |
* cenrep.close();
|
|
49 |
* }
|
|
50 |
* }
|
|
51 |
* }</code>
|
|
52 |
*/
|
|
53 |
public abstract class CentralRepository
|
|
54 |
{
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Hidden default constructor.
|
|
58 |
*/
|
|
59 |
protected CentralRepository()
|
|
60 |
{
|
|
61 |
}
|
|
62 |
|
|
63 |
/**
|
|
64 |
* Opens central repository.
|
|
65 |
*
|
|
66 |
* @param repositoryId it is platform specific and in S60 it is
|
|
67 |
* Symbian Central Repository UID.
|
|
68 |
* @return An instance of CentralRepository class
|
|
69 |
* for accessing a repository.
|
|
70 |
* @throws CentralRepositoryException if openning fails.
|
|
71 |
*/
|
|
72 |
static public CentralRepository open(String repositoryId)
|
|
73 |
throws CentralRepositoryException
|
|
74 |
{
|
|
75 |
return CentralRepositoryImpl.open(repositoryId);
|
|
76 |
}
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Closes central repository. If get or set methods are used after
|
|
80 |
* close operation, exception will be thrown.
|
|
81 |
*/
|
|
82 |
public abstract void close()
|
|
83 |
throws CentralRepositoryException;
|
|
84 |
|
|
85 |
/**
|
|
86 |
* Returns string stored in given key.
|
|
87 |
*
|
|
88 |
* @param key the key of setting to be read.
|
|
89 |
* @return the value of the setting if it is the string.
|
|
90 |
* @throws CentralRepositoryException if key is not found or
|
|
91 |
* stored data is not string.
|
|
92 |
*/
|
|
93 |
public abstract String getString(String key)
|
|
94 |
throws CentralRepositoryException;
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Returns integer stored in given key.
|
|
98 |
*
|
|
99 |
* @param key the key of setting to be read.
|
|
100 |
* @return the value of the setting if it is an integer.
|
|
101 |
* @throws CentralRepositoryException if key is not found or
|
|
102 |
* stored data is not integer.
|
|
103 |
*/
|
|
104 |
public abstract int getInt(String key)
|
|
105 |
throws CentralRepositoryException;
|
|
106 |
|
|
107 |
/** Stores string value in key.
|
|
108 |
*
|
|
109 |
* @param key the key of setting to be stored.
|
|
110 |
* @param value the string value of the setting to be stored.
|
|
111 |
* @throws CentralRepositoryException if string value cannot be stored.
|
|
112 |
*/
|
|
113 |
public abstract void setString(String key, String value)
|
|
114 |
throws CentralRepositoryException;
|
|
115 |
|
|
116 |
/** Stores integer value in key.
|
|
117 |
*
|
|
118 |
* @param key the key of setting to be stored.
|
|
119 |
* @param value the integer value of the setting to be stored.
|
|
120 |
* @throws CentralRepositoryException if integer value cannot be stored.
|
|
121 |
*/
|
|
122 |
public abstract void setInt(String key, int value)
|
|
123 |
throws CentralRepositoryException;
|
|
124 |
}
|