Java Doc for WikiEventManager.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » event » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.event 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.ecyrd.jspwiki.event.WikiEventManager

WikiEventManager
final public class WikiEventManager (Code)
A singleton class that manages the addition and removal of WikiEvent listeners to a event source, as well as the firing of events to those listeners. An "event source" is the object delegating its event handling to an inner delegating class supplied by this manager. The class being serviced is considered a "client" of the delegate. The WikiEventManager operates across any number of simultaneously-existing WikiEngines since it manages all delegation on a per-object basis. Anything that might fire a WikiEvent (or any of its subclasses) can be a client.

Using a Delegate for Event Listener Management

Basically, rather than have all manner of client classes maintain their own listener lists, add and remove listener methods, any class wanting to attach listeners can simply request a delegate object to provide that service. The delegate handles the listener list, the add and remove listener methods. Firing events is then a matter of calling the WikiEventManager's WikiEventManager.fireEvent(Object,WikiEvent) method, where the Object is the client. Prior to instantiating the event object, the client can call WikiEventManager.isListening(Object) to see there are any listeners attached to its delegate.

Adding Listeners

Adding a WikiEventListener to an object is very simple:

 WikiEventManager.addWikiEventListener(object,listener);
 

Removing Listeners

Removing a WikiEventListener from an object is very simple:

 WikiEventManager.removeWikiEventListener(object,listener);
 
If you only have a reference to the listener, the following method will remove it from any clients managed by the WikiEventManager:
 WikiEventManager.removeWikiEventListener(listener);
 

Backward Compatibility: Replacing Existing fireEvent() Methods

Using one manager for all events processing permits consolidation of all event listeners and their associated methods in one place rather than having them attached to specific subcomponents of an application, and avoids a great deal of event-related cut-and-paste code. Convenience methods that call the WikiEventManager for event delegation can be written to maintain existing APIs.

For example, an existing fireEvent() method might look something like this:

 protected final void fireEvent( WikiEvent event )
 {
 for ( Iterator it = m_listeners.iterator(); it.hasNext(); )
 {
 WikiEventListener listener = (WikiEventListener)it.next();
 listener.actionPerformed(event);
 }
 }
 

One disadvantage is that the above method is supplied with event objects, which are created even when no listener exists for them. In a busy wiki with many users unused/unnecessary event creation could be considerable. Another advantage is that in addition to the iterator, there must be code to support the addition and remove of listeners. The above could be replaced with the below code (and with no necessary local support for adding and removing listeners):

 protected final void fireEvent( int type )
 {
 if ( WikiEventManager.isListening(this) )
 {
 WikiEventManager.fireEvent(this,new WikiEngineEvent(this,type));
 }
 }
 

This only needs to be customized to supply the specific parameters for whatever WikiEvent you want to create.

Preloading Listeners

This may be used to create listeners for objects that don't yet exist, particularly designed for embedded applications that need to be able to listen for the instantiation of an Object, by maintaining a cache of client-less WikiEvent sources that set their client upon being popped from the cache. Each time any of the methods expecting a client parameter is called with a null parameter it will preload an internal cache with a client-less delegate object that will be popped and returned in preference to creating a new object. This can have unwanted side effects if there are multiple clients populating the cache with listeners. The only check is for a Class match, so be aware if others might be populating the client-less cache with listeners.

Listener lifecycle

Note that in most cases it is not necessary to remove a listener. As of 2.4.97, the listeners are stored as WeakReferences, and will be automatically cleaned at the next garbage collection, if you no longer hold a reference to them. Of course, until the garbage is collected, your object might still be getting events, so if you wish to avoid that, please remove it explicitly as described above.


author:
   Murray Altheim
since:
   2.4.20




Method Summary
final public static  booleanaddWikiEventListener(Object client, WikiEventListener listener)
     Registers a WikiEventListener with a WikiEventDelegate for the provided client object.

Monitor Listener

If client is a reference to the WikiEventManager class itself and the compile-time flag WikiEventManager.c_permitMonitor is true, this attaches the listener as an all-event monitor, overwriting any previous listener (hence returning true).

