harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r618600 - in /harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer: AppletFrame.java AppletInfo.java HTMLParser.java ViewerAppletContext.java ViewerAudioClip.java
Date Tue, 05 Feb 2008 10:28:37 GMT
Author: ayza
Date: Tue Feb  5 02:28:33 2008
New Revision: 618600

URL: http://svn.apache.org/viewvc?rev=618600&view=rev
Log:
Patch from HARMONY-5457 ([jdktools][appletviewer] appletviewer's methods getApplet and getApplets
don't implemented) was applied

Modified:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java?rev=618600&r1=618599&r2=618600&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java
Tue Feb  5 02:28:33 2008
@@ -23,8 +23,6 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
-import java.net.URLClassLoader;
-import java.net.URL;
 import java.util.HashSet;
 
 import javax.swing.AbstractAction;
@@ -38,32 +36,18 @@
 import javax.swing.SwingConstants;
 
 class AppletFrame extends JFrame {
-    private final AppletInfo appletInfo;
     private final Applet applet;
     private final JLabel statusLabel;
     
     private static ShutdownHandler shutdownHandler = new ShutdownHandler();
     
     public AppletFrame(AppletInfo appletInfo) throws Exception {
-        this.appletInfo = appletInfo;
-        String code = this.appletInfo.getCode();
-        if(code == null || code.equals("")){
-            System.err.println("Warning: <" + appletInfo.getTag() +"> tag requires
code attribute.");
-            System.exit(0);
-        }
-
-        shutdownHandler.addFrame(this);
-        
         // Load applet class
-        if(appletInfo.getCodeBase() == null){
-            appletInfo.setCodeBase(new URL(appletInfo.getDocumentBase(), "./"));
-        }
+        applet = ViewerAppletContext.loadApplet(appletInfo);
 
-        URLClassLoader cl = new URLClassLoader(appletInfo.getClassLoaderURLs());
-        Class clz = cl.loadClass(code);
-        applet = (Applet)clz.newInstance();
-        applet.setStub(new ViewerAppletStub(applet, appletInfo));
         applet.setPreferredSize(new Dimension(appletInfo.getWidth(), appletInfo.getHeight()));
+
+        shutdownHandler.addFrame(this);
         
         // Create menu bar
         setJMenuBar(createMenu());
@@ -109,6 +93,10 @@
     	
     	return menuBar;
     }
+
+    Applet getApplet(){
+        return applet;
+    }
     
     private class StartAction extends  AbstractAction {
     	public StartAction() {
@@ -163,7 +151,16 @@
         }
 
         public void windowClosing(WindowEvent e) {
-            frameList.remove(e.getWindow());
+            JFrame frame = (JFrame)e.getWindow();
+            frameList.remove(frame);
+
+            Applet applet = ((AppletFrame)frame).getApplet();
+            if(applet != null){
+                ViewerAppletContext ac = 
+                    (ViewerAppletContext)applet.getAppletContext();
+                ac.remove(applet);
+            }
+
             if (frameList.isEmpty())
                 System.exit(0);
         }
@@ -184,5 +181,7 @@
             frameList.add(frame);
             frame.addWindowListener(this);
         }
+
     }
+
 }

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java?rev=618600&r1=618599&r2=618600&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/AppletInfo.java
Tue Feb  5 02:28:33 2008
@@ -31,7 +31,6 @@
     private URL codeBase;
     private URL archive;
     private String archiveStr;
-    private String code;
     private String tagName;
     private int width;
     private int height;
@@ -76,10 +75,6 @@
         this.archive = archive;
     }
 
-    public void setArchive(String archive) {
-        this.archiveStr = archive;
-    }
-
     public String getParameter(String name) {
         return params.get(name.toUpperCase());
     }
@@ -88,14 +83,6 @@
         params.put(name.toUpperCase(), value);
     }
 
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = (code.endsWith(".class"))?code.substring(0, code.length()-6):code;
-    }
-
     public int getWidth() {
         return width;
     }
@@ -130,6 +117,7 @@
     }
     
     public URL []getClassLoaderURLs() {
+        archiveStr = getParameter("ARCHIVE");
     	URL []res = (archive == null && archiveStr == null)?new URL[1]:new URL[2];
     	switch (res.length) {
     		case 2: res[1] = getArchive();

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java?rev=618600&r1=618599&r2=618600&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/HTMLParser.java
Tue Feb  5 02:28:33 2008
@@ -94,22 +94,13 @@
                 appletInfo.setDocumentBase(documentBase);
        
                 SimpleAttributeSet attributes = getAttributes();
-                appletInfo.setWidth((String)attributes.getAttribute(HTML.Attribute.WIDTH));
-                appletInfo.setHeight((String)attributes.getAttribute(HTML.Attribute.HEIGHT));
 
-                appletInfo.setArchive((String)attributes.getAttribute(HTML.Attribute.ARCHIVE));
+                appletInfo.setParameter("WIDTH", (String)attributes.getAttribute(HTML.Attribute.WIDTH));

+                appletInfo.setParameter("HEIGHT", (String)attributes.getAttribute(HTML.Attribute.HEIGHT));
+                appletInfo.setParameter("CODE", (String)attributes.getAttribute(HTML.Attribute.CODE));
+                appletInfo.setParameter("CODEBASE", (String)attributes.getAttribute(HTML.Attribute.CODEBASE));
+                appletInfo.setParameter("ARCHIVE", (String)attributes.getAttribute(HTML.Attribute.ARCHIVE));
 
-                try {
-                    appletInfo.setCode((String)attributes.getAttribute(HTML.Attribute.CODE));
-                } catch (Exception e) {}
-
-                if (htmlTag == HTML.Tag.APPLET) {
-                    try {
-                        appletInfo.setCodeBase((String)attributes.getAttribute(HTML.Attribute.CODEBASE));
-                    } catch (Exception e) {
-                        appletInfo.setCodeBase((URL)null);
-                    }
-                }
             }           
         }
 
