FileDocCategorySizeDatePackage
RegistryStore.javaAPI DocphoneME MR2 API (J2ME)17209Wed May 02 18:00:44 BST 2007com.sun.midp.content

RegistryStore

public class RegistryStore extends Object
Standalone Registry Storage manager. All protected methods, which are all static, redirect their work to alone instance allowed for given Java runtime (for MIDP it is Isolate). Teh standalone instance initializes resources in the private constructor and then releases its in the native finalizer.

Fields Summary
static final int
FIELD_ID
Content Handler fields indexes.
Used with functions: @link findHandler(), @link getValues() and
static final int
FIELD_TYPES
Handler ID
static final int
FIELD_SUFFIXES
Types supported by a handler
static final int
FIELD_ACTIONS
by a handler
static final int
FIELD_LOCALES
by a handler
static final int
FIELD_ACTION_MAP
by a handler
static final int
FIELD_ACCESSES
Handler action map
static final int
FIELD_COUNT
Access list
static final int
SEARCH_EXACT
Search flags for @link getHandler() method.
static final int
SEARCH_PREFIX
Search by exact match with ID
private static final int
FLAG_ERROR
Handler flags constants.
They should match according enums in jsr211_registry.h
private static final int
LAUNCH_OK
OK, handler started
private static final int
LAUNCH_OK_SHOULD_EXIT
OK, handler started or is ready to start, invoking app should exit.
private static final int
LAUNCH_ERR_NOTSUPPORTED
ERROR, not supported
private static final int
LAUNCH_ERR_NO_HANDLER
ERROR, no requested handler
private static final int
LAUNCH_ERR_NO_INVOCATION
ERROR, no invocation queued for requested handler
private static final int
LAUNCH_ERROR
common error
private static com.sun.midp.security.SecurityToken
classSecurityToken
This class has a different security domain than the MIDlet suite
private static RegistryStore
store
Singleton instance. Worker for the class static methods.
Constructors Summary
private RegistryStore()
Private constructor for the singleton storage class. If ClassNotFoundException is thrown during ActionNameMap loading the constructor throws RuntimeException


                           
      
        try {
            Class.forName("javax.microedition.content.ActionNameMap");
        } catch (ClassNotFoundException cnfe) {
            throw new RuntimeException(cnfe.getMessage());
        }
        if (!init()) {
            throw new RuntimeException("RegistryStore initialization failed");
        }
    
Methods Summary
private static ContentHandlerImpldeserializeCH(java.lang.String str)
Restores ContentHandler main fields (ID, suite_ID, class_name and flag) from serialized form to ContentHandlerImpl object.

