001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.jsr82;
028:
029: import com.sun.midp.io.j2me.push.ProtocolPush;
030: import com.sun.midp.jsr082.bluetooth.BluetoothPush;
031: import com.sun.kvem.jsr082.bluetooth.BCC;
032: import com.sun.kvem.jsr082.bluetooth.SDDB;
033: import com.sun.midp.midlet.MIDletSuite;
034: import com.sun.midp.security.Permissions;
035: import java.io.IOException;
036: import java.io.InterruptedIOException;
037:
038: /**
039: * Implementation of push behaviour.
040: */
041: public class ProtocolPushImpl extends ProtocolPush {
042:
043: /** Instance */
044: private static ProtocolPushImpl pushInstance;
045:
046: /**
047: * Get instance of this class.
048: * @return class instance
049: */
050: protected ProtocolPush getInstance() {
051: if (pushInstance == null) {
052: pushInstance = new ProtocolPushImpl();
053: }
054: return (ProtocolPush) pushInstance;
055: }
056:
057: /**
058: * Called when registration is checked.
059: * @param connection generic connection <em>protocol</em>, <em>host</em>
060: * and <em>port number</em>
061: * (optional parameters may be included
062: * separated with semi-colons (;))
063: * @param midlet class name of the <code>MIDlet</code> to be launched,
064: * when new external data is available
065: * @param filter a connection URL string indicating which senders
066: * are allowed to cause the MIDlet to be launched
067: * @exception IllegalArgumentException if the connection string is not
068: * valid
069: * @exception ClassNotFoundException if the <code>MIDlet</code> class
070: * name can not be found in the current
071: * <code>MIDlet</code> suite
072: */
073: public void checkRegistration(String connection, String midlet,
074: String filter) {
075: BluetoothPush.verifyUrl(connection);
076: BluetoothPush.verifyFilter(filter);
077: }
078:
079: /**
080: * Called when registration is established.
081: * @param midletSuite MIDlet suite for the suite registering,
082: * the suite only has to implement isRegistered,
083: * checkForPermission, and getID.
084: * @param connection generic connection <em>protocol</em>, <em>host</em>
085: * and <em>port number</em>
086: * (optional parameters may be included
087: * separated with semi-colons (;))
088: * @param midlet class name of the <code>MIDlet</code> to be launched,
089: * when new external data is available
090: * @param filter a connection URL string indicating which senders
091: * are allowed to cause the MIDlet to be launched
092: * @exception IllegalArgumentException if the connection string is not
093: * valid
094: * @exception IOException if the connection is already
095: * registered or if there are insufficient resources
096: * to handle the registration request
097: * @exception ClassNotFoundException if the <code>MIDlet</code> class
098: * name can not be found in the current
099: * <code>MIDlet</code> suite
100: */
101: public void registerConnection(MIDletSuite midletSuite,
102: String connection, String midlet, String filter)
103: throws IllegalArgumentException, IOException,
104: ClassNotFoundException {
105:
106: int index = connection.indexOf(':');
107: /* index > 0 because connection has been checked by ProtocolPush.getInstance() */
108: String protocol = connection.substring(0, index).toLowerCase();
109: int permission = -1;
110: if (protocol.equals("btspp") || protocol.equals("btl2cap")) {
111: permission = Permissions.BLUETOOTH_SERVER;
112: } else if (protocol.equals("btgoep")
113: || protocol.equals("irdaobex")) {
114: permission = Permissions.OBEX_SERVER;
115: } else if (protocol.equals("tcpobex")) {
116: permission = Permissions.TCP_OBEX_SERVER;
117: } else {
118: throw new IllegalArgumentException("Wrong protocol name "
119: + protocol);
120: }
121:
122: try {
123: midletSuite.checkForPermission(permission, connection);
124: } catch (InterruptedException ie) {
125: throw new InterruptedIOException(
126: "Interrupted while trying to ask the user permission");
127: }
128:
129: BluetoothPush.verifyUrl(connection);
130: BluetoothPush.verifyFilter(filter);
131: BluetoothPush.registerUrl(connection);
132: }
133: }
|