Source Code Cross Referenced for ViewerAppletContext.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » tools » appletviewer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.tools.appletviewer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.tools.appletviewer;
019:
020:        import java.applet.Applet;
021:        import java.applet.AppletContext;
022:        import java.applet.AudioClip;
023:        import java.awt.Image;
024:        import java.awt.Toolkit;
025:        import java.io.IOException;
026:        import java.io.InputStream;
027:        import java.net.URL;
028:        import java.net.URLClassLoader;
029:        import java.util.Enumeration;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.Vector;
033:
034:        class ViewerAppletContext implements  AppletContext {
035:            private static final HashMap<String, Applet> namedApplets = new HashMap<String, Applet>();
036:            private static final Vector<Applet> applets = new Vector<Applet>(1,
037:                    1);
038:            private static final HashMap<URL, ViewerClassLoader> loaders = new HashMap<URL, ViewerClassLoader>();
039:
040:            private final AppletInfo appletInfo;
041:
042:            static Applet loadApplet(AppletInfo appletInfo) throws Exception {
043:
044:                String width = appletInfo.getParameter("WIDTH");
045:                if (width != null) {
046:                    appletInfo.setWidth(width);
047:                } else {
048:                    System.err.println("Warning: <" + appletInfo.getTag()
049:                            + "> tag requires width attribute.");
050:                    System.exit(-1);
051:                }
052:
053:                String heigth = appletInfo.getParameter("HEIGHT");
054:                if (heigth != null) {
055:                    appletInfo.setHeight(heigth);
056:                } else {
057:                    System.err.println("Warning: <" + appletInfo.getTag()
058:                            + "> tag requires height attribute.");
059:                    System.exit(-1);
060:                }
061:
062:                String code = appletInfo.getParameter("CODE");
063:                if (code == null || code.equals("")) {
064:                    System.err.println("Warning: <" + appletInfo.getTag()
065:                            + "> tag requires code attribute.");
066:                    System.exit(0);
067:                }
068:
069:                code = (code.endsWith(".class")) ? code.substring(0, code
070:                        .length() - 6) : code;
071:
072:                appletInfo.setCodeBase(appletInfo.getParameter("CODEBASE"));
073:
074:                URL codeBase = appletInfo.getCodeBase();
075:
076:                ViewerClassLoader loader = loaders.get(codeBase);
077:                if (loader == null) {
078:                    loader = new ViewerClassLoader();
079:                    loaders.put(codeBase, loader);
080:                }
081:
082:                loader.addURLs(appletInfo.getClassLoaderURLs());
083:                Class clz = loader.loadClass(code);
084:                Applet applet = (Applet) clz.newInstance();
085:
086:                applets.add(applet);
087:
088:                String name = appletInfo.getParameter("NAME");
089:                if (name != null && name != "")
090:                    namedApplets.put(name, applet);
091:
092:                applet.setStub(new ViewerAppletStub(applet, appletInfo));
093:
094:                return applet;
095:            }
096:
097:            public ViewerAppletContext(AppletInfo appletInfo) {
098:                this .appletInfo = appletInfo;
099:            }
100:
101:            public Applet getApplet(String name) {
102:                return namedApplets.get(name);
103:            }
104:
105:            public Enumeration<Applet> getApplets() {
106:                return applets.elements();
107:            }
108:
109:            public AudioClip getAudioClip(URL url) {
110:                return new ViewerAudioClip(url);
111:            }
112:
113:            public Image getImage(URL url) {
114:                return Toolkit.getDefaultToolkit().createImage(url);
115:            }
116:
117:            public InputStream getStream(String key) {
118:                // TODO Auto-generated method stub
119:                return null;
120:            }
121:
122:            public Iterator<String> getStreamKeys() {
123:                // TODO Auto-generated method stub
124:                return null;
125:            }
126:
127:            public void setStream(String key, InputStream stream)
128:                    throws IOException {
129:                // TODO Auto-generated method stub
130:
131:            }
132:
133:            public void showDocument(URL url) {
134:                // TODO Auto-generated method stub
135:
136:            }
137:
138:            public void showDocument(URL url, String target) {
139:                // TODO Auto-generated method stub
140:
141:            }
142:
143:            public void showStatus(String status) {
144:                appletInfo.setStatus(status);
145:            }
146:
147:            void remove(Applet applet) {
148:                String name = applet.getParameter("NAME");
149:                synchronized (namedApplets) {
150:                    namedApplets.remove(name);
151:                }
152:
153:                synchronized (applets) {
154:                    applets.remove(applet);
155:                }
156:            }
157:
158:            private static class ViewerClassLoader extends URLClassLoader {
159:
160:                public ViewerClassLoader() {
161:                    super (new URL[0]);
162:                }
163:
164:                public void addURL(URL url) {
165:                    URL[] urls = getURLs();
166:                    boolean exists = false;
167:                    for (int i = 0; i < urls.length; i++) {
168:                        if (urls[i].equals(url)) {
169:                            exists = true;
170:                            break;
171:                        }
172:                    }
173:                    if (!exists)
174:                        super .addURL(url);
175:                }
176:
177:                public void addURLs(URL[] urls) {
178:                    if (urls == null)
179:                        return;
180:                    for (int i = 0; i < urls.length; i++) {
181:                        addURL(urls[i]);
182:                    }
183:                }
184:
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.