001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021/*********************************************************************
022 * Uses reflection to access JNLP services.
023 *
024 * @see
025 *   <a target="_blank"
026 *     href="http://croftsoft.com/library/tutorials/browser/">
027 *   Launching a Browser from Java</a>
028 *
029 * @version
030 *   2001-10-23
031 * @since
032 *   2001-08-31
033 * @author
034 *   <a href="http://croftsoft.com/">David Wallace Croft</a>
035 *********************************************************************/
036
037package org.biojava.nbio.structure.align.webstart;
038
039import java.lang.reflect.Method;
040import java.net.URL;
041
042
043public final class  JNLPProxy
044//////////////////////////////////////////////////////////////////////
045//////////////////////////////////////////////////////////////////////
046{
047
048private static final Object  basicServiceObject
049        = getBasicServiceObject ( );
050
051@SuppressWarnings("rawtypes")
052private static final Class   basicServiceClass
053        = getBasicServiceClass ( );
054
055//////////////////////////////////////////////////////////////////////
056//////////////////////////////////////////////////////////////////////
057
058public static void  main ( String [ ]  args )
059        throws Exception
060//////////////////////////////////////////////////////////////////////
061{
062        showDocument ( new URL ( args [ 0 ] ) );
063}
064
065//////////////////////////////////////////////////////////////////////
066//////////////////////////////////////////////////////////////////////
067
068@SuppressWarnings("unchecked")
069public static boolean  showDocument ( URL  url )
070//////////////////////////////////////////////////////////////////////
071{
072        if ( basicServiceObject == null )
073        {
074                        System.out.println("basisServiceObject = null");
075                        return false;
076        }
077
078        try
079        {
080                Method  method = basicServiceClass.getMethod (
081                        "showDocument", new Class [ ] { URL.class } );
082
083                Boolean  resultBoolean = ( Boolean )
084                        method.invoke ( basicServiceObject, new Object [ ] { url } );
085
086                boolean success = resultBoolean.booleanValue ( );
087                if ( ! success )
088                System.out.println("invocation of method failed!");
089                return success;
090        }
091        catch ( Exception  ex )
092        {
093                ex.printStackTrace ( );
094
095                throw new RuntimeException ( ex.getMessage ( ) );
096        }
097}
098
099//////////////////////////////////////////////////////////////////////
100//////////////////////////////////////////////////////////////////////
101
102@SuppressWarnings({ "unchecked" })
103private static Object  getBasicServiceObject ( )
104//////////////////////////////////////////////////////////////////////
105{
106        try
107        {
108                Class  serviceManagerClass
109                        = Class.forName ( "javax.jnlp.ServiceManager" );
110
111                Method  lookupMethod = serviceManagerClass.getMethod ( "lookup",
112                        new Class [ ] { String.class } );
113
114                return lookupMethod.invoke (
115                        null, new Object [ ] { "javax.jnlp.BasicService" } );
116        }
117        catch ( Exception  ex )
118        {
119                return null;
120        }
121}
122
123@SuppressWarnings("rawtypes")
124private static Class  getBasicServiceClass ( )
125//////////////////////////////////////////////////////////////////////
126{
127        try
128        {
129                return Class.forName ( "javax.jnlp.BasicService" );
130        }
131        catch ( Exception  ex )
132        {
133                return null;
134        }
135}
136
137//////////////////////////////////////////////////////////////////////
138//////////////////////////////////////////////////////////////////////
139
140private  JNLPProxy ( ) { }
141
142//////////////////////////////////////////////////////////////////////
143//////////////////////////////////////////////////////////////////////
144}
145