param
str ContentHandler main data in serialized form.
return
restored ContentHandlerImpl object or null

        ContentHandlerImpl ch = null;

        while (str != null && str.length() > 0) {
            String id;
            String class_name;
            int beg = 0, end;

            end = str.indexOf('\n", beg);
            if (end == -1) {
                break; // no 1-st delimiter
            }
            id = str.substring(beg, end);
            if (id.length() == 0) {
                break; // ID is significant field
            }
            beg = end+1;

            end = str.indexOf('\n", beg);
            if (end == -1 || str.length() != end + 4) {
                break; // no 2-nd delimiter or wrong length of the string
            }
            class_name = str.substring(beg, end++);

            ch = new ContentHandlerImpl();
            ch.ID = id;
            ch.classname = class_name;
            ch.storageId = str.charAt(end++);
            ch.storageId <<= 16;
            ch.storageId |= str.charAt(end++);
            ch.registrationMethod = str.charAt(end);

            break;
        }
        return ch;
    
private static ContentHandlerImpl[]deserializeCHArray(java.lang.String str)
Restores ContentHandlerImpl array from serialized form.

param
str ContentHandlerImpl array in serialized form.
return
restored ContentHandlerImpl array

        String[] strs;
        ContentHandlerImpl[] arr;

        strs = deserializeStrArray(str);
        arr = new ContentHandlerImpl[strs.length];
        for (int i = 0; i < strs.length; i++) {
            arr[i] = deserializeCH(strs[i]);
        }

        return arr;
    
private static java.lang.String[]deserializeStrArray(java.lang.String str)
Transforms serialized form to array of Strings.
Serialization format is the same as ContentHandlerImpl used.

param
str String in serialized form to transform to array of Strings.
return
array of Strings. If input String is NULL 0-length array returned. ... And we believe that input string is not misformed.

        int n;          // array length
        String[] arr;   // result array

        n = (str == null || str.length() == 0)? 0: (int)str.charAt(0);

        arr = new String[n];
        if (n > 0) {
            int len;    // String len
            int pos;    // current position

            pos = 1;
            for (int i = 0; i < n; i++) {
                len = (int)str.charAt(pos++);
                arr[i] = str.substring(pos, pos+len);
                pos += len;
            }
        }

        return arr;
    
private native voidfinalize()
Cleanup native resources.

static ContentHandlerImpl[]findConflicted(java.lang.String testID)
Tests ID value for registering handler accordingly with JSR claim:
Each content handler is uniquely identified by an ID. ...
The ID MUST NOT be equal to any other registered handler ID.
Every other ID MUST NOT be a prefix of this ID.
The ID MUST NOT be a prefix of any other registered ID.

param
testID tested value
return
conflicted handlers array.

        return findHandler(null, FIELD_ID, testID);
    
static ContentHandlerImpl[]findHandler(java.lang.String callerId, int searchBy, java.lang.String value)
Searchs coontent handlers by searchable fields values. As specified in JSR 211 API:
Only content handlers that this application is allowed to access will be included. (in result).

param
callerId ID value to check access
param
searchBy indicator of searchable field. Allowed:
link
FIELD_TYPES, @link FIELD_SUFFIXES, @link FIELD_ACTIONS values. The special case for the testId implementation:
link
FIELD_ID specified.
param
value Searched value
return
found handlers array.

        /* Check value for null */
        value.length();
        String res = store.findHandler0(callerId, searchBy, value);
        return deserializeCHArray(res);
    
private native java.lang.StringfindHandler0(java.lang.String callerId, int searchBy, java.lang.String value)
Native implementation of findHandler.

param
callerId ID value to check access
param
searchBy index of searchable field.
param
value searched value
return
found handlers array in serialized form.

static ContentHandlerImpl[]forSuite(int suiteId)
The special finder for exploring handlers registered by the given suite.

param
suiteId explored suite Id
return
found handlers array.

        String res = store.forSuite0(suiteId);
        return deserializeCHArray(res);
    
private native java.lang.StringforSuite0(int suiteId)
Native implementation of findBySuite.

param
suiteId explored suite Id
return
handlers registered for the given suite in serialized form.

static java.lang.String[]getArrayField(java.lang.String handlerId, int fieldId)
Returns array field

param
handlerId ID for access check
param
fieldId index of field. Allowed:
link
FIELD_TYPES, @link FIELD_SUFFIXES, @link FIELD_ACTIONS
link
FIELD_LOCALES, @link FIELD_ACTION_MAP, @link FIELD_ACCESSES valiues.
return
array of values

        String res = store.loadFieldValues0(handlerId, fieldId);
        return deserializeStrArray(res);
    
static ContentHandlerImplgetByURL(java.lang.String callerId, java.lang.String url, java.lang.String action)
Returns content handler suitable for URL.

param
callerId ID of calling application.
param
URL content URL.
param
action requested action.
return
found handler if any or null.

        return deserializeCH(store.getByURL0(callerId, url, action));
    
private native java.lang.StringgetByURL0(java.lang.String callerId, java.lang.String url, java.lang.String action)
Returns content handler suitable for URL.

param
callerId ID of calling application.
param
URL content URL.
param
action requested action.
return
ID of found handler if any or null.

static ContentHandlerImplgetHandler(java.lang.String callerId, java.lang.String id, int searchMode)
Creates and loads handler's data.

param
handlerId ID of content handler to be loaded.
param
searchMode ID matching mode. Used
  • @link SEARCH_EXACT
  • @link SEARCH_PREFIX
return
loaded ContentHandlerImpl object or null if given handler ID is not found in Registry database.

        if (id.length() == 0) {
            return null;
        }

        return deserializeCH(store.getHandler0(callerId, id, searchMode));
    
static ContentHandlerImplgetHandler(int suiteId, java.lang.String classname)
The special finder for acquiring handler by its suite and class name.

param
suiteId explored suite Id
param
classname requested class name.
return
found handler or null if none found.

        ContentHandlerImpl[] arr = forSuite(suiteId);
        ContentHandlerImpl handler = null;

        if (classname.length() == 0)
            throw new IllegalArgumentException("classname can't be emty");

        if (arr != null) {
            for (int i = 0; i < arr.length; i++) {
                if (classname.equals(arr[i].classname)) {
                    handler = arr[i];
                    break;
                }
            }
        }

        return handler;
    
private native java.lang.StringgetHandler0(java.lang.String callerId, java.lang.String id, int mode)
Loads content handler data.

param
callerId ID value to check access.
param
id Id of required content handler.
param
mode flag defined search mode aplied for the operation.
return
serialized content handler or null.

static java.lang.String[]getValues(java.lang.String callerId, int searchBy)
Returns all stored in the Registry values for specified field.

param
callerId ID value to check access
param
searchBy index of searchable field. Allowed:
link
FIELD_TYPES, @link FIELD_SUFFIXES, @link FIELD_ACTIONS,
link
FIELD_ID values.
return
found values array.

        String res = store.getValues0(callerId, searchBy);
        return deserializeStrArray(res);
    
private native java.lang.StringgetValues0(java.lang.String callerId, int searchBy)
Native implementation of getValues.

param
callerId ID value to check access
param
searchBy index of searchable field.
return
found values in serialized form.

private native booleaninit()
Initialize persistence storage.

return
true or
false if initialization fails.

static booleanlaunch(ContentHandlerImpl handler)
Starts native content handler.

param
handler Content handler to be executed.
return
true if invoking app should exit.
exception
ContentHandlerException if no such handler ID in the Registry or native handlers execution is not supported.

        int result = store.launch0(handler.getID());
        if (result < 0) {
            throw new ContentHandlerException(
                        "Unable to launch platform handler",
                        ContentHandlerException.NO_REGISTERED_HANDLER);
        }

        return (result == LAUNCH_OK_SHOULD_EXIT);
    
private native intlaunch0(java.lang.String handlerId)
Starts native content handler.

param
handlerId ID of the handler to be executed
return
result status:
  • LAUNCH_OK or LAUNCH_OK_SHOULD_EXIT if content handler started successfully
  • other code from the LAUNCH_ERR_* constants set according to error codition

private native java.lang.StringloadFieldValues0(java.lang.String handlerId, int fieldId)
Loads values for array fields.

param
handlerId ID of content handler ID.
param
fieldId fieldId to be loaded.
return
loaded field values in serialized form.

static booleanregister(ContentHandlerImpl contentHandler)
Registers given content handler.

param
contentHandler content handler being registered.
return
true if success, false - otherwise.

                          
        
        return store.register0(contentHandler);
    
private native booleanregister0(ContentHandlerImpl contentHandler)
Registers given content handler.

param
contentHandler content handler being registered.
return
true if success, false - otherwise.

static voidsetSecurityToken(com.sun.midp.security.SecurityToken token)
Sets the security token used for priveleged operations. The token may only be set once.

param
token a Security token

        if (classSecurityToken != null) {
            throw new SecurityException();
        }
        classSecurityToken = token;
    
static booleanunregister(java.lang.String handlerId)
Unregisters content handler specified by its ID.

param
handlerId ID of unregistered handler.
return
true if success, false - otherwise.

        return store.unregister0(handlerId);
    
private native booleanunregister0(java.lang.String handlerId)
Unregisters content handler specified by its ID.

param
handlerId ID of unregistered handler.
return
true if success, false - otherwise.