jdk/src/share/classes/com/sun/servicetag/BrowserSupport.java
author mchung
Thu, 02 Oct 2008 16:50:41 -0700
changeset 1327 912486b03832
child 5506 202f599c92aa
permissions -rw-r--r--
6581243: Service Tag and Product Registration Support in JDK 7 Summary: Include service tag creation and product registration support in JDK Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1327
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     1
/*
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     4
 *
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    10
 *
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    15
 * accompanied this code).
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    16
 *
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    20
 *
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    23
 * have any questions.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    24
 */
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    25
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    26
package com.sun.servicetag;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    27
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    28
import java.lang.reflect.Field;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    29
import java.lang.reflect.Method;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    30
import java.lang.reflect.InvocationTargetException;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    31
import java.io.IOException;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    32
import java.net.URI;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    33
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    34
/**
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    35
 * BrowserSupport class.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    36
 *
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    37
 * The implementation of the com.sun.servicetag API needs to be
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    38
 * compiled with JDK 5 as well since the consumer of this API
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    39
 * may require to support JDK 5 (e.g. NetBeans).
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    40
 *
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    41
 * The Desktop.browse() method can be backported in this class
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    42
 * if needed.  The current implementation only supports JDK 6.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    43
 */
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    44
class BrowserSupport {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    45
    private static boolean isBrowseSupported = false;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    46
    private static Method browseMethod = null;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    47
    private static Object desktop = null;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    48
    private static volatile Boolean result = false;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    49
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    50
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    51
    private static void initX() {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    52
        if  (desktop != null) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    53
            return;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    54
        }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    55
        boolean supported = false;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    56
        Method browseM = null;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    57
        Object desktopObj = null;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    58
        try {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    59
            // Determine if java.awt.Desktop is supported
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    60
            Class<?> desktopCls = Class.forName("java.awt.Desktop", true, null);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    61
            Method getDesktopM = desktopCls.getMethod("getDesktop");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    62
            browseM = desktopCls.getMethod("browse", URI.class);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    63
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    64
            Class<?> actionCls = Class.forName("java.awt.Desktop$Action", true, null);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    65
            final Method isDesktopSupportedMethod = desktopCls.getMethod("isDesktopSupported");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    66
            Method isSupportedMethod = desktopCls.getMethod("isSupported", actionCls);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    67
            Field browseField = actionCls.getField("BROWSE");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    68
            // isDesktopSupported calls getDefaultToolkit which can block
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    69
            // infinitely, see 6636099 for details, to workaround we call
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    70
            // in a  thread and time it out, noting that the issue is specific
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    71
            // to X11, it does not hurt for Windows.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    72
            Thread xthread = new Thread() {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    73
                public void run() {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    74
                    try {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    75
                        // support only if Desktop.isDesktopSupported() and
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    76
                        // Desktop.isSupported(Desktop.Action.BROWSE) return true.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    77
                        result = (Boolean) isDesktopSupportedMethod.invoke(null);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    78
                    } catch (IllegalAccessException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    79
                        // should never reach here
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    80
                        InternalError x =
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    81
                            new InternalError("Desktop.getDesktop() method not found");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    82
                        x.initCause(e);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    83
                    } catch (InvocationTargetException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    84
                        // browser not supported
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    85
                        if (Util.isVerbose()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    86
                            e.printStackTrace();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    87
                        }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    88
                    }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    89
                }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    90
            };
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    91
            // set it to daemon, so that the vm will exit.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    92
            xthread.setDaemon(true);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    93
            xthread.start();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    94
            try {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    95
                xthread.join(5 * 1000);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    96
            } catch (InterruptedException ie) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    97
                // ignore the exception
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    98
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
    99
            if (result.booleanValue()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   100
                desktopObj = getDesktopM.invoke(null);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   101
                result = (Boolean) isSupportedMethod.invoke(desktopObj, browseField.get(null));
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   102
                supported = result.booleanValue();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   103
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   104
        } catch (ClassNotFoundException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   105
            // browser not supported
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   106
            if (Util.isVerbose()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   107
                e.printStackTrace();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   108
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   109
        } catch (NoSuchMethodException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   110
            // browser not supported
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   111
            if (Util.isVerbose()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   112
                e.printStackTrace();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   113
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   114
        } catch (NoSuchFieldException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   115
            // browser not supported
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   116
            if (Util.isVerbose()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   117
                e.printStackTrace();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   118
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   119
        } catch (IllegalAccessException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   120
            // should never reach here
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   121
            InternalError x =
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   122
                    new InternalError("Desktop.getDesktop() method not found");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   123
            x.initCause(e);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   124
            throw x;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   125
        } catch (InvocationTargetException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   126
            // browser not supported
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   127
            if (Util.isVerbose()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   128
                e.printStackTrace();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   129
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   130
        }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   131
        isBrowseSupported = supported;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   132
        browseMethod = browseM;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   133
        desktop = desktopObj;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   134
    }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   135
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   136
    static boolean isSupported() {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   137
        initX();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   138
        return isBrowseSupported;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   139
    }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   140
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   141
    /**
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   142
     * Launches the default browser to display a {@code URI}.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   143
     * If the default browser is not able to handle the specified
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   144
     * {@code URI}, the application registered for handling
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   145
     * {@code URIs} of the specified type is invoked. The application
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   146
     * is determined from the protocol and path of the {@code URI}, as
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   147
     * defined by the {@code URI} class.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   148
     * <p>
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   149
     * This method calls the Desktop.getDesktop().browse() method.
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   150
     * <p>
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   151
     * @param uri the URI to be displayed in the user default browser
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   152
     *
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   153
     * @throws NullPointerException if {@code uri} is {@code null}
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   154
     * @throws UnsupportedOperationException if the current platform
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   155
     * does not support the {@link Desktop.Action#BROWSE} action
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   156
     * @throws IOException if the user default browser is not found,
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   157
     * or it fails to be launched, or the default handler application
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   158
     * failed to be launched
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   159
     * @throws IllegalArgumentException if the necessary permissions
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   160
     * are not available and the URI can not be converted to a {@code URL}
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   161
     */
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   162
    static void browse(URI uri) throws IOException {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   163
        if (uri == null) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   164
            throw new NullPointerException("null uri");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   165
        }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   166
        if (!isSupported()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   167
            throw new UnsupportedOperationException("Browse operation is not supported");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   168
        }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   169
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   170
        // Call Desktop.browse() method
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   171
        try {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   172
            if (Util.isVerbose()) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   173
                System.out.println("desktop: " + desktop + ":browsing..." + uri);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   174
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   175
            browseMethod.invoke(desktop, uri);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   176
        } catch (IllegalAccessException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   177
            // should never reach here
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   178
            InternalError x =
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   179
                new InternalError("Desktop.getDesktop() method not found");
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   180
            x.initCause(e);
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   181
                throw x;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   182
        } catch (InvocationTargetException e) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   183
            Throwable x = e.getCause();
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   184
            if (x != null) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   185
                if (x instanceof UnsupportedOperationException) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   186
                    throw (UnsupportedOperationException) x;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   187
                } else if (x instanceof IllegalArgumentException) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   188
                    throw (IllegalArgumentException) x;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   189
                } else if (x instanceof IOException) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   190
                    throw (IOException) x;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   191
                } else if (x instanceof SecurityException) {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   192
                    throw (SecurityException) x;
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   193
                } else {
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   194
                    // ignore
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   195
                }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   196
            }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   197
        }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   198
    }
912486b03832 6581243: Service Tag and Product Registration Support in JDK 7
mchung
parents:
diff changeset
   199
}