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