/[gcjwebplugin]/gcjwebplugin/src/gnu/applet/AppletLoader.java
ViewVC logotype

Diff of /gcjwebplugin/src/gnu/applet/AppletLoader.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by mkoch, Sat Jul 12 10:02:51 2003 UTC revision 1.4 by mkoch, Sun Jul 13 13:01:33 2003 UTC
# Line 46  public class AppletLoader Line 46  public class AppletLoader
46  {  {
47    public static Applet loadApplet (URL codeBase, String appletName)    public static Applet loadApplet (URL codeBase, String appletName)
48    {    {
49        // FIXME: Remove DEBUG output
50        System.out.println ("AppletLoader.loadApplet: codeBase: " + codeBase + " appletName: " + appletName);
51    
52        Object applet = null;
53        
54      try      try
55        {        {
56          URLClassLoader loader = new URLClassLoader (new URL[] { codeBase });          URLClassLoader loader = new URLClassLoader (new URL[] { codeBase });
57          Class appletClass = loader.loadClass (appletName);          Class appletClass = loader.loadClass (appletName);
58          Object applet = appletClass.newInstance();          applet = appletClass.newInstance();
59    
60          if (!(applet instanceof Applet))          if (!(applet instanceof Applet))
61            throw new ClassCastException ("Loaded class is not derived from java.applet.Applet");            throw new ClassCastException ("Loaded class is not derived from java.applet.Applet");
   
         return (Applet) applet;  
62        }        }
63      catch (ClassNotFoundException e)      catch (ClassNotFoundException e)
64        {        {
65            e.printStackTrace();
66        }        }
67      catch (IllegalAccessException e)      catch (IllegalAccessException e)
68        {        {
69            e.printStackTrace();
70        }        }
71      catch (InstantiationException e)      catch (InstantiationException e)
72        {        {
73            e.printStackTrace();
74        }        }
75    
76      return null;      return (Applet) applet;;
77    }    }
78    
79    private String code;    private String code;
# Line 84  public class AppletLoader Line 90  public class AppletLoader
90    
91    public void setCode (String code)    public void setCode (String code)
92    {    {
93        if (code.endsWith (".class"))
94          {
95            code = code.substring (0, code.lastIndexOf (".class"));
96          }
97        
98      this.code = code;      this.code = code;
99    }    }
100    
101    public void setCodeBase (String codeBase)    public void setCodeBase (String base)
102    {    {
103      try      try
104        {        {
105          this.codeBase = new URL (codeBase);          if (!base.endsWith ("/"))
106              {
107                base = base.substring (0, base.lastIndexOf ('/') + 1);
108              }
109            
110            codeBase = new URL (base);
111        }        }
112      catch (MalformedURLException e)      catch (MalformedURLException e)
113        {        {
114        }        }
115    }    }
116    
117    public void setDocumentBase (String documentBase)    public void setDocumentBase (String base)
118    {    {
119      try      try
120        {        {
121          this.documentBase = new URL (documentBase);          documentBase = new URL (base);
122        }        }
123      catch (MalformedURLException e)      catch (MalformedURLException e)
124        {        {
125        }        }
126    
127        if (codeBase == null)
128          setCodeBase (base);
129    }    }
130    
131    public void setArchive (String archive)    public void setArchive (String archive)
# Line 121  public class AppletLoader Line 140  public class AppletLoader
140    
141    public synchronized Applet loadApplet()    public synchronized Applet loadApplet()
142    {    {
143      if (archive != null)      // Check if applet is already loaded.
144        return null;      if (applet != null)
145          return applet;
146    
147        // FIXME: Remove DEBUG output
148        System.out.println (code);
149        System.out.println (codeBase);
150        System.out.println (documentBase);
151        System.out.println (archive);
152            
153      applet = loadApplet (codeBase, code);      try
154      AppletContextImpl context = new AppletContextImpl();        {
155      AppletStubImpl stub = new AppletStubImpl (context, codeBase, documentBase,          applet = loadApplet (codeBase, code);
156                                                params);  
157      applet.setStub (stub);          // Return null when applet couldn't be loaded.
158            if (applet != null)
159              {
160                // Create AppletContext and AppletStub and set it.
161                AppletContextImpl context = new AppletContextImpl();
162                AppletStubImpl stub = new AppletStubImpl (context, codeBase,
163                                                          documentBase, params);
164                applet.setStub (stub);
165              }
166          }
167        catch (Exception e)
168          {
169            e.printStackTrace();
170          }
171    
172      return applet;      return applet;
173    }    }
174  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26