Java Doc for AppContext.java in  » 6.0-JDK-Modules » j2me » sun » awt » 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 » 6.0 JDK Modules » j2me » sun.awt 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   sun.awt.AppContext

AppContext
final public class AppContext (Code)
The AppContext is a table referenced by ThreadGroup which stores application service instances. (If you are not writing an application service, or don't know what one is, please do not use this class.) The AppContext allows applet access to what would otherwise be potentially dangerous services, such as the ability to peek at EventQueues or change the look-and-feel of a Swing application.

Most application services use a singleton object to provide their services, either as a default (such as getSystemEventQueue or getDefaultToolkit) or as static methods with class data (System). The AppContext works with the former method by extending the concept of "default" to be ThreadGroup-specific. Application services lookup their singleton in the AppContext.

For example, here we have a Foo service, with its pre-AppContext code:

 public class Foo {
 private static Foo defaultFoo = new Foo();
 public static Foo getDefaultFoo() {
 return defaultFoo;
 }
 ... Foo service methods
 }

The problem with the above is that the Foo service is global in scope, so that applets and other untrusted code can execute methods on the single, shared Foo instance. The Foo service therefore either needs to block its use by untrusted code using a SecurityManager test, or restrict its capabilities so that it doesn't matter if untrusted code executes it.

Here's the Foo class written to use the AppContext:

 public class Foo {
 public static Foo getDefaultFoo() {
 Foo foo = (Foo)AppContext.getAppContext().get(Foo.class);
 if (foo == null) {
 foo = new Foo();
 getAppContext().put(Foo.class, foo);
 }
 return foo;
 }
 ... Foo service methods
 }

Since a separate AppContext can exist for each ThreadGroup, trusted and untrusted code have access to different Foo instances. This allows untrusted code access to "system-wide" services -- the service remains within the AppContext "sandbox". For example, say a malicious applet wants to peek all of the key events on the EventQueue to listen for passwords; if separate EventQueues are used for each ThreadGroup using AppContexts, the only key events that applet will be able to listen to are its own. A more reasonable applet request would be to change the Swing default look-and-feel; with that default stored in an AppContext, the applet's look-and-feel will change without disrupting other applets or potentially the browser itself.

Because the AppContext is a facility for safely extending application service support to applets, none of its methods may be blocked by a a SecurityManager check in a valid Java implementation. Applets may therefore safely invoke any of its methods without worry of being blocked. Note: If a SecurityManager is installed which derives from sun.awt.AWTSecurityManager, it may override the AWTSecurityManager.getAppContext() method to return the proper AppContext based on the execution context, in the case where the default ThreadGroup-based AppContext indexing would return the main "system" AppContext. For example, in an applet situation, if a system thread calls into an applet, rather than returning the main "system" AppContext (the one corresponding to the system thread), an installed AWTSecurityManager may return the applet's AppContext based on the execution context.
author:
   Thomas Ball
author:
   Fred Ecks
version:
   1.35 10/10/06



Field Summary
final public static  StringDISPOSED_PROPERTY_NAME
     If any PropertyChangeListeners have been registered, the changeSupport field describes them.
final public static  ObjectEVENT_QUEUE_KEY
    

Constructor Summary
 AppContext(ThreadGroup threadGroup)
     Constructor for AppContext.

Method Summary
public  voiddispose()
     Disposes of this AppContext, all of its top-level Frames, and all Threads and ThreadGroups contained within it.
public  Objectget(Object key)
     Returns the value to which the specified key is mapped in this context.
Parameters:
  key - a key in the AppContext.
final public static  AppContextgetAppContext()
     Returns the appropriate AppContext for the caller, as determined by its ThreadGroup.
public  ClassLoadergetContextClassLoader()
     Returns the context ClassLoader that was used to create this AppContext.
public  ThreadGroupgetThreadGroup()
     Returns the root ThreadGroup for all Threads contained within this AppContext.
public  booleanisDisposed()
    
public  Objectput(Object key, Object value)
     Maps the specified key to the specified value in this AppContext.
public  Objectremove(Object key)
     Removes the key (and its corresponding value) from this AppContext.
public  StringtoString()
     Returns a string representation of this AppContext.

Field Detail
DISPOSED_PROPERTY_NAME
final public static String DISPOSED_PROPERTY_NAME(Code)
If any PropertyChangeListeners have been registered, the changeSupport field describes them.
See Also:   AppContext.addPropertyChangeListener
See Also:   AppContext.removePropertyChangeListener
See Also:   AppContext.firePropertyChange
See Also:   private PropertyChangeSupport changeSupport = null;



EVENT_QUEUE_KEY
final public static Object EVENT_QUEUE_KEY(Code)




Constructor Detail
AppContext
AppContext(ThreadGroup threadGroup)(Code)
Constructor for AppContext. This method is not public, nor should it ever be used as such. The proper way to construct an AppContext is through the use of SunToolkit.createNewAppContext. A ThreadGroup is created for the new AppContext, a Thread is created within that ThreadGroup, and that Thread calls SunToolkit.createNewAppContext before calling anything else. That creates both the new AppContext and its EventQueue.
Parameters:
  threadGroup - The ThreadGroup for the new AppContext
See Also:   sun.awt.SunToolkit
since:
   JDK1.2




Method Detail
dispose
public void dispose() throws IllegalThreadStateException(Code)
Disposes of this AppContext, all of its top-level Frames, and all Threads and ThreadGroups contained within it. This method must be called from a Thread which is not contained within this AppContext.
exception:
  IllegalThreadStateException - if the current thread iscontained within this AppContext
since:
   JDK1.2



get
public Object get(Object key)(Code)
Returns the value to which the specified key is mapped in this context.
Parameters:
  key - a key in the AppContext. the value to which the key is mapped in this AppContext;null if the key is not mapped to any value.
See Also:   AppContext.put(Object,Object)
since:
   JDK1.2



getAppContext
final public static AppContext getAppContext()(Code)
Returns the appropriate AppContext for the caller, as determined by its ThreadGroup. If the main "system" AppContext would be returned and there's an AWTSecurityManager installed, it is called to get the proper AppContext based on the execution context. the AppContext for the caller.
See Also:   java.lang.ThreadGroup
since:
   JDK1.2



getContextClassLoader
public ClassLoader getContextClassLoader()(Code)
Returns the context ClassLoader that was used to create this AppContext.
See Also:   java.lang.Thread.getContextClassLoader



getThreadGroup
public ThreadGroup getThreadGroup()(Code)
Returns the root ThreadGroup for all Threads contained within this AppContext.
since:
   JDK1.2



isDisposed
public boolean isDisposed()(Code)



put
public Object put(Object key, Object value)(Code)
Maps the specified key to the specified value in this AppContext. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.
Parameters:
  key - the AppContext key.
Parameters:
  value - the value. the previous value of the specified key in this AppContext, or null if it did not have one.
exception:
  NullPointerException - if the key or value isnull.
See Also:   AppContext.get(Object)
since:
   JDK1.2




remove
public Object remove(Object key)(Code)
Removes the key (and its corresponding value) from this AppContext. This method does nothing if the key is not in the AppContext.
Parameters:
  key - the key that needs to be removed. the value to which the key had been mapped in this AppContext,or null if the key did not have a mapping.
since:
   JDK1.2



toString
public String toString()(Code)
Returns a string representation of this AppContext.
since:
   JDK1.2



Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.