You can remove any existing monitor by either calling this method with client as a reference to this class and the listener parameter as null, or WikiEventManager.removeWikiEventListener(Object,WikiEventListener) with a client as a reference to this class.

public static  voidfireEvent(Object client, WikiEvent event)
     Notify all listeners of the WikiEventDelegate having a registered interest in change events of the supplied WikiEvent.
public static  WikiEventManagergetInstance()
     As this is a singleton class, this returns the single instance of this class provided with the property file filename and bit-wise application settings.
final public static  SetgetWikiEventListeners(Object client)
     Return the Set containing the WikiEventListeners attached to the delegate for the supplied client.
public static  booleanisListening(Object client)
     Returns true if there are one or more listeners registered with the provided client Object (undelegated event source).
final public static  booleanremoveWikiEventListener(Object client, WikiEventListener listener)
     Un-registers a WikiEventListener with the WikiEventDelegate for the provided client object.
final public static  booleanremoveWikiEventListener(WikiEventListener listener)
     Un-registers a WikiEventListener from any WikiEventDelegate client managed by this WikiEventManager.



Method Detail
addWikiEventListener
final public static boolean addWikiEventListener(Object client, WikiEventListener listener)(Code)
Registers a WikiEventListener with a WikiEventDelegate for the provided client object.

Monitor Listener

If client is a reference to the WikiEventManager class itself and the compile-time flag WikiEventManager.c_permitMonitor is true, this attaches the listener as an all-event monitor, overwriting any previous listener (hence returning true).

You can remove any existing monitor by either calling this method with client as a reference to this class and the listener parameter as null, or WikiEventManager.removeWikiEventListener(Object,WikiEventListener) with a client as a reference to this class. The listener parameter in this case is ignored.
Parameters:
  client - the client of the event source
Parameters:
  listener - the event listener true if the listener was added (i.e., it was not already in the list and was added)




fireEvent
public static void fireEvent(Object client, WikiEvent event)(Code)
Notify all listeners of the WikiEventDelegate having a registered interest in change events of the supplied WikiEvent.
Parameters:
  client - the client initiating the event.
Parameters:
  event - the WikiEvent to fire.



getInstance
public static WikiEventManager getInstance()(Code)
As this is a singleton class, this returns the single instance of this class provided with the property file filename and bit-wise application settings. A shared instance of the WikiEventManager



getWikiEventListeners
final public static Set getWikiEventListeners(Object client) throws UnsupportedOperationException(Code)
Return the Set containing the WikiEventListeners attached to the delegate for the supplied client. If there are no attached listeners, returns an empty Iterator rather than null. Note that this will create a delegate for the client if it did not exist prior to the call.

NOTE

This method returns a Set rather than an Iterator because of the high likelihood of the Set being modified while an Iterator might be active. This returns an unmodifiable reference to the actual Set containing the delegate's listeners. Any attempt to modify the Set will throw an java.lang.UnsupportedOperationException . This method is not synchronized and it should be understood that the composition of the backing Set may change at any time.


Parameters:
  client - the client of the event source an unmodifiable Set containing the WikiEventListeners attached to the client
throws:
  java.lang.UnsupportedOperationException - if any attempt is made to modify the Set



isListening
public static boolean isListening(Object client)(Code)
Returns true if there are one or more listeners registered with the provided client Object (undelegated event source). This locates any delegate and checks to see if it has any listeners attached.
Parameters:
  client - the client Object True, if there is a listener for this client object.



removeWikiEventListener
final public static boolean removeWikiEventListener(Object client, WikiEventListener listener)(Code)
Un-registers a WikiEventListener with the WikiEventDelegate for the provided client object.
Parameters:
  client - the client of the event source
Parameters:
  listener - the event listener true if the listener was found and removed.



removeWikiEventListener
final public static boolean removeWikiEventListener(WikiEventListener listener)(Code)
Un-registers a WikiEventListener from any WikiEventDelegate client managed by this WikiEventManager. Since this is a one-to-one relation, the first match will be returned upon removal; a true return value indicates the WikiEventListener was found and removed.
Parameters:
  listener - the event listener true if the listener was found and removed.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(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.