01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.content;
28:
29: import com.sun.midp.log.*;
30: import javax.microedition.midlet.MIDlet;
31: import javax.microedition.content.*;
32:
33: /**
34: * The tool for start given Content Handler from the platform.
35: */
36: class Invoker extends MIDlet implements Runnable {
37:
38: Registry r;
39:
40: /**
41: * Default constructor.
42: */
43: public Invoker() {
44: r = Registry.getRegistry(this .getClass().getName());
45: new Thread(this ).start();
46: }
47:
48: /**
49: * Standard MIDlet life-cycle call-back.
50: */
51: protected void startApp() {
52: }
53:
54: /**
55: * Standard MIDlet life-cycle call-back.
56: */
57: protected void pauseApp() {
58: }
59:
60: /**
61: * Standard MIDlet life-cycle call-back.
62: */
63: protected void destroyApp(boolean unconditional) {
64: }
65:
66: /**
67: * Loads Invocation parameters.
68: * According current implementation Invocation parameters consist of
69: * <ContentHandlerID>, <URL> and <Type> command line arguments provided
70: * for this MIDlet.
71: */
72: private Invocation getNativeInvocation() {
73: String id = getAppProperty("arg-0");
74: String url = getAppProperty("arg-1");
75: String action = getAppProperty("arg-2"); /* optional */
76: String type = null;
77: boolean responseRequired = false;
78:
79: return new Invocation(url, type, id, responseRequired, action);
80: }
81:
82: /**
83: * Actual handler invoking is performed in the separated thread.
84: */
85: public void run() {
86: Invocation i = getNativeInvocation();
87: try {
88: r.invoke(i);
89: } catch (Throwable t) {
90: Logging
91: .report(Logging.ERROR, LogChannels.LC_AMS,
92: "Exception during invoking native invocation: "
93: + t);
94: }
95: notifyDestroyed();
96: }
97: }
|