RegistryInstallerpublic final class RegistryInstaller extends Object Support for parsing attributes and installing from the
manifest or application descriptors. |
Fields Summary |
---|
private static final String | CH_PREFIXAttribute prefix for ContentHandler attributes. | private static final String | CH_ID_SUFFIXAttribute suffix for ContentHandler ID attribute. | private static final String | CH_ACCESS_SUFFIXAttribute suffix for ContentHandler visibility attribute. | private Vector | instHandlersParced handlers to be installed. | private Vector | remHandlersOld handlers to be removed. |
Methods Summary |
---|
private static java.util.Vector | getDelimSeparatedValues(java.lang.String input, char delim)Create a vector of values from a string containing delimiter separated
values. The values cannot contain the delimiter. The output values will
be trimmed of whitespace. The vector may contain zero length strings
where there are 2 delimiters in a row or a comma at the end of the input
string.
Vector output = new Vector(5, 5);
int len;
int start;
int end;
input = input.trim();
len = input.length();
if (len == 0) {
return output;
}
for (start = end = 0; end < len; ) {
// Skip leading spaces and control chars
while (start < len && (input.charAt(start) <= ' ")) {
start += 1;
}
// Scan for end delimiter (tab also if delim is space)
for (end = start; end < len; end++) {
char c = input.charAt(end);
if (c == delim || (c == '\t" && delim == ' ")) {
output.addElement(input.substring(start, end).trim());
start = end + 1;
break;
}
}
}
end = len;
output.addElement(input.substring(start, end).trim());
return output;
| void | install()Performs static installation (registration) the application
to handle the specified type and to provide a set of actions.
int i, sz;
// Remove static and conflicted handlers.
sz = (remHandlers == null? 0: remHandlers.size());
for (i = 0; i < sz; i++) {
ContentHandlerImpl handler =
(ContentHandlerImpl)remHandlers.elementAt(i);
RegistryStore.unregister(handler.getID());
}
// Install new handlers.
sz = (instHandlers == null? 0: instHandlers.size());
for (i = 0; i < sz; i++) {
ContentHandlerImpl handler =
(ContentHandlerImpl)instHandlers.elementAt(i);
RegistryStore.register(handler);
if (AppProxy.LOG_INFO) {
AppProxy.getCurrent().logInfo("Register: " +
handler.classname +
", id: " + handler.getID());
}
}
| private static javax.microedition.content.ActionNameMap[] | parseActionNames(java.lang.String[] actions, java.lang.String[] locales, java.lang.String prefix, AppProxy appl)Scan the available properties for the locale specific
attribute names and parse and The actionname maps for
each.
if (locales == null || locales.length == 0) {
return null;
}
prefix = prefix.concat("-");
Vector maps = new Vector();
for (int i = 0; i < locales.length; i++) {
String localeAttr = prefix.concat(locales[i]);
String localeValue = appl.getProperty(localeAttr);
if (localeValue == null) {
throw new IllegalArgumentException("missing locale");
}
String[] actionnames = split(localeValue, ',");
ActionNameMap map =
new ActionNameMap(actions, actionnames, locales[i]);
maps.addElement(map);
}
if (maps.size() > 0) {
ActionNameMap[] result = new ActionNameMap[maps.size()];
maps.copyInto(result);
return result;
} else {
return null;
}
| private static java.util.Vector | parseAttributes(AppProxy appl)Parse the ContentHandler attributes and check for errors.
Vector handlers = new Vector();
for (int index = 1; ; index++) {
String sindex = Integer.toString(index);
String handler_n = CH_PREFIX.concat(sindex);
String value = appl.getProperty(handler_n);
if (value == null) {
break;
}
String[] types = null;
String[] suffixes = null;
String[] actions = null;
String[] locales = null;
String classname;
String[] fields = split(value, ',");
switch (fields.length) {
case 5: // Has locales
locales = split(fields[4], ' ");
// Fall through
case 4: // Has actions
actions = split(fields[3], ' ");
// Fall through
case 3: // Has suffixes
suffixes = split(fields[2], ' ");
// Fall through
case 2: // Has types
// Parse out the types (if any)
types = split(fields[1], ' ");
// Fall through
case 1: // Has classname
classname = fields[0];
if (classname != null && classname.length() > 0) {
// Has non-empty classname
break;
}
// No classname, fall through to throw exception
case 0: // no nothing; error
default: // too many fields, error
throw
new IllegalArgumentException("Too many or too few fields");
}
// Get the application info for this new class;
// Throws ClassNotFoundException or IllegalArgumentException
AppProxy newAppl = appl.forClass(classname);
ActionNameMap[] actionnames =
parseActionNames(actions, locales, handler_n, newAppl);
// Parse the ID if any and the Access attribute
String idAttr = handler_n.concat(CH_ID_SUFFIX);
String id = newAppl.getProperty(idAttr);
String visAttr = handler_n.concat(CH_ACCESS_SUFFIX);
String visValue = newAppl.getProperty(visAttr);
String[] accessRestricted = split(visValue, ' ");
// Default the ID if not supplied
if (id == null) {
// Generate a unique ID based on the MIDlet suite
id = newAppl.getApplicationID();
}
// Now create the handler
ContentHandlerImpl handler =
new ContentHandlerImpl(types, suffixes, actions,
actionnames, id, accessRestricted,
newAppl.getAuthority());
// Fill in the non-public fields
handler.classname = classname;
handler.storageId = newAppl.getStorageId();
handler.appname = newAppl.getApplicationName();
handler.version = newAppl.getVersion();
/* Check new registration does not conflict with others. */
for (int i = 0; i < handlers.size(); i++) {
ContentHandlerImpl curr =
(ContentHandlerImpl)handlers.elementAt(i);
if (curr.classname.equals(handler.classname)) {
handlers.insertElementAt(handler, i);
handler = null;
break;
}
}
if (handler != null) { // not yet inserted
handlers.addElement(handler);
}
}
return handlers;
| int | preInstall(AppProxy appl)Parse the ContentHandler attributes and check for errors.
- Parse attributes into set of ContentHandlers.
- If none, return
- Check for permission to install handlers
- Check each for simple invalid arguments
- Check each for MIDlet is registered
- Check each for conflicts with other application registrations
- Find any current registrations
- Remove current dynamic registrations from set to be removed
- Check and resolve any conflicts between static and curr dynamic
int i, j, sz;
int suiteId = appl.getStorageId();
ContentHandlerImpl[] chs;
/*
* Check for any CHAPI attributes;
* if so, then the MIDlet suite must have permission.
*/
remHandlers = new Vector();
instHandlers = parseAttributes(appl);
/*
* Remove all static registrations.
*/
chs = RegistryStore.forSuite(suiteId);
sz = (chs == null? 0: chs.length);
for (i = 0; i < sz; i++) {
if (chs[i] == null)
continue;
if (chs[i].registrationMethod !=
ContentHandlerImpl.REGISTERED_STATIC) {
// Verify dynamic handler.
try {
// is it a valid application?
appl.verifyApplication(chs[i].classname);
// is there new handler to replace this one?
for (j = 0; j < instHandlers.size(); j++) {
ContentHandlerImpl handler =
(ContentHandlerImpl)instHandlers.elementAt(j);
if (handler.classname.equals(chs[i].classname)) {
throw new Throwable("Replace dynamic handler");
}
}
// The handler remains.
continue;
} catch(Throwable t) {
// Pass down to remove handler
}
}
// Remove handler -- either [static] or [replaced] or [invalid]
remHandlers.addElement(chs[i]);
chs[i] = null;
}
/* Verify new registrations */
for (i = 0; i < instHandlers.size(); i++) {
ContentHandlerImpl handler =
(ContentHandlerImpl)instHandlers.elementAt(i);
// Verify ID ...
// ... look through Registry
ContentHandlerImpl[] conf = RegistryStore.findConflicted(handler.ID);
if (conf != null) {
for (j = 0; j < conf.length; j++) {
if (conf[j].storageId != suiteId || !willRemove(conf[j].ID))
throw new ContentHandlerException(
"Content Handler ID: "+handler.ID,
ContentHandlerException.AMBIGUOUS);
}
}
// ... look through newbies
j = i;
while (j-- > 0) {
ContentHandlerImpl other =
(ContentHandlerImpl)instHandlers.elementAt(j);
if (handler.ID.startsWith(other.ID) ||
other.ID.startsWith(handler.ID)) {
throw new ContentHandlerException(
"Content Handler ID: "+handler.ID,
ContentHandlerException.AMBIGUOUS);
}
}
// Check permissions for each new handler
appl.checkRegisterPermission("register");
}
return instHandlers.size();
| static java.lang.String[] | split(java.lang.String string, char delim)Split the values in a field by delimiter and return a string array.
String[] ret = ContentHandlerImpl.ZERO_STRINGS;
if (string != null) {
Vector values = getDelimSeparatedValues(string, delim);
ret = new String[values.size()];
values.copyInto(ret);
}
return ret;
| static void | uninstallAll(int suiteId, boolean update)Performs static uninstallation (unregistration) of the application.
ContentHandlerImpl[] chs = RegistryStore.forSuite(suiteId);
for (int i = 0; i < chs.length; i++) {
if (!update || chs[i].registrationMethod ==
ContentHandlerImpl.REGISTERED_STATIC) {
RegistryStore.unregister(chs[i].getID());
}
}
| private boolean | willRemove(java.lang.String ID)
Enumeration en = remHandlers.elements();
while (en.hasMoreElements()) {
ContentHandlerImpl handler = (ContentHandlerImpl) en.nextElement();
if (handler.ID.equals(ID))
return true;
}
return false;
|
|