001         package com.croftsoft.core.jnlp;
002    
003         import java.lang.reflect.*;
004         import java.net.*;
005    
006         /*********************************************************************
007         * Uses reflection to access JNLP services.
008         *
009         * @see
010         *   <a target="_blank" 
011         *     href="https://www.croftsoft.com/library/tutorials/browser/">
012         *   Launching a Browser from Java</a>
013         *
014         * @version
015         *   2001-10-23
016         * @since
017         *   2001-08-31
018         * @author
019         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
020         *********************************************************************/
021    
022         public final class  JnlpProxy
023         //////////////////////////////////////////////////////////////////////
024         //////////////////////////////////////////////////////////////////////
025         {
026    
027         private static final Object  basicServiceObject
028           = getBasicServiceObject ( );
029    
030         private static final Class   basicServiceClass
031           = getBasicServiceClass ( );
032    
033         //////////////////////////////////////////////////////////////////////
034         //////////////////////////////////////////////////////////////////////
035    
036         public static void  main ( String [ ]  args )
037           throws Exception
038         //////////////////////////////////////////////////////////////////////
039         {
040           showDocument ( new URL ( args [ 0 ] ) );
041         }
042    
043         //////////////////////////////////////////////////////////////////////
044         //////////////////////////////////////////////////////////////////////
045    
046         public static boolean  showDocument ( URL  url )
047         //////////////////////////////////////////////////////////////////////
048         {
049           if ( basicServiceObject == null )
050           {
051             return false;
052           }
053    
054           try
055           {
056             Method  method = basicServiceClass.getMethod (
057               "showDocument", new Class [ ] { URL.class } );
058    
059             Boolean  resultBoolean = ( Boolean )
060               method.invoke ( basicServiceObject, new Object [ ] { url } );
061    
062             return resultBoolean.booleanValue ( );
063           }
064           catch ( Exception  ex )
065           {
066             ex.printStackTrace ( );
067    
068             throw new RuntimeException ( ex.getMessage ( ) );
069           }
070         }
071    
072         //////////////////////////////////////////////////////////////////////
073         //////////////////////////////////////////////////////////////////////
074    
075         private static Object  getBasicServiceObject ( )
076         //////////////////////////////////////////////////////////////////////
077         {
078           try
079           {
080             Class  serviceManagerClass
081               = Class.forName ( "javax.jnlp.ServiceManager" );
082    
083             Method  lookupMethod = serviceManagerClass.getMethod ( "lookup",
084               new Class [ ] { String.class } );
085    
086             return lookupMethod.invoke (
087               null, new Object [ ] { "javax.jnlp.BasicService" } );
088           }
089           catch ( Exception  ex )
090           {
091             return null;
092           }
093         }
094    
095         private static Class  getBasicServiceClass ( )
096         //////////////////////////////////////////////////////////////////////
097         {
098           try
099           {
100             return Class.forName ( "javax.jnlp.BasicService" );
101           }
102           catch ( Exception  ex )
103           {
104             return null;
105           }
106         }
107    
108         //////////////////////////////////////////////////////////////////////
109         //////////////////////////////////////////////////////////////////////
110    
111         private  JnlpProxy ( ) { }
112    
113         //////////////////////////////////////////////////////////////////////
114         //////////////////////////////////////////////////////////////////////
115         }