@@ -125,13 +116,10 @@
             HTML.Tag htmlTag = tag.getHTMLTag();
             if (appletInfo != null && htmlTag == HTML.Tag.PARAM) {
                 SimpleAttributeSet attributes = getAttributes();
-                String name = (String)attributes.getAttribute(HTML.Attribute.NAME);
-                if(name.equalsIgnoreCase("code")){
-                    appletInfo.setCode((String)attributes.getAttribute(HTML.Attribute.VALUE));
-                } else {
-                    appletInfo.setParameter(name, (String)attributes.getAttribute(HTML.Attribute.VALUE));
-                }
+                appletInfo.setParameter((String)attributes.getAttribute(HTML.Attribute.NAME),

+                    (String)attributes.getAttribute(HTML.Attribute.VALUE));
             }
+
         }
     }
 }

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java?rev=618600&r1=618599&r2=618600&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAppletContext.java
Tue Feb  5 02:28:33 2008
@@ -25,24 +25,80 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Vector;
 
 class ViewerAppletContext implements AppletContext {
+    private static final HashMap<String, Applet> namedApplets = new HashMap<String,
Applet>();
+    private static final Vector<Applet> applets = new Vector<Applet>(1, 1);
+    private static final HashMap<URL, ViewerClassLoader> loaders = 
+        new HashMap<URL, ViewerClassLoader>();
+
     private final AppletInfo appletInfo;
 
+    static Applet loadApplet(AppletInfo appletInfo) throws Exception {
+
+        String width = appletInfo.getParameter("WIDTH");
+        if(width != null) {
+            appletInfo.setWidth(width);
+        } else {
+            System.err.println("Warning: <" + appletInfo.getTag() +"> tag requires
width attribute.");
+            System.exit(-1);
+        }
+
+        String heigth = appletInfo.getParameter("HEIGHT");
+        if(heigth != null) {
+            appletInfo.setHeight(heigth);
+        } else {
+            System.err.println("Warning: <" + appletInfo.getTag() +"> tag requires
height attribute.");
+            System.exit(-1);
+        }
+  
+        String code = appletInfo.getParameter("CODE");
+        if(code == null || code.equals("")){
+            System.err.println("Warning: <" + appletInfo.getTag() +"> tag requires
code attribute.");
+            System.exit(0);
+        }
+
+        code = (code.endsWith(".class"))?code.substring(0, code.length()-6):code;
+        
+        appletInfo.setCodeBase(appletInfo.getParameter("CODEBASE"));
+
+        URL codeBase = appletInfo.getCodeBase();
+
+        ViewerClassLoader loader = loaders.get(codeBase);
+        if(loader == null){
+            loader = new ViewerClassLoader();
+            loaders.put(codeBase, loader);
+        }
+
+        loader.addURLs(appletInfo.getClassLoaderURLs());
+        Class clz = loader.loadClass(code);
+        Applet applet = (Applet)clz.newInstance();
+
+        applets.add(applet);
+
+        String name = appletInfo.getParameter("NAME");
+        if(name != null && name != "") namedApplets.put(name, applet);
+
+        applet.setStub(new ViewerAppletStub(applet, appletInfo));
+
+        return applet;
+    }
+
     public ViewerAppletContext(AppletInfo appletInfo) {
         this.appletInfo = appletInfo;
     }
 
     public Applet getApplet(String name) {
-        // TODO Auto-generated method stub
-        return null;
+        return namedApplets.get(name);
     }
 
     public Enumeration<Applet> getApplets() {
-        // TODO Auto-generated method stub
-        return null;
+        return applets.elements();
     }
 
     public AudioClip getAudioClip(URL url) {
@@ -80,5 +136,43 @@
 
     public void showStatus(String status) {
         appletInfo.setStatus(status);
+    }
+
+    void remove(Applet applet){
+        String name = applet.getParameter("NAME");
+        synchronized(namedApplets){
+            namedApplets.remove(name);
+        }
+
+        synchronized(applets){
+            applets.remove(applet);
+        }
+    }
+
+    private static class ViewerClassLoader extends URLClassLoader{
+
+        public ViewerClassLoader(){
+            super(new URL[0]);
+        }
+
+        public void addURL(URL url){
+            URL[] urls = getURLs();
+            boolean exists = false;
+            for(int i = 0; i < urls.length; i++){
+                if(urls[i].equals(url)){
+                    exists = true;
+                    break;
+                }
+            }
+            if(!exists) super.addURL(url);
+        }
+
+        public void addURLs(URL[] urls){
+            if(urls == null) return;
+            for(int i = 0; i < urls.length; i++){
+                addURL(urls[i]);
+            }
+        }
+
     }
 }

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java?rev=618600&r1=618599&r2=618600&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/appletviewer/ViewerAudioClip.java
Tue Feb  5 02:28:33 2008
@@ -37,9 +37,7 @@
         try {
             ais = AudioSystem.getAudioInputStream(url);
         } catch (Exception e) {
-            System.out.println(url.toString());
             e.printStackTrace();
-            ais = null;
             return;
         }
         af = ais.getFormat();



Mime
View raw message